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
Nice shot!
well done,
Funny, I did not see this post, but looks we have almost the same solution
https://dev.virtuemart.net/projects/virtuemart/repository/virtuemart/revisions/10981/diff/trunk/virtuemart/administrator/components/com_virtuemart/helpers/calculationh.php