在产品页面中显示自定义属性?

问题描述 投票:3回答:4

我是Magento Go的新手,我想在产品描述页面中有两个自定义字段:功能和规格。似乎我需要使用“自定义属性”来实现这一点,所以我这样做了,但自定义属性不会出现在产品页面中?如何制作以便它出现在产品页面中?

magento magento-go
4个回答
2
投票

当您创建自定义属性“在前端的产品视图页面上可见”时,将此选项设置为YES,它将在产品页面上显示该属性...


2
投票

您可以通过以下方式打印产品自定义属性的方法很少:

1. $getPrdocutData = $_product->getData();

这将为您提供所有产品属性的数组,以便您可以使用它。

2. $attributes = $product->getAttributes();
   foreach ($attributes as $attribute) {
      if ($attribute->getIsVisibleOnFront()) {
         $value = $attribute->getFrontend()->getValue($product);
        // do something with $value here
      }
   }

3. $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
    foreach ($productAttrs as $productAttr) { 
        /** $productAttr Mage_Catalog_Model_Resource_Eav_Attribute */
        var_dump($productAttr->getAttributeCode());
    }

请尝试上面的代码来显示产品属性。


2
投票

要在产品页面上显示属性的内容,您需要在view.phtml文件中添加以下代码。

<?php echo $_product->getResource()->getAttribute('brand_info')->getFrontend()->getValue($_product); ?>

1
投票

在产品页面上添加代码以显示产品定义属性的所有属性必须在首页上应用选项产品视图设置是:

<?php echo $this->getLayout()->
      createBlock('catalog/product_view_attributes', '', 
      array('template'=> 'catalog/product/view/attributes.phtml'))->toHtml(); 
?>

您可以使用此选择属性来使用此代码:

$Designer = Mage::getModel('catalog/product')->load($_product->getId())->
getAttributeText('manufacturer'); 


<?php if($Designer): ?>
        <div class="details"><p><span>Designer:</span> 
<?php echo Mage::getModel('catalog/product')->load($_product->getId())->
       getAttributeText('manufacturer');
?></p></div>
<?php endif; ?>
© www.soinside.com 2019 - 2024. All rights reserved.