2012-07-16 134 views
0

誰能告訴我如何更新Magento中購物車中已有的可配置產品的選項(使用下拉選擇)。更新Magento 1.6.2購物車中已配置產品的選項

我把代碼顯示在以下文件中的可配置產品的超級屬性選項(使用下拉列表):magento\app\design\frontend\default\theme-name\template\checkout\cart\item\default.phtml

我發現這個代碼行:

<?php if ($_options = $this->getOptionList()):?> 

在那之後,我把我的代碼,以示對配置的產品,其做工精細屬性下拉列表中,但我需要更新超級屬性選項當我從超級屬性下拉列表中選擇另一個選項時,該產品的值。下面是我的代碼來顯示下拉列表:

<?php 
if($this->getProduct()->isConfigurable()){ 
    $_product = Mage::getModel('catalog/product')->load($this->getProduct()->getId()); 
    Mage::getBlockSingleton('catalog/product_view_type_configurable')->unsetData(); 
    $_configurable = Mage::getBlockSingleton('catalog/product_view_type_configurable')->setData('product', $_product); 
    $_cdata = json_decode($_configurable->getJsonConfig()); 
    $_current = array(); 
    foreach((array)$this->getOptionList() as $_option) { 
     $_current[$_option['label']]=$_option['value']; 
    } 
    foreach($_cdata->attributes as $attribute) { 
     ?> 
     <strong><?php echo $attribute->label; 
     $catchlabel = $attribute->label; 
     if($catchlabel == 'Clipboard Color'): 
      $SelectOptions = "selectAtt"; 
     else: 
      $SelectOptions = "selectFont"; 
     endif; 
     ?> 
     </strong> 
     <select style="width: 150px;" 
name="cart[<?php echo $_item->getId() ?>][option][<?php echo $attribute->id ?>]" 
id="<?php echo $_item->getId(); ?>_<?php echo $attribute->id; ?>" 
class="<?php echo $SelectOptions; ?>"> 
      <?php 
      foreach($attribute->options as $option) { 
       ?> 
       <option 
       <?php echo ($_current[$attribute->label]==$option->label) ? ' selected' : '' ?> 
        value="<?php echo $option->id ?>"> 
        <?php echo $option->label ?> 

       </option> 
       <?php 
      } 
      ?> 
     </select> 
     <script type="text/javascript"> 
      jQuery('#<?php echo $_item->getId(); ?>_<?php echo $attribute->id; ?>').change(function() { 
       var getOption = jQuery('#<?php echo $_item->getId(); ?>_<?php echo $attribute->id; ?>').val(); 
       // something to do here for update attibute options for current product 
       alert(getOption); 
      }); 
     </script> <?php 
    } 
} 
?> 

請告訴我如何更新所選可配置產品的超級屬性選項。

回答

0

您需要將新的配置信息提交給處理更新的控制器操作。

Magento沒有這樣的控制器操作,但是,當您在購物車中編輯單個可配置產品時,您將獲得帶有稍微不同標記的產品視圖。該頁面中的表單用於編輯購物車中的產品,而不是添加新的產品。

您應該檢查該控制器操作中的算法並使用控制器創建一個模塊,該控制器將該算法應用於您的購物車中的每個產品

相關問題