2012-07-16 121 views
0

顯示的顏色和大小的屬性,我有一個工作代碼在Magento產品頁

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

echo '<p>Product name :',$cModel->getData('name'),'</p>'; 
echo '<p>Manufacturer id :',$cModel->getData('manufacturer'),'</p>'; 

$attributes = Mage::getResourceModel('eav/entity_attribute_collection') 
     ->setEntityTypeFilter($_product->getResource()->getTypeId()) 

     ->addFieldToFilter('attribute_code', 'manufacturer'); 
$attribute = $attributes->getFirstItem()->setEntity($_product->getResource()); 

echo '<p> Manufacturer :',$attribute->getSource()->getOptionText($cModel->getData('manufacturer')),'</p>'; 

它正在與製造商。但不適用於大小和顏色屬性。謝謝。

+0

有兩個問題:它們是什麼類型的產品屬性? (文本,下拉等)另外,你可以發佈代碼,你試圖獲取大小和顏色屬性的值嗎? – Jason 2013-08-08 16:12:11

回答

1

在目錄 - >屬性 - >管理屬性下,您必須確保所提及的屬性對於「產品清單中使用」選項的值爲「是」。

+0

我已將產品清單中的「已使用」設置爲「是」。但沒用。 – user1528635 2012-07-16 11:13:21

1

你試過<?php echo $_product->getAttributeText("color"); ?>

+0

沒有爲我工作 – ahnbizcad 2015-09-08 19:08:41

0

如果您正在使用下拉菜單的屬性添加在您的/template/catalog/product/view.phtml文件下面的代碼

這將顯示你的第一屬性

<?php if ($_product->isSaleable() && $this->hasOptions()):?> 
<?php echo $this->getChildChildHtml('container1', '', true, true) ?> 
<?php endif;?> 

這將顯示您的第二個屬性(超過1個自定義屬性)

<?php if ($_product->isSaleable() && $this->hasOptions()):?> 
<?php echo $this->getChildChildHtml('container2', '', true, true) ?> 
<?php endif;?>