Magento结合了目录价格规则

时间:2013-09-03 14:06:00

标签: magento mage magento-rules

我正在尝试创建一个magento目录定价规则,条件使用'any'代替'all'

以下代码创建了一个包含两个条件的规则 - 但它们是使用all组合的。有谁知道如何实现这一目标?我正在使用magento 1.7.0.2(社区版)

$skuCondition = Mage::getModel('catalogrule/rule_condition_product')
                    ->setType('catalogrule/rule_condition_product')
                ->setAggregator('any')
                ->setAttribute('category_ids')
                    ->setOperator('==')
                ->setValue('18');


$skuCondition2 = Mage::getModel('catalogrule/rule_condition_product')
                    ->setType('catalogrule/rule_condition_product')
                ->setAttribute('category_ids')
                    ->setOperator('==')
                ->setValue('40');

 $catalogPriceRule->getConditions()->addCondition($skuCondition);
 $catalogPriceRule->getConditions()->addCondition($skuCondition2);

$catalogPriceRule->save(); 

1 个答案:

答案 0 :(得分:0)

通过改变我的方法并使用一个具有不同条件的规则,我设法实现了与下面相同的操作。注意使用'()'而不是'=='来表示'是任何'。我发现这个解决方案是通过创建一个规则并查看数据库表'catalogrule'中的数据,如果你选择了'condition_serialized'列我找到了

8:"operator";s:2:"()";s

“()”是操作员

所以我的最终代码是:

$catalogPriceRule->setName($name)
                 ->setDescription('')
                 ->setIsActive(1)
                 ->setWebsiteIds(array($websiteId))
                 ->setCustomerGroupIds(array($customerGroupId))
                 ->setFromDate('')
                 ->setToDate('')
                 ->setSortOrder('')
                 ->setSimpleAction($actionType)
                 ->setDiscountAmount($discount)
                 ->setStopRulesProcessing(0);

$skuCondition = Mage::getModel('catalogrule/rule_condition_product')
                ->setType('catalogrule/rule_condition_product')
                ->setAggregator('any')
                ->setAttribute('category_ids')
                ->setOperator('()')
                ->setValue('18,40');

$catalogPriceRule->getConditions()->addCondition($skuCondition);
$catalogPriceRule->save();  

希望能帮助别人!