1

we have around 1300 shopping cart price rules. we now added a new product that we want't to exclude from all of our shopping cart price rules. what is the best way to do that? I though of updating the conditions of the shopping cart price rules programmatically, but I have no idea how to handle the serialized conditions.

Michael

  • You want to "Apply the rule only to cart items matching the following conditions"? There is only available for product: "Attribute set" or "Category". How do you select your product? By category or specific attribute set? – mkutyba Mar 28 '15 at 0:14
  • hi, yes this product is in a category that can be used to exclude it from shopping cart price rules. i know how to do it in the admin backend, but as we have so many rules i need a programmatically solution to update all of them with a script. – maigner Mar 28 '15 at 9:03
0

I don't know if there is some more OO solution, but my code just works.

$model = Mage::getModel('salesrule/rule')
        ->getCollection()
        ->load();


foreach ($model as $item) {
    if (!in_array($item->getId(), [11,12,13])) continue; //which rules you want to modify, or comment this line to modify all

    $actions = unserialize($item->getActionsSerialized());

    $actions['conditions'][] = [
        'type' => 'salesrule/rule_condition_product',
        'attribute' => 'category_ids',
        'operator' => '==',
        'value' => 3, // insert here your category id
        'is_value_processed' => false
    ];

    $item->setActionsSerialized(serialize($actions));
    $item->save();
}

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.