I am creating coupon code(shopping cart rule) programmatically in Magento Enterprise ver. 1.12.0.2.
Coupon code gets created without any problem.
But when I add the condition with the third rule i.e "1--1--1" as shown below and execute it, It gives error as
"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (dbname
.salesrule_product_attribute
, CONSTRAINT FK_SALESRULE_PRODUCT_ATTRIBUTE_RULE_ID_SALESRULE_RULE_ID
FOREIGN KEY (rule_id
) REFERENCES salesrule
(rule_id
) ON DELETE C)' in D:\wamp\www\projectname\lib\Zend\Db\Statement\Pdo.php".
My code for condition is as shown below:
$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();
Can anyone help on this?
If you're not using it, I believe that disabling the Enterprise Rewards module can sometimes fix this PDO exception error. Try following this guide and see if it fixes your issue.