Update cookies preferences

Magento catalog price rules not applying conditions to bundle products correctly

I recently found an issue on a Magento 1 site where no matter what I tried, product SKU, product attribute in any combinations the product would always get the discount rule applied and the customer group would receive a discount on a product the merchant did not want discounted.

Simple products worked fine but there seems to be a bug for bundle products. We tried to add exclusions for the simple product and the bundle product but whenever the rule was applied again the bundle was always discounted.

So the following solution was found to fix the issue without spending too much more time working out why the rules conditions were not being checked correctly.

I wrote a small bit of code that checks a category which I setup not in the navigation called ‘Do not discount’. This category can then be used by the merchant to add any products they want. After being added this product can never be discounted by any catalog price rules.

As a simple fix add the following code.

Implement the following code by attaching an event observer to the catalogrule_before_apply event.

$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$exclusionCategoryId = 224;
$products = Mage::getModel('catalog/category')->load($exclusionCategoryId)->getProductCollection();
 
    foreach( $products as $product ){
 
      $table = $resource->getTableName('catalogrule_product_price');
      $query = "DELETE from { $table} where product_id = ".$product->getId();
      $writeConnection->query($query);
 
      $resource->getTableName('catalogrule_affected_product');
      $query = "DELETE from { $table} where product_id = ".$product->getId();
      $writeConnection->query($query);
 
   }

With $exclusionCategoryId being the category you can place product that will always be excluded.

If you enjoyed this article, read our other Learn articles to see more from our Magento developers or browse the site to see what else we do with Adobe Commerce, PunchOut Catalog and more.

Need a hand or want to consult with our developers on your latest project?


...
Luke

share:

Ready to start your next project?

See how we can help you accelerate your business