2013-10-24 66 views
0

Magento 1.6.1.0版。我試圖編寫一些代碼來動態更新可配置產品選項的價格。我的最終目標是編寫一個模塊,根據可配置產品的價格更新可配置產品選件的價格。所附代碼從目錄中抽出所有可配置產品,並將其與產品選項&價格以及兒童產品名稱&價格一起顯示。我計劃解決可配置產品和每個兒童產品之間的價格差異,並更新適當的價格選項以匹配。到目前爲止,我一直無法解決如何更新產品選項的價格。Magento - 更新可配置產品選項的價格

短版本:我只需要一種方法來更新可配置產品的選項的價格。你知道如何做到這一點?

<?php 
require_once './app/Mage.php'; 
Mage::app(); 
Mage::app()->setCurrentStore(1); 

// load in configurable products 
$productConfig = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', 'configurable'); 
foreach ($productConfig as $_product) 
{ 
    // load the configurable product 
    $_product = Mage::getModel('catalog/product')->load($_product->getId()); 
    echo 'Product Name'; 
    var_dump ($_product->getName()); 
    var_dump ($_product->getPrice()); 
    // Collect options applicable to the configurable product 
    $productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product); 
    $attributeOptions = array(); 
    foreach ($productAttributeOptions as $productAttribute) 
     { 
     var_dump($productAttribute['label']); 
     foreach ($productAttribute['values'] as $attribute) 
      { 
      var_dump($attribute); 
      } 
     } 

    // loop through the child products 
    echo 'Child products'; 
    $col = Mage::getModel('catalog/product_type_configurable')->setProduct($_product)->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); 
    foreach($col as $simple_product) 
    { 
     var_dump($simple_product->getName()); 
     var_dump($simple_product->getPrice()); 
    } 
} 
echo '~fin'; 
?> 

謝謝!

回答

0

好吧,我解決了這個問題後,相當多的頭撓。我不知道我是否做到了「正確」。

我通過手動運行一些SQL來調整catalog_product_super_attribute_pricing表中的定價來解決這個問題。如果您要這樣做,則需要一個product_super_attribute_id,如果您有產品ID,則可以從catalog_product_super_attribute表中獲得該表。

一個警告:如果某個選項的後端不存在價格(如果該選項存在,但在選擇時將產品價格加上0英鎊),catalog_product_super_attribute_pricing表中的選項將不會有記錄,那麼在這種情況下,您將需要插入查詢而不是更新。

0

我有同樣的問題,我開始做同樣的事情:編寫一個模塊來更新可配置產品的選項。

我最近發表在這裏:Magento Configurable Auto Pricing

我測試了它只是EE 1.12,但應與CE也工作,如果有人想嘗試一下,給我任何反饋,甚至更好寫我會很高興他自己的修復和承諾:)

相關問題