Warning division by zero in - error message after updating to


  • Default avatar
    InfluentialSoftware    
     8 years ago
    0

    We recently updated to AwoCoupon Pro 2.3.8 from a previously working installation. (Joomla 2.5.20 and VM 2.0.14).
    Since then, on entering a previously working coupon code, we now get a series of errors at the top of the page when adding the code in the cart

    Warning: Division by zero in /var/www/live.satelliteinternet.co.uk/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php on line 902

    (multiple lines all showing the same warning message)

    The discount code does seem to get added to the order OK, but we see the above warning lines.

    I found two old forum posts https://awodev.com/forum/awocoupon/help-section/discount-code-not-valid and https://awodev.com/forum/awocoupon/help-section/another-error-gift-certificate but I can't work out whether these are relevant.

    Can you help point in the right direction?
    Thanks
  • Your avatar
    seyi    
     8 years ago
    0

    Hello,

    Do you have any products in the cart with a price of 0?

    What version of Virtuemart is this?

  • Default avatar
    rytech123    
     8 years ago
    0

    This comment has been moved here.
  • Default avatar
    InfluentialSoftware    
     8 years ago
    0

    Hallo - the answer is "yes and no".
    1) yes - we have products with a 0 value (eg customer can select collect as shipping method which has no cost). But before the upgrade, the coupon code could be added and processed and we did not get the division by zero warning message.
    2) no - I made a cart order with the same products but deleted the zero value items. Then I added the discount code - and still got the warning message.
    Virtuemart is 2.0.14
    Thanks
  • Your avatar
    seyi    
     8 years ago
    0

    hello,

    Ok, I think this will fix your issue. In that file
    /var/www/live.satelliteinternet.co.uk/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php on line 900 is this
    <?php
                $tax_rate 
    = isset($this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])
    ?>


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

  • Default avatar
    InfluentialSoftware    
     8 years ago
    0

    Hello Seyi, thanks. That has solved one of the cases (case 2) and we have put it live.

    However, we still get the error in case 1 when we have products with zero value (e.g. when customers collect, delivery = zero). Is there a fix for that? It will take some time to re-work the shop / products to avoid this, so it would be helpful if we can fix it in Awo Coupon.
    Thanks, Mike
  • Your avatar
    seyi    
     8 years ago
    0

    Take 3:

    Ok, the same file same lines should now be:

    <?php
    $tax_rate 
    = !empty($this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])
                    ? (
    $product_price-$this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])/$this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax']
                    : (
    $product_price-$this->vmcartPrices[$cartpricekey]['priceWithoutTax'])/$this->vmcartPrices[$cartpricekey]['priceWithoutTax']
                                ;
    ?>


    Please alter it to:
    <?php
    $tax_rate 
    = !empty($this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])
                    ? (
    $product_price-$this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax'])/$this->vmcartPrices[$cartpricekey]['discountedPriceWithoutTax']
                    : (empty(
    $this->vmcartPrices[$cartpricekey]['priceWithoutTax']) ? : ($product_price-$this->vmcartPrices[$cartpricekey]['priceWithoutTax'])/$this->vmcartPrices[$cartpricekey]['priceWithoutTax'])
                                ;
    ?>

  • Default avatar
    InfluentialSoftware    
     8 years ago
    0

    This works fine, Seyi, many thanks.