Skip to content

Commit fff9f67

Browse files
Revert "patch fix for updating quantity"
This reverts commit d79e0e0.
1 parent 76c3a01 commit fff9f67

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ 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);
511512
$quantity = get_post_meta($post->ID, '_quantity', true);
512513
$quantityunit = get_post_meta($post->ID, '_quantityunit', true);
513514
$recur = get_post_meta($post->ID, '_recur', true);
@@ -522,11 +523,17 @@ function kkd_pff_paystack_editor_add_quantity_data()
522523
$quantity = '10';
523524
}
524525
if ($inventory == "" ) {
525-
526+
if($sold !== ""){
527+
$inventory = $sold;
528+
}else{
526529
$inventory = '1';
527-
530+
}
528531

529532
}
533+
if($sold == ""){
534+
$sold = '0';
535+
}
536+
$stock = $inventory - $sold;
530537
if ($quantityunit == "") {
531538
$quantityunit = 'Quantity';
532539
}
@@ -546,7 +553,7 @@ function kkd_pff_paystack_editor_add_quantity_data()
546553
if($usequantity == "yes"){
547554

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

566573
}
567574
if($useinventory == "yes" && $usequantity == "yes"){
568-
// echo '<p>Total Inventory</p>';
569-
// echo '<input type="number" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />';
575+
echo '<p>Total Inventory</p>';
576+
echo '<input type="number" min="'.$sold.'" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />';
570577
echo '<p>In stock</p>';
571-
echo '<input type="number" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />
578+
echo '<input type="number" readonly name="_in_stock" value="' . $stock . '" class="widefat pf-number" />
572579
<small></small>';
573580

574581
}

public/class-paystack-forms-public.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -824,23 +824,26 @@ function kkd_pff_paystack_form_shortcode($atts)
824824
}
825825
$useinventory = get_post_meta($id, '_useinventory', true);
826826
$inventory = get_post_meta($id, '_inventory',true);
827+
$sold = get_post_meta($id, '_sold',true);
827828
if ($inventory == "" ) {
828829
$inventory = '1';
829830
}
830-
831+
if($sold == ""){
832+
$sold = '0';
833+
}
831834
if($useinventory == ""){
832835
$useinventory = "no";
833836
}
837+
$stock = $inventory - $sold;
834838

835-
if($useinventory == "yes" && $inventory <= 0){
839+
if($useinventory == "yes" && $stock <= 0){
836840
echo "<h1>Out of Stock</h1>";
837841
}
838842
else if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
839843
echo '<div id="paystack-form">';
840844
if ($hidetitle != 1) {
841845
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
842846
}
843-
844847
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>
845848
<div class="j-row">';
846849
echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action">';
@@ -919,9 +922,9 @@ function kkd_pff_paystack_form_shortcode($atts)
919922
<input type="hidden" id="pf-amount" />
920923
<select class="form-control" id="pf-vamount" name="pf-amount">';
921924
$max = $quantity + 1;
922-
if($max > ($inventory +1) && $useinventory == 'yes'){
923-
$max = $inventory + 1 ;
924-
}
925+
if($max > ($stock +1)){
926+
$max = $stock + 1 ;
927+
}
925928
foreach ($paymentoptions as $key => $paymentoption) {
926929
list($a, $b) = explode(':', $paymentoption);
927930
echo '<option value="'.$b.'" data-name="'.$a.'">'.$a.' - '.$currency.' '.number_format($b).'</option>';
@@ -1009,12 +1012,8 @@ function kkd_pff_paystack_form_shortcode($atts)
10091012
</label>
10101013
</div><br>';
10111014
}
1012-
// if($useinventory == "yes" && $usequantity == "yes"){
1013-
// echo '<small>'.$inventory.' left in stock. </small>';
1014-
// }
10151015
echo '<div class="span12 unit">
1016-
<small><span style="color: red;">*</span> are compulsory</small><br />
1017-
1016+
<small><span style="color: red;">*</span> are compulsory</small><br />
10181017
<img src="'. plugins_url('../images/[email protected]', __FILE__) .'" alt="cardlogos" class="paystack-cardlogos size-full wp-image-1096" />
10191018
10201019
<button type="reset" class="secondary-btn">Reset</button>';
@@ -1399,7 +1398,10 @@ function kkd_pff_paystack_submit_action()
13991398
$transaction_charge = get_post_meta($_POST["pf-id"], '_merchantamount', true);
14001399
$transaction_charge = $transaction_charge*100;
14011400
//--------------------------------------------------------------------------
1402-
1401+
$sold = get_post_meta($_POST["pf-id"], '_sold', true);
1402+
if($sold == ''){
1403+
$sold = '0';
1404+
}
14031405
//--------------------------------------------------------------------------
14041406
$txncharge = get_post_meta($_POST["pf-id"], '_txncharge', true);
14051407
$minimum = get_post_meta($_POST["pf-id"], '_minimum', true);
@@ -1410,6 +1412,7 @@ function kkd_pff_paystack_submit_action()
14101412
$originalamount = $amount;
14111413
$quantity = 1;
14121414
$usequantity = get_post_meta($_POST["pf-id"], '_usequantity', true);
1415+
14131416
if (($recur == 'no') && ($formamount != 0)) {
14141417
$amount = (int)str_replace(' ', '', $formamount);
14151418
}
@@ -1444,7 +1447,13 @@ function kkd_pff_paystack_submit_action()
14441447
}
14451448
//--------------------------------------
14461449

1450+
$sold = $sold+$quantity;
14471451

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

14491458
//--------------------------------------
14501459
if ($txncharge == 'customer') {
@@ -1754,15 +1763,6 @@ function kkd_pff_paystack_confirm_payment()
17541763
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
17551764
} else {
17561765
$usequantity = get_post_meta($payment_array->post_id, '_usequantity', true);
1757-
$useinventory = get_post_meta($payment_array->post_id, '_useinventory', true);
1758-
$inventory = get_post_meta($payment_array->post_id, '_inventory', true);
1759-
if($useinventory == 'yes' && $usequantity == 'yes'){
1760-
$quantity = $_POST["quantity"];
1761-
$message = $quantity;
1762-
$result = "success";
1763-
$inventory = $inventory - $quantity;
1764-
update_post_meta($payment_array->post_id, '_inventory', $inventory);
1765-
}
17661766
if ($usequantity == 'no') {
17671767
$oamount = (int)str_replace(' ', '', $amount);
17681768
} else {

0 commit comments

Comments
 (0)