【问题标题】:Magento combine catalogue price rulesMagento 结合目录价格规则
【发布时间】:2013-09-03 14:06:00
【问题描述】:

我正在尝试创建一个 magento 目录价格规则,其中条件组合使用“任何”而不是“全部”

以下代码创建具有两个条件的规则 - 但它们使用 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(); 

【问题讨论】:

    标签: magento mage magento-rules


    【解决方案1】:

    通过改变我的方法并使用一个具有不同条件的规则,我设法实现了以下相同的目标。注意使用 '()' 而不是 '==' 来表示 'is any of'。我通过创建一个规则并查看数据库表 '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();  
    

    希望对某人有所帮助!

    【讨论】:

    • 'catalogrule/rule_condition_product' 应该是 'salesrule/rule_condition_product' 您可以通过检查管理中的隐藏输入来检查这一点...除此之外,代码有效。
    猜你喜欢
    • 2011-05-26
    • 2014-06-18
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多