Skip to content

Commit d79e0e0

Browse files
patch fix for updating quantity
1 parent 7b16a35 commit d79e0e0

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ function kkd_pff_paystack_editor_add_quantity_data()
508508
$usequantity = get_post_meta($post->ID, '_usequantity', true);
509509
$useinventory = get_post_meta($post->ID, '_useinventory', true);
510510
$inventory = get_post_meta($post->ID, '_inventory',true);
511-
$sold = get_post_meta($post->ID, '_sold',true);
512511
$quantity = get_post_meta($post->ID, '_quantity', true);
513512
$quantityunit = get_post_meta($post->ID, '_quantityunit', true);
514513
$recur = get_post_meta($post->ID, '_recur', true);
@@ -523,17 +522,11 @@ function kkd_pff_paystack_editor_add_quantity_data()
523522
$quantity = '10';
524523
}
525524
if ($inventory == "" ) {
526-
if($sold !== ""){
527-
$inventory = $sold;
528-
}else{
525+
529526
$inventory = '1';
530-
}
527+
531528

532529
}
533-
if($sold == ""){
534-
$sold = '0';
535-
}
536-
$stock = $inventory - $sold;
537530
if ($quantityunit == "") {
538531
$quantityunit = 'Quantity';
539532
}
@@ -553,7 +546,7 @@ function kkd_pff_paystack_editor_add_quantity_data()
553546
if($usequantity == "yes"){
554547

555548
echo '<p>Max payable quantity:</p>';
556-
echo '<input type="number" min="1" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
549+
echo '<input type="number" min="1" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
557550
<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>';
558551
echo '<p>Unit of quantity:</p>';
559552
echo '<input type="text" name="_quantityunit" value="' . $quantityunit . '" class="widefat" />
@@ -572,10 +565,10 @@ function kkd_pff_paystack_editor_add_quantity_data()
572565

573566
}
574567
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" />';
568+
// echo '<p>Total Inventory</p>';
569+
// echo '<input type="number" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />';
577570
echo '<p>In stock</p>';
578-
echo '<input type="number" readonly name="_in_stock" value="' . $stock . '" class="widefat pf-number" />
571+
echo '<input type="number" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />
579572
<small></small>';
580573

581574
}

public/class-paystack-forms-public.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -822,26 +822,23 @@ function kkd_pff_paystack_form_shortcode($atts)
822822
}
823823
$useinventory = get_post_meta($id, '_useinventory', true);
824824
$inventory = get_post_meta($id, '_inventory',true);
825-
$sold = get_post_meta($id, '_sold',true);
826825
if ($inventory == "" ) {
827826
$inventory = '1';
828827
}
829-
if($sold == ""){
830-
$sold = '0';
831-
}
828+
832829
if($useinventory == ""){
833830
$useinventory = "no";
834831
}
835-
$stock = $inventory - $sold;
836832

