Coupon discount not showing until refreshing the page


  • Default avatar
    webman    
     a year ago  last edited a year ago
    0

    Hi there,

    I have a Shop on Joomla 4.2.8 with Virtuemart 4.0.12, PHP 8 and Awo Coupon Pro 4.0.0.5.
    I created an automatic coupon as a combination of two coupons. The first one has an amount of 0 and gets applied on a specific shipping method. The second one is a discount of 0.5 € per item.

    When I go to the shopping cart the coupon is applied before I chose any shipping method. I see the title and the discount value.
    When I choose the shipping method, the discount vanishes. If I refresh the page, either by F5 or by clicking on another payment method (Ajax Refresh) the discount is applied.

    I thought it would be VP Onepagecheckout but it is the same behaviour with the default Virtuemart Checkout.

    The strange thing is that I tested it in your demo before I purchased Awocoupon and it works like it should. You can try with any product, select "self pick-up" and the discount @kombi will be applied.
    I chose exactly the same settings than in your demo, I don't know where to look for the problem.

    If I create a normal coupon with 5% discount when more than 72 articles are in the cart, than the behaviour is exactly the same. The name of the coupon appears but the discount doesn't appear until you refresh the page.

    Maybe someone can help.
    Kind regards,
    Tanja
  • Your avatar
    seyi    
     a year ago
    0

    Hello,

    Try this to see if it fixes the issue.  In the file
    \administrator\components\com_awocoupon\helper\estore\virtuemart\class-awocoupon-helper-estore-virtuemart-discount.php
    around line 289 is this:

    <?php
            
    foreach ( $codes as $coupon ) {
                $this->o_cart->setCouponCode$coupon->coupon_code );
                break;
            }
    ?>

    Right after that add this
    <?php
            $orig_value 
    $this->_disable_awocoupon;
            $this->o_cart->getCartPrices$force true );
            $this->_disable_awocoupon $orig_value;
    ?>


  • Default avatar
    webman    
     a year ago  last edited a year ago
    0

    Hi Seyi,

    I put your code beneath the foreach and the refreshing now seems to work as expected (although the $force isn't used in the php file).
    But still the coupon is applied before I choose any shipping method. That makes the price in the Minicart wrong.
    It is even stranger. If I change the number of products in the cart and therefore the chosen shipping method isn't availabe anymore the Coupon is applied again with no shipping method chosen.
    The setting of preferred shipping method in the VM config is 'none', so I really don't know why the coupon is appearing.

    And I am not sure what is with this change if I update the component. Isn't there another solution where we don't have to override core files?

    Kind regards,
    Tanja
  • Your avatar
    seyi    
     a year ago
    0

    Hello,

    In the behavior of AwoCoupon, a shipping coupon is loaded before the shipping is selected.   Once selected, it then determines if it should remove the coupon or keep it.  This works well for normal coupons when customer have not yet chosen a shipping method but do have a valid coupon and they want to enter it.  The fix I gave you was for the discount displaying immediately without having to hit refresh.
  • Default avatar
    webman    
     a year ago
    0

    Hi,

    the discount displaying without refresh is working.
    But as I said, in your demo, I created an automatic coupon @kombi with exactely the same settings than I did on my website and it your demo it works as expected. The coupon is not applied until the user chooses "self pick-up".
    Why is it working in the demo but not on my page. I'm sorry, but to me that really makes no sense at all.

    Kind regards,
    Tanja
  • Your avatar
    seyi    
     a year ago
    0

    On the demo website, as shipping option is automatically selected.
  • Default avatar
    webman    
     a year ago
    0

    Hi Seyi,
    Ok, if it is not possible. I changed the coupon to a normal coupon with the payment "Zahlung bei Abholung" (Pay during self-pickup).
    And if you choose self-pick up the payment is automatically selected and the coupon automatically applied. Works perfect.

    But as I told I have a second coupon (get 5% if you buy more than 72 articles) and they can both be applied (automatically). If the coupon is active and you than switch the shipping method the behaviour is like before. The payment discount is not applied until the cart is refreshed.

    What can I do on this?
  • Your avatar
    seyi    
     a year ago
    0

    The code I sent should have fixed that.  If not, then not sure, would have to look at it directly to see what the issue is.  Feel free to send me a private message with temp admin and ftp access.
  • Your avatar
    seyi    
     a year ago
    0

    Seems to work fine with vponepage disabled.  How is the .7 euro coupon disabled from specific shipping methods?  Its not in the coupon setup.
  • Default avatar
    webman    
     a year ago
    0

    Hi Seyi, the coupon is not disabled from specific shipping methods because that didn't work as I wanted it.
    So I changed the coupon to a normal coupon with payment on self-pick up as condition.

    Payment on self-pick up is only available for shipping self-pick up and there it is the only payment method.
    Shall I open a ticket at Virtueplanet and see, if they can help?
  • Your avatar
    seyi    
     a year ago
    0

    Hello,

    Ok, you have alot of things going on, and I think that is basically breaking the code.  Looking through vp one page checkout code, in the javascript, when the shipping option is selected, it runs this code
                      ProOPC.getcartlist();
                        if (VPOPC._('RELOADPAYMENTS')) {
                            ProOPC.getpayments()
                        }

    As you can see, it gets the cart list before it runs the code to set the payment.  To combat this, in webman-bottom.js, I added the below code, which basically waits for half a second, which should give the above time to run, and then re-run's the getcartlist:
    <script>
    jQuery(document).ready(function( ) {
        $shipmentForm = jQuery('form#proopc-shipment-form');
        jQuery('input[name="virtuemart_shipmentmethod_id"][type="radio"]', $shipmentForm).each(function() {
            jQuery(this).click(function() {
                var ProOPC = window.ProOPC;
                setTimeout(function() {
                    ProOPC.getcartlist();
                }, 500);
            } );
        } );
    } );
    </script>

    The other issue, for some reason when calling getcartlist, the cart is not yet up to date.  So in the file
    \plugins\system\vponepagecheckout\cart\cartview.html.php, is this:
    <?php
                
    case 'getcartlist' :
                    $this->setDefaultCountry();
                    $this->checkPaymentMethodsConfigured();
                    $this->checkShipmentMethodsConfigured();
    # seyi_code
        $this->prepareCartForUpdate();
        $this->cart->prepareCartData();
    }
    ?>

    Where seyi_code is my code.  Seems to work better now.  Don't think there is any thing wrong with the coupon processing in AwoCoupon, just the order of things and how vponepage is processing it.
  • Default avatar
    webman    
     11 months ago
    0

    Hi Seyi,

    thank you for your adjustments.
    If you switch between two shipping methods, the discount for pick-up still isn't applied until you change something else in the cart or klick on the payment or shipment options again.

    Therefore my question again: Shall I ask VirtuePlanet for help?
    And what about your changes (in your component and the OPC plugin) if there is an update?

    Kind regards
    Tanja