Question

Je suis en train de modifier mes attributs configurables options que je l'ai mis dans Magento, mais sur save je reçois une erreur de PDO en disant qu'il est un doublon. Je ne l'ai pas été en mesure de trouver un moyen de mettre ces travers catalogue / produit, catalogue / product_type_configurable_attribute ou dans le catalogue / product_type_configurable mais ce fut ma tentative meilleure et la plus compréhensible. Quelqu'un peut-il me dire la meilleure façon de changer ces données? Merci!

// Get a collection of all the configurables
$productConfig = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', 'configurable');
foreach($productConfig as $product) {
    // Get an array of all of the configurable products and their options
    $product_attribute_options = $product->getTypeInstance(true)->getConfigurableOptions($product);
    $product_attribute_options = array_shift($product_attribute_options);
    foreach($product_attribute_options as & $child) {
        // Adjust arrays price in here
    }
    // Get a new fresh product just in case the collection product doesn't have everything. 
    $config_product = Mage::getModel('catalog/product');
    $config_product->load($product->getId());
    // Set and save
    $config_product->setCanSaveConfigurableAttributes(true);
    $config_product->setConfigurableAttributesData($product_attribute_options);
    $config_product->save();
}

Et voici l'erreur PDO:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2864-0' for key 'UNQ_CATALOG_PRODUCT_SUPER_ATTRIBUTE_PRODUCT_ID_ATTRIBUTE_ID'' in /lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#1 /lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#5 /lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pd in /lib/Zend/Db/Statement/Pdo.php on line 234
Était-ce utile?

La solution

Le problème a fini par être le array_shift, je fini par l'extension de la boucle foreach et il fonctionne maintenant.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top