Search code examples
magentocatalogdiscount

Catalog Price Rules applied to special_price


First question on stackoverflow...i am excited :)

Currently magento is using the special price if its lower than the applied catalog price rule. If the catalog price rule makes the product cheaper than the special price, then the catalog price rule defines the shop price.

I am looking for an elegant way to make catalog price rules be applied to the special price (additionally). Maybe there is some store config for it? Maybe there is some neat observer way?

Thank you so much!


Solution

  • Works up to current Magento 1.9.3.10. Just tested it in a project after update. Josef tried another approach which might work as well.


    I am sad to say, I solved my first real stackoverflow question for my own:

    1. Goto Mage_CatalogRule_Model_Resource_Rule
    2. Goto method _getRuleProductsStmt
    3. Add this to the initial select of the method before the first original ->from:

      $select->from(null, array('default_price' => new Zend_Db_Expr("CASE WHEN pp_default_special.value THEN pp_default_special.value ELSE pp_default_normal.value END")));

    4. Add this after the first join() has happened

      $specialPriceAttr  = Mage::getSingleton('eav/config')
                          ->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'special_price');
      $specialPriceTable = $specialPriceAttr->getBackend()->getTable();
      $specialPriceAttributeId= $specialPriceAttr->getId();
      $joinCondition2 = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id=' . $specialPriceAttributeId . ') 
                                                      AND %1$s.store_id=%2$s';
      $select->join(
              array('pp_default_special'=>$specialPriceTable),
              sprintf($joinCondition2, 'pp_default_special', Mage_Core_Model_App::ADMIN_STORE_ID), null
      );
      

    How it works:

    When a catalog price rule is applied (via backend or cron) the db table catalogrule_product_price is populated. The above SQL magic joins the special_price (if exists) to the resultset as column default_value, if no special_price is found the regular price gets joined.

    The result has been checked and is working.

    Have fun! And dont hack the core!