Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Any ideas this is occurring with a fresh install of Professional with the rewards module SQLSTATE[23000]: Integrity constraint violation: 1452
 
acp63
Member
 
Total Posts:  73
Joined:  2009-03-12
 

Any ideas this is occurring with a fresh install of Professional with the rewards module

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`xxxxxxxxx/enterprise_reward`, CONSTRAINT `FK_REWARD_CUSTOMER_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE)

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

set “SET foreign_key_checks = 0” on your mysql_setup file.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gbromios
Jr. Member
 
Total Posts:  1
Joined:  2011-08-25
 
Gaurav Mehta - 19 July 2011 09:25 PM

set “SET foreign_key_checks = 0” on your mysql_setup file.

I’m not finding where this mysql_setup file is. Can you please expand on that? I’d appreciate it!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lyonscg
Sr. Member
 
Avatar
Total Posts:  173
Joined:  2009-11-13
Chicago IL
 

He is referring to your sql file (MySQL dump). You can do the foreign key check through phpMyAdmin during the export process. The option is a checkbox near the top of the page.

If you’re not using phpMyAdmin or something like it you can open the sql file and insert the foreign key check near the top.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Greygorn
Jr. Member
 
Avatar
Total Posts:  1
Joined:  2009-11-15
Leeds
 

Hi, I’m also getting the error, I’ve tried disabling the Rewards module in the XML config files but the error still occurs? Any one know if its safe to remove the FK contraint?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Shahil
Member
 
Total Posts:  36
Joined:  2008-05-19
 

File Path: app/code/core/Enterprise/Reward/Model/Observer.php
Function:_revertRewardPointsForOrder
Line Number: 540

Current code is:

protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
    
{
        Mage
::getModel('enterprise_reward/reward')
            ->
setCustomerId($order->getCustomerId())
            ->
setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
            ->
setPointsDelta($order->getRewardPointsBalance())
            ->
setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
            ->
setActionEntity($order)
            ->
updateRewardPoints();

        return 
$this;
    
}

Replace it with

protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
    
{
        
if (!$order->getCustomer()->getId()) {
            
return $this;
        
}

        Mage
::getModel('enterprise_reward/reward')
            ->
setCustomerId($order->getCustomerId())
            ->
setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
            ->
setPointsDelta($order->getRewardPointsBalance())
            ->
setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
            ->
setActionEntity($order)
            ->
updateRewardPoints();

        return 
$this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
designer84
Sr. Member
 
Total Posts:  102
Joined:  2009-08-20
 

We’ve tried this fix for a few months now and although it seemed to work at first, we still get orders trickling in with this error. Does anyone know of another fix we could try? Would upgrading to the latest version solve this issue?

Shahil - 22 December 2011 04:13 AM

File Path: app/code/core/Enterprise/Reward/Model/Observer.php
Function:_revertRewardPointsForOrder
Line Number: 540

Current code is:

protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
    
{
        Mage
::getModel('enterprise_reward/reward')
            ->
setCustomerId($order->getCustomerId())
            ->
setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
            ->
setPointsDelta($order->getRewardPointsBalance())
            ->
setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
            ->
setActionEntity($order)
            ->
updateRewardPoints();

        return 
$this;
    
}

Replace it with
protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
    
{
        
if (!$order->getCustomer()->getId()) {
            
return $this;
        
}

        Mage
::getModel('enterprise_reward/reward')
            ->
setCustomerId($order->getCustomerId())
            ->
setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
            ->
setPointsDelta($order->getRewardPointsBalance())
            ->
setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
            ->
setActionEntity($order)
            ->
updateRewardPoints();

        return 
$this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
aaronventi
Jr. Member
 
Total Posts:  1
Joined:  2012-08-14
 

Here is the code that appears in Magento Enterprise 1.12.0.2.  Pretty similar.

Location:  /app/code/core/Enterprise/Reward/Model/Observer.php
Line:  563

/**
     * Revert authorized reward points amount for order
     *
     * @param   Mage_Sales_Model_Order $order
     * @return  Enterprise_Reward_Model_Observer
     */
    protected function _revertRewardPointsForOrder(Mage_Sales_Model_Order $order)
    
{
        
if (!$order->getCustomer()->getId()) {
            
return $this;
        
}
        Mage
::getModel(\'enterprise_reward/reward\')
            ->
setCustomerId($order->getCustomer()->getId())
            ->
setWebsiteId(Mage::app()->getStore($order->getStoreId())->getWebsiteId())
            ->
setPointsDelta($order->getRewardPointsBalance())
            ->
setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_REVERT)
            ->
setActionEntity($order)
            ->
updateRewardPoints();

        return 
$this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top