I need to check if a product has a catalog price rule and if it has, it needs to display a specific div.

So I need something like:

<?php if catalog price rule : ?>
<?php endif; ?>

How can I achieve that?

2 Answers 2


If you don't have many rules or many products you can try this:

$website = Mage::app()->getWebsite();
$product = $this->getProduct();
$rules = Mage::getModel('catalogrule/rule')->getCollection()
    ->addWebsiteFilter($website) //filter rules for current site
    ->addIsActiveFilter(1); //filter active rules

foreach ($rules as $rule) {
    $affectedProductIds = $rule->getMatchingProductIds();
    if (in_array($product->getId(), $affectedProductIds)) {
        //product has a price rule set for it

The quick and dirty idea would be to search for a record in the table catalogrule_product.
All products that are affected by catalog rules are referenced in that table.

$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_read');
$tableName = $resource->getTableName('catalogrule_product');
$count = $connection->fetchOne('SELECT COUNT(1) as c FROM '.$tableName.' WHERE product_id = '. $product->getId());

if ($count == 1) { 
    //you have a rule for the product

But this is not the best practice.

  • Thanks! But we do have a lot of products, 45.000+. So I do not know if that is a good idea, isn't?
    – JGeer
    Commented Nov 9, 2015 at 16:18
  • the second approach should work.
    – Marius
    Commented Nov 9, 2015 at 16:39
  • i will use second option... it better for speed..
    – Amit Bera
    Commented Nov 9, 2015 at 16:59
  • I tried the second option, but that does not work. Do I need to edit something inside your code?
    – JGeer
    Commented Nov 9, 2015 at 18:03
  • See how the variable $count looks like. It may be an array or something else.
    – Marius
    Commented Nov 9, 2015 at 18:22

Old question, but for others looking, this seems to be an efficient method:

$product = $this->getProduct();

See Mage_CatalogRule_Model_Rule for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.