简体   繁体   English

Magento自定义属性值将显示在购物车页面上

[英]Magento custom attribute value to be shown on cart page

In Magento,I have functionality where, a product has multiple colors, user can select quantity and color for product on product view page, where a product has different colors, 在Magento中,我具有以下功能:产品具有多种颜色,用户可以在产品查看页面上为产品选择数量和颜色,其中产品具有不同的颜色,

I need to show selected color on a cart page. 我需要在购物车页面上显示选定的颜色。 I tried following code. 我尝试了以下代码。

  <?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo     $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); 

but it returns all color values for a product on cart page, instead of selected value for cart page. 但是它将返回购物车页面上某个产品的所有颜色值,而不是购物车页面上的选定值。

any ideas? 有任何想法吗?

There are 2 main options for a product to have multiple colors: 产品具有两种颜色的主要选择有两种:

  1. Configurable products: 可配置产品:
    If you are using configurable products then you can get you color attribute like this: 如果您使用的是可配置产品,则可以使用以下颜色属性:

     <?php $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('color_attribute')); echo $product->getColorAttribute(); ?></code> 

    Replace 'color_attribute' and getColorAttribute with your attribute name. 用您的属性名称替换'color_attribute'和getColorAttribute。

  2. Custom options: 自定义选项:
    In this case use: 在这种情况下,请使用:

     <?php print_r($_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct())); ?> 

    And look for the options you need to display. 并查找您需要显示的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM