0

I want to add/remove applicable product sku to/from already defined price rules programmatically when ever it is needed.

How can I do that?

1 Answer 1

0

I made it work like this. But still dont know how to remove the condition for a certain sku. This is my code:

$productId = Mage::getSingleton('catalog/product')->getIdBySku($sku);
if($productId){
    $realProduct = Mage::getModel('catalog/product')->load($productId);
    $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($realProduct->getId());
    $configProduct = Mage::getModel("catalog/product")->load($parentIds[0]);
    if(!$voucherRule->getConditions()->validate($realProduct)){
        $item_found = Mage::getModel('salesrule/rule_condition_product_found')
            ->setType('salesrule/rule_condition_product_found')
            ->setValue(1) // 1 == FOUND
            ->setAggregator('any'); // match ANY conditions
        $skuCondition = Mage::getModel('salesrule/rule_condition_product')
            ->setType('salesrule/rule_condition_product')
            ->setAttribute('sku')
            ->setOperator('==')
            ->setValue($realProduct->getSku());

        try{
            $voucherRule->getConditions()->addCondition($item_found);
            $item_found->addCondition($skuCondition);
            $voucherRule->save();
        }
        catch (Exception $e) {
            die($e->getMessage());
        }
    }
}

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.