837-
if($useinventory == "yes" && $stock <= 0){
833+
if($useinventory == "yes" && $inventory <= 0){
838834
echo "<h1>Out of Stock</h1>";
839835
}
840836
else if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
841837
echo '<div id="paystack-form">';
842838
if ($hidetitle != 1) {
843839
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
844840
}
841+
845842
echo '<form version="'.KKD_PFF_PAYSTACK_VERSION.'" enctype="multipart/form-data" action="' . admin_url('admin-ajax.php') . '" url="' . admin_url() . '" method="post" class="paystack-form j-forms" novalidate>
846843
<div class="j-row">';
847844
echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action">';
@@ -920,9 +917,9 @@ function kkd_pff_paystack_form_shortcode($atts)
920917
<input type="hidden" id="pf-amount" />
921918
<select class="form-control" id="pf-vamount" name="pf-amount">';
922919
$max = $quantity + 1;
923-
if($max > ($stock +1)){
924-
$max = $stock + 1 ;
925-
}
920+
if($max > ($inventory +1) && $useinventory == 'yes'){
921+
$max = $inventory + 1 ;
922+
}
926923
foreach ($paymentoptions as $key => $paymentoption) {
927924
list($a, $b) = explode(':', $paymentoption);
928925
echo '<option value="'.$b.'" data-name="'.$a.'">'.$a.' - '.$currency.' '.number_format($b).'</option>';
@@ -948,8 +945,8 @@ function kkd_pff_paystack_form_shortcode($atts)
948945
<select class="form-control" id="pf-quantity" name="pf-quantity" >';
949946
$max = $quantity + 1;
950947

951-
if($max > ($stock +1) && $useinventory == 'yes'){
952-
$max = $stock + 1 ;
948+
if($max > ($inventory +1) && $useinventory == 'yes'){
949+
$max = $inventory + 1 ;
953950
}
954951
for ($i=1; $i < $max; $i++) {
955952
echo ' <option value="'.$i.'">'.$i.'</option>';
@@ -1010,8 +1007,12 @@ function kkd_pff_paystack_form_shortcode($atts)
10101007
</label>
10111008
</div><br>';
10121009
}
1010+
// if($useinventory == "yes" && $usequantity == "yes"){
1011+
// echo '<small>'.$inventory.' left in stock. </small>';
1012+
// }
10131013
echo '<div class="span12 unit">
1014-
<small><span style="color: red;">*</span> are compulsory</small><br />
1014+
<small><span style="color: red;">*</span> are compulsory</small><br />
1015+
10151016
<img src="'. plugins_url('../images/[email protected]', __FILE__) .'" alt="cardlogos" class="paystack-cardlogos size-full wp-image-1096" />
10161017
10171018
<button type="reset" class="secondary-btn">Reset</button>';
@@ -1396,10 +1397,7 @@ function kkd_pff_paystack_submit_action()
13961397
$transaction_charge = get_post_meta($_POST["pf-id"], '_merchantamount', true);
13971398
$transaction_charge = $transaction_charge*100;
13981399
//--------------------------------------------------------------------------
1399-
$sold = get_post_meta($_POST["pf-id"], '_sold', true);
1400-
if($sold == ''){
1401-
$sold = '0';
1402-
}
1400+
14031401
//--------------------------------------------------------------------------
14041402
$txncharge = get_post_meta($_POST["pf-id"], '_txncharge', true);
14051403
$minimum = get_post_meta($_POST["pf-id"], '_minimum', true);
@@ -1410,7 +1408,6 @@ function kkd_pff_paystack_submit_action()
14101408
$originalamount = $amount;
14111409
$quantity = 1;
14121410
$usequantity = get_post_meta($_POST["pf-id"], '_usequantity', true);
1413-
14141411
if (($recur == 'no') && ($formamount != 0)) {
14151412
$amount = (int)str_replace(' ', '', $formamount);
14161413
}
@@ -1445,13 +1442,7 @@ function kkd_pff_paystack_submit_action()
14451442
}
14461443
//--------------------------------------
14471444

1448-
$sold = $sold+$quantity;
14491445

1450-
if (get_post_meta($_POST["pf-id"], '_sold', false)) { // If the custom field already has a value
1451-
update_post_meta($_POST["pf-id"], '_sold', $sold);
1452-
} else { // If the custom field doesn't have a value
1453-
add_post_meta($_POST["pf-id"], '_sold', $sold);
1454-
}
14551446

14561447
//--------------------------------------
14571448
if ($txncharge == 'customer') {
@@ -1759,6 +1750,15 @@ function kkd_pff_paystack_confirm_payment()
17591750
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
17601751
} else {
17611752
$usequantity = get_post_meta($payment_array->post_id, '_usequantity', true);
1753+
$useinventory = get_post_meta($payment_array->post_id, '_useinventory', true);
1754+
$inventory = get_post_meta($payment_array->post_id, '_inventory', true);
1755+
if($useinventory == 'yes' && $usequantity == 'yes'){
1756+
$quantity = $_POST["quantity"];
1757+
$message = $quantity;
1758+
$result = "success";
1759+
$inventory = $inventory - $quantity;
1760+
update_post_meta($payment_array->post_id, '_inventory', $inventory);
1761+
}
17621762
if ($usequantity == 'no') {
17631763
$oamount = (int)str_replace(' ', '', $amount);
17641764
} else {

0 commit comments

Comments
 (0)