AwoCoupon discounts for Shipping by Rules for VM


  • Default avatar
    eliot6    
     5 years ago  last edited 5 years ago
    0

    Hi Seyi,


    On a site i'm using AWOCoupon + VP One Page Checkout + Advanced Shipping Rules (opentools). I've also installed:

    AwoCoupon Discounts for the Shipping by Rules Plugins for VirtueMart
    Price : FREE
    AwoCoupon discounts for Shipping by Rules for VM, Version 1.2AwoCoupon discounts for Shipping by Rules for VM, Version 1.2
    Filename: plg_opentools_vmshipmentrules_awocoupon_v1.2.zip
    MIME-Type: application/zip
    File size: 4936 Bytes

    When I apply a Coupon (which works fine) and debug I can see the awo variables used in this plugin, however they seem to have values before the coupon was applied?


    [awoproductdiscount] => 0

        [awoproductdiscountnotax] => 0

        [awoshippingdiscount] => 0

        [awoshippingdiscountnotax] => 0

        [awodiscount] => 0

        [amountaftercoupon] => 34.98

        [amountwithtaxaftercoupon] => 34.98

        [taxamountaftercoupon] => 0

        [amountwithouttaxaftercoupon] => 34.98


    The cart shows the Coupon Discount 9.99 and deducts it properly so total is 24.99.

    Any ideas?

    1tFQ1GR.png

    regards

    Eliot


  • Default avatar
    eliot6    
     5 years ago
    0

    Hi Seyi


    The code that looks like its not getting your AWOCoupon values is in plugins\vmshipmentrules\awocoupon\awocoupon.php

    function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method) {
    // First, make sure coupons are processes (VM core processes third-party coupons AFTER the shipping)
    // This does NOT update the cart_prices array, but at least it makes sure Awocoupon has processed the coupon
    JPluginHelper::importPlugin('vmcoupon');
    if (!empty($cart->couponCode)) {
    $dispatcher = JDispatcher::getInstance();
    // TODO: This does not yet work...
    // $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($cart->couponCode, &$cart->cartData, $cart->cartPrices));
    }

    $coupon_discount = 0;
    $session = JFactory::getSession();
    $coupon_row = $session->get('coupon', '', 'awocoupon');
    $cartvals['awoproductdiscount'] = 0.0;
    $cartvals['awoproductdiscountnotax'] = 0.0;
    // $cartvals['awoproductdiscounttax'] = 0.0;
    $cartvals['awoshippingdiscount'] = 0.0;
    $cartvals['awoshippingdiscountnotax'] = 0.0;
    // $cartvals['awoshippingdiscounttax'] = 0.0;
    $cartvals['awodiscount'] = 0.0;
    if(!empty($coupon_row)) {
    $coupon_row = unserialize($coupon_row);
    // JFactory::getApplication()->enqueueMessage("<pre>AwoCoupon row: ".print_r($coupon_row,1)."</pre>", 'error');

    $cartvals['awoproductdiscount']       = $coupon_row['product_discount'];
    $cartvals['awoproductdiscountnotax']  = $coupon_row['product_discount_notax'];
    // $cartvals['awoproductdiscounttax']    = $coupon_row['product_discount_tax'];
    $cartvals['awoshippingdiscount']      = $coupon_row['shipping_discount'];
    $cartvals['awoshippingdiscountnotax'] = $coupon_row['shipping_discount_notax'];
    // $cartvals['awoshippingdiscounttax']   = $coupon_row['shipping_discount_tax'];
      $cartvals['awodiscount']              = $coupon_row['product_discount'] + $coupon_row['shipping_discount'];
    }
    $cartvals['amountaftercoupon'] = $cartvals['amount'] - $cartvals['awoproductdiscount'];
    $cartvals['amountwithtaxaftercoupon'] = $cartvals['amountaftercoupon'];
    $cartvals['taxamountaftercoupon'] = $cartvals['taxamount'] - ($cartvals['awoproductdiscount'] - $cartvals['awoproductdiscountnotax']);
    $cartvals['amountwithouttaxaftercoupon'] = $cartvals['amountaftercoupon'] - $cartvals['taxamountaftercoupon'];
    // TODO: Apply shipping coupon discounts
        }



  • Your avatar
    seyi    
     5 years ago  last edited 5 years ago
    0

    Assuming you are using AwoCoupon 3.x, the coupon_row is not serialized anymore, it is now json encoded, so maybe change this

    <?php
    <span style="white-space:pre;"></span>$coupon_row unserialize($coupon_row);
    ?>

    to this
    <?php
    <span style="white-space:pre;"></span>$coupon_row json_decode$coupon_rowtrue );
    ?>

    Will fix the issue
  • Default avatar
    eliot6    
     5 years ago
    0

    Hi Seyi


    I can see $cart-couponCode, but it looks like it doesn't actually get the coupon_row from the session

    $coupon_row = $session->get('coupon', '', 'awocoupon');

    regards

    Eliot

  • Your avatar
    seyi    
     5 years ago  last edited 5 years ago
    0

    Good point, here is how to get the info:

    <?php
    if ( ! class_exists'awocoupon' ) ) {
            require JPATH_ADMINISTRATOR '/components/com_awocoupon/helper/awocoupon.php';
    }
    AwoCoupon::instance();
    AC()->init();

    $coupon_session AC()->storediscount->get_coupon_session();
    ?>

    This already returns an object, so do not have to unserialize or json_decode.  Again, this assumes AwoCoupon 3.x.
  • Default avatar
    eliot6    
     5 years ago
    0

    Hi Seyi


    Working now:


    function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method) {
    // First, make sure coupons are processes (VM core processes third-party coupons AFTER the shipping)
    // This does NOT update the cart_prices array, but at least it makes sure Awocoupon has processed the coupon
    JPluginHelper::importPlugin('vmcoupon');
    if (!empty($cart->couponCode)) {
    $dispatcher = JDispatcher::getInstance();
    // TODO: This does not yet work...
    // $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($cart->couponCode, &$cart->cartData, $cart->cartPrices));
    }

    $coupon_discount = 0;
    //$session = JFactory::getSession();
    if ( ! class_exists( 'awocoupon' ) ) {
    require JPATH_ADMINISTRATOR . '/components/com_awocoupon/helper/awocoupon.php';
    }
    AwoCoupon::instance();
    AC()->init();

    $coupon_session = AC()->storediscount->get_coupon_session();
    //$coupon_row = $session->get('coupon', '', 'awocoupon');
    $coupon_row = $coupon_session;
    //JFactory::getApplication()->enqueueMessage("<pre>Coupon row: ".print_r($coupon_row,1)."</pre>", 'error');
    $cartvals['awoproductdiscount'] = 0.0;
    $cartvals['awoproductdiscountnotax'] = 0.0;
    // $cartvals['awoproductdiscounttax'] = 0.0;
    $cartvals['awoshippingdiscount'] = 0.0;
    $cartvals['awoshippingdiscountnotax'] = 0.0;
    // $cartvals['awoshippingdiscounttax'] = 0.0;
    $cartvals['awodiscount'] = 0.0;
    if(!empty($coupon_row)) {
    // Assuming you are using AwoCoupon 3.x, the coupon_row is not serialized anymore, it is now json encoded, so maybe change this
    // $coupon_row = unserialize($coupon_row);
    // $coupon_row = json_decode( $coupon_row, true );

    $cartvals['awoproductdiscount']       = $coupon_row->product_discount;
    $cartvals['awoproductdiscountnotax']  = $coupon_row->product_discount_notax;
    // $cartvals['awoproductdiscounttax']    = $coupon_row->product_discount_tax;
    $cartvals['awoshippingdiscount']      = $coupon_row->shipping_discount;
    $cartvals['awoshippingdiscountnotax'] = $coupon_row->shipping_discount_notax;
    // $cartvals['awoshippingdiscounttax']   = $coupon_row->shipping_discount_tax;
      $cartvals['awodiscount']              = $coupon_row->product_discount + $coupon_row->shipping_discount;
    }
    $cartvals['amountaftercoupon'] = $cartvals['amount'] - $cartvals['awoproductdiscount'];
    $cartvals['amountwithtaxaftercoupon'] = $cartvals['amountaftercoupon'];
    $cartvals['taxamountaftercoupon'] = $cartvals['taxamount'] - ($cartvals['awoproductdiscount'] - $cartvals['awoproductdiscountnotax']);
    $cartvals['amountwithouttaxaftercoupon'] = $cartvals['amountaftercoupon'] - $cartvals['taxamountaftercoupon'];
    // TODO: Apply shipping coupon discounts
        }

    Also needed to make the $coupon_row object references as well ... $coupon_row->product_discount


    regards

    Eliot

  • Default avatar
    eliot6    
     4 years ago
    0

    Hi Seyi,


    re: plugins\vmshipmentrules\awocoupon\awocoupon.php

    Has this changed again? I getting empty values for the following even though i can see the product discount in the cart.

    $cartvals['awoproductdiscount']       = $coupon_row->product_discount;
    $cartvals['awoproductdiscountnotax']  = $coupon_row->product_discount_notax;


    Hope you can help, thanks

    Eliot

  • Default avatar
    eliot6    
     4 years ago
    0

    please ignore, not an awocoupon