Ändern Sie die Preisanpassung konfigurierbarer Produkte durch API.
-
16-10-2019 - |
Frage
Ich versuche, meine konfigurierbaren Attributeoptionen zu ändern, die ich in Magento festgelegt habe, aber beim Speichern erhalte ich einen PDO -Fehler, der besagt, dass es sich um ein Duplikat handelt. Ich konnte diese keine Möglichkeit finden, diese durch Katalog/Produkt, Katalog/product_type_configurable_attribute oder Katalog/product_type_configurable festzulegen, aber dies war mein bester und verständlichste Versuch. Kann mir jemand sagen, wie ich diese Daten am besten ändern kann? Vielen Dank!
// 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();
}
Und hier ist der PDO -Fehler:
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
Lösung
Das Problem war das Array_Shift, ich habe die Foreach -Schleife erweitert und es funktioniert jetzt.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange