简体   繁体   English

在list.phtml中显示产品属性 - Magento

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

Hello I have read many posts about this, and while it works its not complete. 您好我已经阅读了很多关于此的帖子,虽然它的工作原理尚不完整。

For example; 例如; Attribute 1= shoesize and attribute 2 = shoe color. 属性1 =鞋类和属性2 =鞋色。 Both are in a dropdown and I would like to list all of the possible attribute colors per product within the category pages. 两者都在下拉列表中,我想在类别页面中列出每个产品的所有可能的属性颜色。

Problem: When I test the code it will only display the first shoe color, instead of all posibilites. 问题:当我测试代码时,它只显示第一个鞋子颜色,而不是所有的posibilites。 What am I doing wrong here? 我在这做错了什么?

Here are 3 examples of what I have. 以下是我所拥有的3个例子。 All code work, but only shows the first attribute color. 所有代码都有效,但只显示第一个属性颜色。 Example 1: 例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?>
<!-- ... --> 

Example 2 例2

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

Example 3 例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; ?> 

you can just config it in attribute edit page 你可以在属性编辑页面中配置它

Used in Product Listing -> Yes 用于产品列表 - >是

Another way 其他方式

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

If you create an attribute like yours "shoesize" then you can access by following code. 如果你创建一个像你的“shoesize”这样的属性,那么你可以通过以下代码访问。

If your attribute type Text Field ( $_product should loaded ) : 如果您的属性类型为Text Field($ _product应加载):

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

If your attribute type Multiple Select or Dropdown, to get all attribute value : 如果您的属性类型为Multiple Select或Dropdown,则获取所有属性值:

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

Here is the code get attribute name and value that that doesn't belongs to any product 以下是不属于任何产品的代码获取属性名称和值

$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

Try this: 尝试这个:

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

in: 在:

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

Attribute Code:dm 属性代码:dm

Type: Text area

in view.phtml 在view.phtml中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM