8

I am trying to exclude the associated simple product of configurable product from catalog price rule.The reason behind to doing this all that I have already added -price in super attribute configuration section and i don't want to give anymore discount to this particular product.

I have tried to exclude product to save in catalogrule_product table but i found that this table not saving the associated product it save configurable product id, and calculate the price using it.

Also i have tried to out some condition in configurable.php but no luck yet..

I don't want to use any dirty way to do this. Please tell me what is the smart way to do this..

  • 1
    Does setting the option: "Enable Discounts to Subproducts" to "No" in Catalog rule > Action helps? – Raks Apr 8 '14 at 12:18
  • No its not working. – Jitendra Apr 8 '14 at 18:37
2

Magento does not support this by default. Instead, we overrode Mage_SalesRule_Model_Validator and created a salesrule rewrite. In that we check to see if the associated product matches the sales rule.

app/code/local/AAA/SalesRule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <AAA_SalesRule>
            <version>0.1.0</version>
        </AAA_SalesRule>
    </modules>
    <global>
        <models>
            <aaa_salesrule>
                <class>AAA_SalesRule_Model</class>
            </aaa_salesrule>
            <salesrule>
                <rewrite>
                    <validator>AAA_SalesRule_Model_SalesRule_Validator</validator>
                </rewrite>
            </salesrule>
        </models>
    </global>
</config>

app/code/local/AAA/SalesRule/Model/SalesRule/Validator.php

private function _hasChildInCart($product) {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
        $childrenIds = $this->_getChildrenIds($childProducts);

        foreach ($quote->getAllItems() as $item) {
            if (in_array($item->getProductId(), $childrenIds)) {
                $registeredItem = Mage::registry('rule_config_product_' . $product->getId());
                if ($registeredItem != null && $registeredItem->getId() != $item->getId()) {
                    Mage::unregister('rule_config_product_' . $product->getId());
                }
                if ($registeredItem == null) {
                    Mage::register('rule_config_product_' . $product->getId(), $item);
                }
                return true;
            }
        }
        return false;
    }

    private function _getChildrenIds($childProducts) {
        $childrenIds = array();
        foreach ($childProducts as $child) {
            $childrenIds[] = $child->getId();
        }

        return $childrenIds;
    }
1

You can use the Super Products Attributes section to increase the default price of an associated product. The price of the associated product will continue to appear in the Admin panel. From the store, the item will have a zero value unless you enter a new price as either a fixed amount or as a percentage of the default price of the Configurable product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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