1

这是我在 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');

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

4

3 回答 3

0

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

echo $_product->getData('width');
echo $_product->getData('height');
echo $_product->getData('depth');
于 2013-10-11T13:29:46.700 回答
0

尝试这个

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

    }
}
于 2013-04-14T08:20:13.963 回答
0

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

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

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

于 2014-11-11T07:41:42.390 回答