I am trying to create a product importer in Magento. Probably exception is thrown by the line: $product->setConfigurableProductsData($configurableProductsData);
. When I comment it, no exceptions are thrown. What is wrong with the array?
$configurableProductsData = Array
(
[0] => Array
(
[0] => Array
(
[attribute_id] => 135
[label] => 00
[value_index] => 48
[is_percent] => 0
[pricing_value] => 0
)
[1] => Array
(
[attribute_id] => 92
[label] => Print
[value_index] => 511
[is_percent] => 0
[pricing_value] => 0
)
)
[1] => Array
(
[0] => Array
(
[attribute_id] => 135
[label] => 0
[value_index] => 48
[is_percent] => 0
[pricing_value] => 0
)
[1] => Array
(
[attribute_id] => 92
[label] => Print
[value_index] => 511
[is_percent] => 0
[pricing_value] => 0
)
)
[2] => Array
(
[0] => Array
(
[attribute_id] => 135
[label] => 2
[value_index] => 49
[is_percent] => 0
[pricing_value] => 0
)
[1] => Array
(
[attribute_id] => 92
[label] => Print
[value_index] => 511
[is_percent] => 0
[pricing_value] => 0
)
)
)
Exception:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`c1_estelles`.`catalog_product_super_link`, CONSTRAINT `FK_CAT_PRD_SPR_LNK_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE C)' in /var/www/clients/client1/web97/web/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/clients/client1/web97/web/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/clients/client1/web97/web/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/clients/client1/web97/web/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/clients/client1/web97/web/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
Best Answer
The error's right there for you to see
PHP is telling you it can't perform the SQL you asked it to perform, because a SQL foreign key constraint failed.
If you look at the details of the error, you know this is on the table
catalog_product_super_link
.and it's the key named
FK_CAT_PRD_SPR_LNK_PRD_ID_CAT_PRD_ENTT_ENTT_ID
.You can look at the table definition if you run the following SQL query.
The specific definition for our key is
In plain english, that's saying "Every
product_id
incatalog_product_super_link
needs to have a correspondingentity_id
incatalog_product_entity
".So, there's nothing specifically wrong with your array of information — the problem seems to be in your program logic. My guess would be you're inserting those attributes before the actual product is saved to the
catalog_product_entity
table.