无法以编程方式创建优惠券代码


Couldnot create a coupon code programmatically

我正在Magento Enterprise版本1.12.0.2中以编程方式创建优惠券代码(购物车规则)。

优惠券代码的创建没有任何问题。

但是,当我用第三条规则(即"1-1")添加条件并执行它时,它会给出错误

"致命错误:D:''wamp''www''projectname''lib''Zend''Db''Statement''Pdo.php中未捕获异常'PDOException',消息为'SQLSTATE[23000]:完整性约束冲突:1452无法添加或更新子行:外键约束失败(dbname.salesrule_product_attribute,constraint FK_SALESRULE_PRODUCT_ATTRIBUTE_RULE_ID_SALESRULE_RULE_ID foreign key(rule_id)REFERENCES salesrulerule_id)ON DELETE C)'"。

我的条件代码如下所示:

  $conditions = array(
        "1" => array(
            'type' => 'salesrule/rule_condition_combine',
            'aggregator' => 'all',
            'value' => 1,
            'new_child' => false
            ),
        "1--1" => array(
            'type' => 'salesrule/rule_condition_product_found',
            'value' => 1,
            'aggregator' => 'all',
            'new_child' => false
        ),
        "1--1--1" => array(
            'type' => 'salesrule/rule_condition_product',
            'attribute' => "category_ids",
            'operator' => "!=",
            'value' => "10"
        )
    );
$rule = Mage::getModel('salesrule/rule');
....
...
$rule->setData('conditions',$conditions);
$rule->loadPost($rule->getData());
$rule->save();

有人能帮忙吗?

如果您没有使用它,我相信禁用Enterprise Rewards模块有时可以修复这个PDO异常错误。请尝试遵循本指南,看看它是否解决了您的问题。