将新添加的属性从产品详细信息页面传递到购物车页面(magento)

将新添加的属性从产品详细信息页面传递到购物车页面(magento),magento,magento-1.7,Magento,Magento 1.7,我使用的是Magento 1.7.0版 我在产品详细信息页面中添加了衬衫尺寸(新添加的属性)下拉框。使用以下代码 app\design\frontend\default{mytempalte}\template\catalog\product\view.phtml <?php $product = $_product->getAttributeText('size_chart'); ?> shirt size <select name="size_chart"&g

我使用的是Magento 1.7.0版

我在产品详细信息页面中添加了衬衫尺寸(新添加的属性)下拉框。使用以下代码

app\design\frontend\default{mytempalte}\template\catalog\product\view.phtml

 <?php $product = $_product->getAttributeText('size_chart'); ?>    shirt size
<select name="size_chart">
<option value="Select">Select</option>
<?php for($i = 0;$i < count($product);$i++) { ?>
<option value="<?php echo $product[$i]; ?>"><?php echo $product[$i]; ?></option>
<?php } ?>
</select>
衬衫尺码
挑选

实际上,在购物车页面中,您可以在quote对象中获取购物车项目

$cart = Mage::getModel('checkout/cart')->getQuote();
$items = $cart->getAllVisibleItems();
foreach ($items as $item){
    $options = $item->getProductOptions();
    $superAttributes = $options['info_buyRequest']['super_attribute'];

    if (!!$superAttributes){
        $attributeObjSize = Mage::getModel('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'size_chart');
        $attributeObjSizeId = $attributeObjSize->getAttributeId();

        foreach ($superAttributes as $code=>$superAttribute){
            if ($attributeObjSizeId == $code){
                $sizeCode = $superAttribute;
                $sizeLabel = $attributeObjSize->getSource()->getOptionText($sizeCode);
            }
        }
    }
}
$sizeLabel应该是您想要的。希望它能起作用。

以下内容将非常有用。