I'm trying to create catalog price rule programmatically (percentage discount on category for specific customer group). But it is not being applied programmatically. Even if you go to Catalog Price Rules section, and press "Apply Rules" button - it is not being applied. It applies only if you go to edit this rule in backend, save it without any modification, and then press "Apply Rules". Here is the code:
$catalogRule = Mage::getModel('catalogrule/rule');
$catalogRule->setName($ruleName)
->setIsActive(true)
->setWebsiteIds(array(1))
->setCustomerGroupIds(array($group->getId()))
->setSimpleAction('by_percent')
->setDiscountAmount($discountAmount);
$categoryCondition = Mage::getModel('catalogrule/rule_condition_combine')
->setType('catalogrule/rule_condition_product')
->setAttribute('category_ids')
->setOperator('==')
->setValue($categoryId);
$catalogRule->getConditions()->addCondition($categoryCondition);
$catalogRule->save();
$catalogRule->applyAll();
Mage::app()->removeCache('catalog_rules_dirty');
Thank you for help!