簡體   English   中英

在list.phtml中顯示產品屬性 - Magento

[英]Show product attributes in list.phtml - Magento

您好我已經閱讀了很多關於此的帖子,雖然它的工作原理尚不完整。

例如; 屬性1 =鞋類和屬性2 =鞋色。 兩者都在下拉列表中,我想在類別頁面中列出每個產品的所有可能的屬性顏色。

問題:當我測試代碼時,它只顯示第一個鞋子顏色,而不是所有的posibilites。 我在這做錯了什么?

以下是我所擁有的3個例子。 所有代碼都有效,但只顯示第一個屬性顏色。 例1:

<!-- Find the following loop -->
<?php foreach ($_productCollection as $_product): ?>
<!-- Inside it insert one of the following codes as needed -->
<!-- Use this for regular text attributes -->
<?php echo $_product->getMyAttribute() ?>
<?php echo $_product->getAnotherCustomAttribute() ?>

<!-- Use this for dropdown attributes -->
<?php echo $_product->getAttributeText('shoecolor') ?>
<?php endforeach?>
<!-- ... --> 

例2

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

例3

<?php $type = "simple"; $p = "0" ?> 
<?php foreach ($_productCollection as $_product): ?> 
<?php $custom = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); ?> 
<?php $col = $custom->getUsedProductCollection()->addAttributeToSelect('shoecolor')->addFilterByRequiredOptions(); ?> 
<?php foreach($col as $simple_product) { $p=$simple_product->getId(); $type="configurable"; } ?> 

<?php if($type == "configurable"): ?> 
<h5><?php echo $_product->load($p)->getAttributeText('shoecolor'); ?><?php $type="simple" ?></h5> 
 <?php endif; ?> 

你可以在屬性編輯頁面中配置它

用於產品列表 - >是

其他方式

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

如果你創建一個像你的“shoesize”這樣的屬性,那么你可以通過以下代碼訪問。

如果您的屬性類型為Text Field($ _product應加載):

<?php
  echo $_product->getShoesize();
  // if your arribute was shoe_size then
  echo $_product->getShoeSize();
?>

如果您的屬性類型為Multiple Select或Dropdown,則獲取所有屬性值:

<?php
   echo $_product->getAttributeText('shoesize');
?>

以下是不屬於任何產品的代碼獲取屬性名稱和值

$attributeCode = 'YOUR_ATTRIBUTE_CODE';

$product = Mage::getModel('catalog/product');

$productCollection = Mage::getResourceModel('eav/entity_attribute_collection')
   ->setEntityTypeFilter($product->getResource()->getTypeId())
   ->addFieldToFilter('attribute_code', $attributeCode);

$attribute = $productCollection->getFirstItem()->setEntity($product->getResource());
print_r($attribute->getData()); // print out the available attributes

$options = $attribute->getSource()->getAllOptions(false);
print_r($options); // print out attribute options

嘗試這個:

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

在:

 <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>

屬性代碼:dm

Type: Text area

在view.phtml中

echo $_product->get>getdm(); ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM