News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Fix for allowed categories / products coupon in cart

Started by Kuubs, March 01, 2024, 15:50:30 PM

Previous topic - Next topic

Kuubs

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! This should be implemented in the core code.