Division by Zero Error


  • Default avatar
    xpozay    
     9 years ago
    0

    Two issues - perhaps the first will resolve the second ....

    The coupon code I have setup is working with the exception that if I change/refresh the quantity of products in my cart (when the coupon is active), I receive a Division by zero error in "components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php on line 902" For example:
    - If I add 4 products while shopping. Then apply the coupon code I get a discount on 3 products only (correct).
    - If I change the quantity of products (or just push the refresh / recalc quantity button), I get the error.
    - If there is only one product in the cart, the price is still calculated correctly. Checkout and payment proceed as normal.

    However, BIG issue
    - If there are two products in the cart, say 1 piece of product A worth $100 and 3 pieces of product B worth $10 each (so total of $130), with the coupon code entered, and you refresh the product quantity of the second product (in the case B), the error happens and the first product takes on the price of the second. Therefore the total has changed from $130 to $40 (less coupon amount).
    - Similarly, if there are 3 products in the cart and you refresh / recalc the quantity of any product they all take on the price of the last product in the cart.
    - If there is no coupon active changing the quantity of a product and recalc / refresh happens properly.
    - The Division by zero error message will appear multiple times. 2 x for every product type in the cart the first refresh / recalc or 1 x for every product type in the cart if you refresh / recalc multiple times without removing and re-adding the coupon.


    My Coupon Configuration is
    Percentage or Amount: Percentage
    Discount Type: Specific
    Value:
    - Process Type: Step
    - Ordering: Found first match
    - Apply discount count: Not selected
    - 3,10
    - 4,0
    Number of Uses Total: blank
    Number of uses Customer: 3
    Min value: blank
    Min product quantity: 1
    Included 1 shopper group (test group)
    Included 1 product category

    I am using
    - AWO 2.3.8
    - J 2.5.9
    - VM 2.0.18a
    - Onepage checkout 2.0.286.100415



  • Default avatar
    xpozay    
     9 years ago
    0

    Perhaps this will help
    - I looked at the code (I am not a coder) helpers/estore/virtuemart/couponhandler.php
    and notice this line talks about Tax. We do not charge any tax on our products.
  • Your avatar
    seyi    
     9 years ago
    0

    Hello,

    Thanks for reporting with good details. I was able to reproduce. For both problems they have different solutions. Both require some code modification

    Divisible by 0:

    in www/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php, around line 900 is this:
    <?php
        $tax_rate 
    = isset($this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])
    ?>


    Change it to this:
    <?php
        $tax_rate 
    = !empty($this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])
    ?>


     
     
     
    Price change problems:
    This one is just strange and seems to affect only older versions of Virtuemart, and it happens because the function VirtueMartModelProduct::getProduct is called while trying to process the coupon. So instead, we get the product properties by accessing the table directly

    The fix, same file:
    in www/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php, around line 618 is this:
    <?php
            $product 
    $model->getProduct($virtuemart_product_idtruefalse);

            if ( 
    VmConfig::get('oncheckout_show_images')){
                
    $model->addImages($product,1);

            }
    ?>


    Delete it and replace it with this:
    <?php
            $product 
    $model->getTable ('products');
            
    $product->load ($virtuemart_product_id);
    ?>


    That should get rid of the price changing problem.

  • Default avatar
    xpozay    
     9 years ago
    0

    Thanks very much. I can confirm that both of these fixes are working.

    Can you confirm if these fixes will find their way into your support package or will I need to copy manage?

    Thanks again
  • Your avatar
    seyi    
     9 years ago
    0

    Hello,

    The fixes will be in the next update of AwoCoupon.