Coupon code disallowed categories is very buggy: FIXED IT< FIXED CORE CODE

Started by Kuubs, March 01, 2024, 12:18:49 PM

Previous topic - Next topic

Kuubs

Hello,

Am i the only one around here that finds the allowed categories for the coupons very buggy? When I set certain categories most of the time it just refused to apply coupon codes for a specific product in the allowed category.. Anyone know why this happens?

Where is this code located, maybe I can take a look and see if I can make some changes to it...

EDIT:

I found the solution and the culprit.

The problem is this method in the calculationh.php helper file in administrator

protected function couponHandler($_code)

There is this peice of code:

for($i = 0; $i < $sizeof_cartitems_by_product; $i++){
            if( (!empty($allowed_product_ids) and in_array($this->_cart->cartPrices[$i]['virtuemart_product_id'],$allowed_product_ids)) || (!empty($allowed_productcat_ids) and array_intersect($this->_cart->products[$i]->categories, $allowed_productcat_ids))){
               $coupon_discount += ($this->_cart->cartPrices[$i]['salesPriceTt'] * ($_data->coupon_value / 100));
            }
         }

this is pretty buggy because the cart doesn't always start at the 0 index.. So i changed this code to this:

foreach ($this->_cart->products as $i => $product) {
            if ((!empty($allowed_product_ids) && in_array($this->_cart->cartPrices[$i]['virtuemart_product_id'], $allowed_product_ids)) || (!empty($allowed_productcat_ids) && array_intersect($product->categories, $allowed_productcat_ids))) {
               $coupon_discount += ($this->_cart->cartPrices[$i]['salesPriceTt'] * ($_data->coupon_value / 100));
            }
         }

Now it works beautifully! I will post this as a code change to be implemented in the core code


Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/