Skip to content

Commit 073b0f5

Browse files
authored
Merge pull request #56 from lukman008/master
patch/Added inventory management
2 parents 42fa86b + 2b47d3a commit 073b0f5

23 files changed

+152
-18
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ function kkd_pff_paystack_editor_add_recur_data()
479479
$recur = get_post_meta($post->ID, '_recur', true);
480480
$recurplan = get_post_meta($post->ID, '_recurplan', true);
481481

482-
if ($recur == "") {
482+
if ($recur == "") {
483483
$recur = 'no';
484484
}
485485
if ($recurplan == "") {
@@ -506,16 +506,34 @@ function kkd_pff_paystack_editor_add_quantity_data()
506506

507507
// Get the location data if its already been entered
508508
$usequantity = get_post_meta($post->ID, '_usequantity', true);
509+
$useinventory = get_post_meta($post->ID, '_useinventory', true);
510+
$inventory = get_post_meta($post->ID, '_inventory',true);
511+
$sold = get_post_meta($post->ID, '_sold',true);
509512
$quantity = get_post_meta($post->ID, '_quantity', true);
510513
$quantityunit = get_post_meta($post->ID, '_quantityunit', true);
511514
$recur = get_post_meta($post->ID, '_recur', true);
512-
515+
513516
if ($usequantity == "") {
514517
$usequantity = 'no';
515518
}
519+
if($useinventory == ""){
520+
$useinventory = "no";
521+
}
516522
if ($quantity == "") {
517523
$quantity = '10';
518524
}
525+
if ($inventory == "" ) {
526+
if($sold !== ""){
527+
$inventory = $sold;
528+
}else{
529+
$inventory = '1';
530+
}
531+
532+
}
533+
if($sold == ""){
534+
$sold = '0';
535+
}
536+
$stock = $inventory - $sold;
519537
if ($quantityunit == "") {
520538
$quantityunit = 'Quantity';
521539
}
@@ -532,12 +550,37 @@ function kkd_pff_paystack_editor_add_quantity_data()
532550
<option value="yes" '.kkd_pff_paystack_txncheck('yes', $usequantity).'>Yes</option>
533551
</select>';
534552
}
535-
echo '<p>Max payable quantity:</p>';
536-
echo '<input type="number" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
537-
<small>Your users only get to pay in quantities if the from amount is not set to zero and recur is set to none.</small>';
538-
echo '<p>Unit of quantity:</p>';
539-
echo '<input type="text" name="_quantityunit" value="' . $quantityunit . '" class="widefat" />
540-
<small>What is the unit of this quantity? Default is <code>Quantity</code>.</small>';
553+
if($usequantity == "yes"){
554+
555+
echo '<p>Max payable quantity:</p>';
556+
echo '<input type="number" min="1" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
557+
<small>Your users only get to pay in quantities if the from amount is not set to zero and recur is set to none.</small>';
558+
echo '<p>Unit of quantity:</p>';
559+
echo '<input type="text" name="_quantityunit" value="' . $quantityunit . '" class="widefat" />
560+
<small>What is the unit of this quantity? Default is <code>Quantity</code>.</small>';
561+
562+
563+
echo '<p>Inventory Payment:</p>';
564+
echo '
565+
<select class="form-control" name="_useinventory" style="width:100%;">
566+
<option value="no" '.kkd_pff_paystack_txncheck('no', $useinventory).'>No</option>
567+
<option value="yes" '.kkd_pff_paystack_txncheck('yes', $useinventory).'>Yes</option>
568+
</select>
569+
<small>Set maximum available items in stock</small>
570+
';
571+
572+
573+
}
574+
if($useinventory == "yes" && $usequantity == "yes"){
575+
echo '<p>Total Inventory</p>';
576+
echo '<input type="number" min="'.$sold.'" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />';
577+
echo '<p>In stock</p>';
578+
echo '<input type="number" readonly name="_in_stock" value="' . $stock . '" class="widefat pf-number" />
579+
<small></small>';
580+
581+
}
582+
583+
541584
}
542585
function kkd_pff_paystack_editor_add_agreement_data()
543586
{
@@ -641,7 +684,8 @@ function kkd_pff_paystack_save_data($post_id, $post)
641684
if (!current_user_can('edit_post', $post->ID)) {
642685
return $post->ID;
643686
}
644-
687+
$form_meta['_inventory'] = $_POST['_inventory'];
688+
$form_meta['_useinventory'] = $_POST['_useinventory'];
645689
$form_meta['_amount'] = $_POST['_amount'];
646690
$form_meta['_hidetitle'] = $_POST['_hidetitle'];
647691
$form_meta['_minimum'] = $_POST['_minimum'];

includes/class-paystack-forms-activator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function activate()
2222
txn_code varchar(255) DEFAULT '' NOT NULL,
2323
txn_code_2 varchar(255) DEFAULT '' NOT NULL,
2424
amount varchar(255) DEFAULT '' NOT NULL,
25-
ip varchar(255) NOT NULL,
25+
ip varchar(255) NOT NULL,
2626
deleted_at varchar(255) DEFAULT '' NULL,
2727
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2828
modified timestamp DEFAULT '0000-00-00 00:00:00' NOT NULL,

public/class-paystack-forms-public.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,24 @@ function kkd_pff_paystack_form_shortcode($atts)
820820
}
821821
}
822822
}
823-
if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
823+
$useinventory = get_post_meta($id, '_useinventory', true);
824+
$inventory = get_post_meta($id, '_inventory',true);
825+
$sold = get_post_meta($id, '_sold',true);
826+
if ($inventory == "" ) {
827+
$inventory = '1';
828+
}
829+
if($sold == ""){
830+
$sold = '0';
831+
}
832+
if($useinventory == ""){
833+
$useinventory = "no";
834+
}
835+
$stock = $inventory - $sold;
836+
837+
if($useinventory == "yes" && $stock <= 0){
838+
echo "<h1>Out of Stock</h1>";
839+
}
840+
else if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
824841
echo '<div id="paystack-form">';
825842
if ($hidetitle != 1) {
826843
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
@@ -902,7 +919,10 @@ function kkd_pff_paystack_form_shortcode($atts)
902919
<input type="hidden" id="pf-vname" name="pf-vname" />
903920
<input type="hidden" id="pf-amount" />
904921
<select class="form-control" id="pf-vamount" name="pf-amount">';
905-
$max = $quantity+1;
922+
$max = $quantity + 1;
923+
if($max > ($stock +1)){
924+
$max = $stock + 1 ;
925+
}
906926
foreach ($paymentoptions as $key => $paymentoption) {
907927
list($a, $b) = explode(':', $paymentoption);
908928
echo '<option value="'.$b.'" data-name="'.$a.'">'.$a.' - '.$currency.' '.number_format($b).'</option>';
@@ -926,7 +946,10 @@ function kkd_pff_paystack_form_shortcode($atts)
926946
<div class="select">
927947
<input type="hidden" value="'.$amount.'" id="pf-qamount"/>
928948
<select class="form-control" id="pf-quantity" name="pf-quantity" >';
929-
$max = $quantity+1;
949+
$max = $quantity + 1;
950+
if($max > ($stock +1)){
951+
$max = $stock + 1 ;
952+
}
930953
for ($i=1; $i < $max; $i++) {
931954
echo ' <option value="'.$i.'">'.$i.'</option>';
932955
}
@@ -1371,7 +1394,12 @@ function kkd_pff_paystack_submit_action()
13711394
$txnbearer = get_post_meta($_POST["pf-id"], '_txnbearer', true);
13721395
$transaction_charge = get_post_meta($_POST["pf-id"], '_merchantamount', true);
13731396
$transaction_charge = $transaction_charge*100;
1374-
1397+
//--------------------------------------------------------------------------
1398+
$sold = get_post_meta($_POST["pf-id"], '_sold', true);
1399+
if($sold == ''){
1400+
$sold = '0';
1401+
}
1402+
//--------------------------------------------------------------------------
13751403
$txncharge = get_post_meta($_POST["pf-id"], '_txncharge', true);
13761404
$minimum = get_post_meta($_POST["pf-id"], '_minimum', true);
13771405
$variableamount = get_post_meta($_POST["pf-id"], '_variableamount', true);
@@ -1414,9 +1442,17 @@ function kkd_pff_paystack_submit_action()
14141442
$unitamount = (int)str_replace(' ', '', $amount);
14151443
$amount = $quantity*$unitamount;
14161444
}
1417-
1418-
1445+
//--------------------------------------
1446+
1447+
$sold = $sold+$quantity;
14191448

1449+
if (get_post_meta($_POST["pf-id"], '_sold', false)) { // If the custom field already has a value
1450+
update_post_meta($_POST["pf-id"], '_sold', $sold);
1451+
} else { // If the custom field doesn't have a value
1452+
add_post_meta($_POST["pf-id"], '_sold', $sold);
1453+
}
1454+
1455+
//--------------------------------------
14201456
if ($txncharge == 'customer') {
14211457
$amount = kkd_pff_paystack_add_paystack_charge($amount);
14221458
}
@@ -1532,7 +1568,7 @@ function kkd_pff_paystack_submit_action()
15321568

15331569
$fixedmetadata = json_decode(json_encode($fixedmetadata, JSON_NUMERIC_CHECK), true);
15341570
$fixedmetadata = array_merge($untouchedmetadata, $fixedmetadata);
1535-
1571+
15361572
$insert = array(
15371573
'post_id' => strip_tags($_POST["pf-id"], ""),
15381574
'email' => strip_tags($_POST["pf-pemail"], ""),
@@ -1590,6 +1626,10 @@ function kkd_pff_paystack_submit_action()
15901626
'txnbearer' => $txnbearer,
15911627
'transaction_charge' => $transaction_charge
15921628
);
1629+
1630+
//-------------------------------------------------------------------------------------------
1631+
1632+
15931633
echo json_encode($response);
15941634
die();
15951635
}

