質問

Magentoで設定した設定可能な属性オプションを変更しようとしていますが、Saveを使用すると、PDOエラーが重複していると言っています。 Catalog/Product、Catalog/Product_Type_Configurable_Attribute、またはCatalog/Product_Type_Configurableを使用してこれらを設定する方法を見つけることができませんでしたが、これは私の最高で最も理解できる試みでした。誰かがこのデータを変更する最良の方法を教えてもらえますか?ありがとうございました!

// 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();
}

そして、これが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
役に立ちましたか?

解決

問題は最終的にArray_shiftになりました。私は最終的にforeachループを拡張し、現在機能しています。

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top