【问题标题】:Magento: getting attribute values in cartMagento:在购物车中获取属性值
【发布时间】:2013-04-13 23:28:16
【问题描述】:

这是我在 Magento 中的第一个项目,我在尝试获取我的购物车项目的属性值时遇到了问题。我现在所拥有的没有显示任何东西。我有 3 个基本属性(宽度、高度、深度)和一个可配置属性(织物)。这是我在 default.phtml 中用于结帐项目的内容:

$_item = $this->getItem();
$_product = Mage::getModel('catalog/product')->load($_item->getProductId());

echo $_product->getWidth();
echo $_product->getHeight();
echo $_product->getDepth();

echo $_product->getAttributeText('fabric');

如果有人能告诉我如何让它工作,我将不胜感激。谢谢。

【问题讨论】:

  • var_dump($_product) 是否显示任何内容?

标签: magento attributes cart


【解决方案1】:

试试这个

$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) {
    if ($attribute->getIsVisibleOnFront()) {
      echo  $value = $attribute->getFrontend()->getValue($_product);

    }
}

【讨论】:

    【解决方案2】:

    当你添加你的属性时,你给了他们一个属性代码,只有小写和下划线。 (目录 > 属性 > 管理属性,属性代码通常列在左侧)。假设您将它们命名为类似于它们的描述,那么......

    echo $_product->getData('width');
    echo $_product->getData('height');
    echo $_product->getData('depth');
    

    【讨论】:

      【解决方案3】:

      对于下拉属性类型在购物车中获取值可以通过以下代码完成:

      echo nl2br($_product->getResource()->getAttribute('fabric')->getFrontend()->getValue($_product));

      面料是属性代码。您可以在此处使用您的属性代码。

      【讨论】:

        猜你喜欢
        • 2012-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多