public/css/pff-paystack-style.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@
99
width:300px !important;
1010
height:87px !important;
1111
}
12+
@font-face {
13+
font-family: 'Graphik';
14+
font-style: normal;
15+
font-weight: normal;
16+
src: url('/fonts/graphik/Graphik-Regular.eot');
17+
src: url('/fonts/graphik/Graphik-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Regular.woff') format('woff'), /* Modern Browsers */ url('/fonts/graphik/Graphik-Regular.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Regular.svg#Graphik-Regular') format('svg');
18+
text-rendering: optimizeLegibility;
19+
20+
/* IE9 Compat Modes */
21+
/* Legacy iOS */
22+
}
23+
@font-face {
24+
font-family: 'Graphik';
25+
font-style: normal;
26+
font-weight: 300;
27+
src: url('/fonts/graphik/Graphik-Light.eot');
28+
src: url('/fonts/graphik/Graphik-Light.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Light.woff') format('woff'), Modern Browsers url('/fonts/graphik/Graphik-Light.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Light.svg#Graphik-Light') format('svg');
29+
text-rendering: optimizeLegibility;
30+
31+
/* IE9 Compat Modes */
32+
/* Legacy iOS */
33+
}
34+
@font-face {
35+
font-family: 'Graphik';
36+
font-style: normal;
37+
font-weight: bold;
38+
src: url('/fonts/graphik/Graphik-Medium.eot');
39+
src: url('/fonts/graphik/Graphik-Medium.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Medium.woff') format('woff'), /* Modern Browsers */ url('/fonts/graphik/Graphik-Medium.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Medium.svg#Graphik-Medium') format('svg');
40+
text-rendering: optimizeLegibility;
41+
42+
/* IE9 Compat Modes */
43+
/* Legacy iOS */
44+
}
45+
1246

1347
/* Default
1448
=============================== */
@@ -27,6 +61,11 @@
2761
padding:40px 15px;
2862
max-width: 1280px;
2963
margin: 0 auto;
64+
font-family: 'Graphik', 'Helvetica Neue', 'Arial', sans-serif;
65+
-webkit-text-size-adjust: 100%;
66+
-webkit-font-smoothing: antialiased;
67+
-moz-osx-font-smoothing: grayscale;
68+
text-rendering: optimizeLegibility;
3069
}
3170

3271
#pf-form.j-forms {
@@ -84,6 +123,18 @@
84123
border-radius:0px;
85124
}
86125

126+
.j-forms input{
127+
display: block;
128+
height: 35px;
129+
font-size: 14px;
130+
width: 100%;
131+
line-height: 35px;
132+
padding: 0 10px;
133+
border: solid 1px #cccccc;
134+
border-radius: 2px;
135+
outline: none;
136+
}
137+
87138
/* Header
88139
=============================== */
89140
.j-forms .header {

public/fonts/Graphik-Black.otf

137 KB
Binary file not shown.
140 KB
Binary file not shown.

public/fonts/Graphik-Bold.otf

136 KB
Binary file not shown.
139 KB
Binary file not shown.
132 KB
Binary file not shown.
136 KB
Binary file not shown.

0 commit comments

Comments
 (0)