谁能告诉我如何更新已经在 Magento 购物车中的可配置产品的选项(使用下拉选择)。
我将代码以显示可配置产品的超级属性选项(使用下拉列表)放在以下文件中: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
}
}
?>
请告诉我如何更新所选可配置产品的超属性选项。