Coupon usage not being recorded


  • Default avatar
    doug70    
     3 days ago
    0

    Hello!

    I am having trouble with coupon usage not being recorded, or being recorded only sporadically.

    This all started when I installed version 3.5.6.9 of AwoCoupon, and version 2.3.3 of AwoAffiliate. I had previously been using an older version of AwoCoupon, and had not been using AwoAffiliate. I am using version 3.9.1 of Joomla, and version 3.2.14 of Virtuemart.

    After installing this new version of AwoCoupon, I at first got an error when customers returned to the site after paying for their purchase on Paypal, using the standard payment method. I was able to resolve this error by modifying the Virtuemart code, which I will freely admit could be part of the problem.

    I patched the following file:


    components/com_virtuemart/helpers/cart.php


    I added the following lines:


                           if (!class_exists('CouponHelper')) {

                           require(VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php');

                           }



    Into the emptyCartValues function, in the following context:


                   if(!empty($cart->couponCode)){

                           if (!class_exists('CouponHelper')) {

                           require(VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php');

                           }

                           CouponHelper::setInUseCoupon($couponCode, true, 1);

                   }


    For several days no coupon usage was recorded in AwoCoupon, even though customers were able to successfully use coupons to receive discounts on products. Then, coupon usage started getting recorded again, even though I did not make any further changes. I was baffled by this.

    In the intervening time, I have duplicated this environment on my test server, where I am now using the PayPal Sandbox environment for testing. Occasionally, a coupon use will be recorded, but most of the time it is not recorded.

    Currently, if I examine the awocoupon_history table in the database, the last entry is as follows:

    2579 virtuemart NULL NULL 75 [actual address removed for privacy] 0 0 0 0 0 5643380a2e0abc6ce5534182883182e5 NULL {"redeemed":true,"user_id":"75","uniquecartstring":"0|0|SonjaTest28|75|[actual address removed for privacy]|0|1|ship|3|223|21|1","coupon_id":122,"coupon_code":"SonjaTest28","coupon_code_internal":"SonjaTest28","product_discount":24,"product_discount_notax":24,"product_discount_tax":0,"shipping_discount":0,"shipping_discount_notax":0,"shipping_discount_tax":0,"extra_discount":0,"extra_discount_notax":0,"extra_discount_tax":0,"use_customer_balance":false,"productids":"126,","entered_coupon_ids":{"122":1},"processed_coupons":{"122":{"coupon_entered_id":"122","coupon_code":"SonjaTest28","orig_coupon_code":"SonjaTest28","product_discount":24,"product_discount_notax":24,"product_discount_tax":0,"shipping_discount":0,"shipping_discount_notax":0,"shipping_discount_tax":0,"extra_discount":0,"extra_discount_notax":0,"extra_discount_tax":0,"is_discount_before_tax":0,"usedproducts":"126","display_text":"SonjaTest28","isauto":false,"isgift":false,"isbalance":false,"ischild":false}},"cart_items":[{"product_id":126,"cartpricekey":0,"discount":0,"product_price":25,"product_price_notax":25,"product_price_tax":0,"qty":1,"tax_rate":0,"is_special":"0","is_discounted":0,"definition_id":126,"orig_product_price":25,"orig_product_price_notax":25,"orig_product_price_tax":0,"totaldiscount":24,"totaldiscount_notax":24,"totaldiscount_tax":0,"coupons":{"122":{"totaldiscount":24,"totaldiscount_notax":24,"totaldiscount_tax":0}},"_marked_total":false,"_marked_qty":false}],"cart_items_breakdown":{"1":{"product_id":126,"cartpricekey":0,"discount":0,"product_price":1,"product_price_notax":1,"product_price_tax":0,"tax_rate":0,"is_special":"0","is_discounted":0,"definition_id":126,"orig_product_price":25,"orig_product_price_notax":25,"orig_product_price_tax":0,"totaldiscount":24,"totaldiscount_notax":24,"totaldiscount_tax":0,"coupons":{"122":{"totaldiscount":24,"totaldiscount_notax":24,"totaldiscount_tax":0}},"_marked_total":false,"_marked_qty":false,"key":0}},"coupon_code_db":"SonjaTest28"} 5/15/19 16:01


    That coupon happens to be for a specific amount off. I then created a new coupon for a percentage off, which was successfully recorded when I used it, and now has an entry in the database:

    2581 virtuemart 151 151 NULL 75 [address removed for privacy] 28405 3.75 0 USD 3.75 0 NULL 142 {"redeemed":true,"user_id":"75","uniquecartstring":"0|0|SonjaTest29|75|[address removed for privacy]|0|1|ship|3|223|21|1","coupon_id":151,"coupon_code":"SonjaTest29","coupon_code_internal":"SonjaTest29","product_discount":3.75,"product_discount_notax":3.75,"product_discount_tax":0,"shipping_discount":0,"shipping_discount_notax":0,"shipping_discount_tax":0,"extra_discount":0,"extra_discount_notax":0,"extra_discount_tax":0,"use_customer_balance":false,"productids":"142,","entered_coupon_ids":{"151":1},"processed_coupons":{"151":{"coupon_entered_id":"151","coupon_code":"SonjaTest29","orig_coupon_code":"SonjaTest29","product_discount":3.75,"product_discount_notax":3.75,"product_discount_tax":0,"shipping_discount":0,"shipping_discount_notax":0,"shipping_discount_tax":0,"extra_discount":0,"extra_discount_notax":0,"extra_discount_tax":0,"is_discount_before_tax":0,"usedproducts":"142","display_text":"SonjaTest29","isauto":false,"isgift":false,"isbalance":false,"ischild":false}},"cart_items":[{"product_id":142,"cartpricekey":0,"discount":0,"product_price":25,"product_price_notax":25,"product_price_tax":0,"qty":1,"tax_rate":0,"is_special":"0","is_discounted":0,"definition_id":142,"orig_product_price":25,"orig_product_price_notax":25,"orig_product_price_tax":0,"totaldiscount":3.75,"totaldiscount_notax":3.75,"totaldiscount_tax":0,"coupons":{"151":{"totaldiscount":3.75,"totaldiscount_notax":3.75,"totaldiscount_tax":0}},"_marked_total":false,"_marked_qty":false}],"cart_items_breakdown":{"1":{"product_id":142,"cartpricekey":0,"discount":0,"product_price":21.25,"product_price_notax":21.25,"product_price_tax":0,"tax_rate":0,"is_special":"0","is_discounted":0,"definition_id":142,"orig_product_price":25,"orig_product_price_notax":25,"orig_product_price_tax":0,"totaldiscount":3.75,"totaldiscount_notax":3.75,"totaldiscount_tax":0,"coupons":{"151":{"totaldiscount":3.75,"totaldiscount_notax":3.75,"totaldiscount_tax":0}},"_marked_total":false,"_marked_qty":false,"key":0}},"coupon_code_db":"SonjaTest29"} 5/15/19 20:13


    The previous entry remains as it was, and is not reflected in the History of Uses list within AwoCoupon.

    I am also including an extract from the virtuemart_orders table, showing the last several orders. As you can see, coupons were used in all of them, but the only two for which any information appears in the awocoupon_history table are the last two, and the only one for which information appears in the "History of Uses" list is the last one.

    customer_number order_language virtuemart_order_id virtuemart_user_id virtuemart_vendor_id order_number order_pass order_create_invoice_pass order_total order_salesPrice order_billTaxAmount order_billTax order_billDiscountAmount order_discountAmount order_subtotal order_tax order_shipment order_shipment_tax order_payment order_payment_tax coupon_discount coupon_code order_discount order_currency order_status user_currency_id user_currency_rate user_shoppergroups payment_currency_id payment_currency_rate virtuemart_paymentmethod_id virtuemart_shipmentmethod_id oc_note delivery_date ip_address o_hash created_on created_by modified_on modified_by locked_on locked_by 93d6e711537d639a4130366975e85847 en-GB 28400 75 1 W22D028395 p_1SRpvUfE Ta9KJfNt 62.5 62.5 0 0 0 0 62.5 0 0 0 0 0 0 testWCEA 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx c82c991cc61c3d2cbdc6d9de23751849 5/15/19 19:22 75 5/15/19 19:22 0 0000-00-00 00:00:00 0 93d6e711537d639a4130366975e85847 en-GB 28401 75 1 7SYH028396 p_YNhRhv3z 7ZZ05HsK 45 45 0 0 0 0 45 0 0 0 0 0 0 testWCEA 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx 7bce787ec951018d31de4c3dc71da86a 5/15/19 19:39 75 5/15/19 19:39 0 0000-00-00 00:00:00 0 93d6e711537d639a4130366975e85847 en-GB 28402 75 1 8XYH028397 p_9vBEqJza 8cjDOFlY 25 25 0 0 0 0 25 0 0 0 0 0 0 testWCEA 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx 2c23d2e26d528b77af0923c0b6e48091 5/15/19 19:44 75 5/15/19 19:44 0 0000-00-00 00:00:00 0 93d6e711537d639a4130366975e85847 en-GB 28403 75 1 FSMK028398 p_6gSmpb7c 1nh11fDc 1 25 0 0 0 0 25 0 0 0 0 0 -24 SonjaTest28 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx c4582799157b61be818eb1ae30e7095a 5/15/19 19:49 75 5/15/19 19:49 0 0000-00-00 00:00:00 0 93d6e711537d639a4130366975e85847 en-GB 28404 75 1 ZCTQ028399 p_ArBBQzx9 GoSGgixl 1 25 0 0 0 0 25 0 0 0 0 0 -24 SonjaTest28 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx 8d17b41acabcebef4394f1d5374c9f35 5/15/19 20:00 75 5/15/19 20:01 0 0000-00-00 00:00:00 0 93d6e711537d639a4130366975e85847 en-GB 28405 75 1 GRF1028400 p_SVY5FV13 EEbzjYIX 21.25 25 0 0 0 0 25 0 0 0 0 0 -3.75 SonjaTest29 0 144 C 144 1 2 144 1 1 3 Same as invoice date 66.44.15.xx e96602daf5c49e07f60bf9af1d427c48 5/15/19 20:12 75 5/15/19 20:13 0 0000-00-00 00:00:00 0

    I would appreciate any insight you have on this issue, and am happy to perform any additional testing you think would be helpful!

  • Your avatar
    seyi    
     2 days ago
    0

    In AwoCoupon > configuration > triggers, how do you have 'Order state to trigger coupon processing' set?
  • Default avatar
    doug70    
     2 days ago
    0

    It is set to “Confirmed”. Virtuemart lists all of the orders as Confirmed.
  • Your avatar
    seyi    
     2 days ago
    0

    In the file www/administrator/components/com_awocoupon/helper/estore/virtuemart/class-awocoupon-helper-estore-virtuemart-discount.php  around line 543 is this:

    <?php
        
    public function order_new$order_id ) {
            $this->init();
    ?>

    Update it to this
    <?php
        
    public function order_new$order_id ) {

            $order_id = (int) $order_id;
            if ( $order_id ) {
                return null;
            }

            $this->init();
    ?>

    Does that make a difference?

  • Default avatar
    doug70    
     2 days ago
    0

    Thank you for the quick reply!

    I input the code you suggested, and have conducted several tests of different coupons without being able to generate a failure. I also re-enabled AwoAffiliate and for the first time, was able to get commissions to be correctly recorded.

    I will let you know if, after further testing, it turns out that this did not solve the problem.

    Thank you again!