显示产品属性在list.phtml - Magento的 [英] Show product attributes in list.phtml - Magento
问题描述
您好我看了一下这个很多帖子,虽然它的工作没有完成。
例如;属性1 = shoesize和属性2 =鞋子的颜色。
两者都是在下拉,我想列出类别页面内的所有单位产品的可能的属性颜色。
问题:当我试code只会显示第一个鞋的颜色,而不是所有posibilites。我在做什么错在这里?
下面是什么,我有3个例子。所有code的工作,但只显示第一个属性的颜色。
实施例1:
<! - 找到下面的循环 - >
?< PHP的foreach($ _productCollection为_product $):>
<! - 它里面插入以下codeS的一个需要 - >
<! - 使用此定期文本属性 - >
<?PHP的echo $ _product-> getMyAttribute()&GT?;
<?PHP的echo $ _product-> getAnotherCustomAttribute()&GT?;<! - 使用此为下拉属性 - >
<?PHP的echo $ _product-> getAttributeText('shoecolor')&GT?;
<?PHP endforeach>
<! - ... - >
例2
<?pre>&LT; PHP的echo $ _product-&GT;的getResource() - GT;的getAttribute('shoecolor') - GT; getFrontend() - GT;的getValue($ _产品)&GT? ;
例3
&LT; PHP $类型=简单; $ p值=0&GT?;
?&LT; PHP的foreach($ _productCollection为_product $):&GT;
?&LT; PHP $定制=法师:: getModel('目录/ product_type_configurable') - GT; setProduct($ _产品); ?&GT;
&LT; PHP $山坳= $custom->getUsedProductCollection()->addAttributeToSelect('shoecolor')->addFilterByRequiredOptions(); ?&GT;
&LT; PHP的foreach($山坳作为simple_product $){$ P = $ simple_product-&GT;的getId(); $ TYPE =配置; ?}&GT;?&LT; PHP如果($类型==配置):&GT;?
?&LT;&H5 GT;&LT; PHP的echo $ _product-&GT;负载($ P) - GT; getAttributeText('shoecolor'); ?&GT;&LT; PHP $类型=简单&GT;&LT; / H5&GT;
&LT; PHP ENDIF; ?&GT;
下面是code获得属性名称和价值,不属于任何产品
$属性code ='YOUR_ATTRIBUTE_ code';$产品=法师:: getModel('目录/产品');$ productCollection =法师:: getResourceModel('EAV / entity_attribute_collection')
- &GT; setEntityTypeFilter($产品 - &GT;的getResource() - GT; getTypeId())
- &GT; addFieldToFilter('attribute_ code',$属性code);$属性= $ productCollection-&GT; getFirstItem() - GT; setEntity($产品 - &GT;的getResource());
的print_r($属性 - &GT;的getData()); //打印出可用的属性$选项= $属性 - &GT;的getSource() - GT; getAllOptions(假);
的print_r($选项); //打印属性选项
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. 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. What am I doing wrong here?
Here are 3 examples of what I have. All code work, but only shows the first attribute color. Example 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
<?php echo $_product->getResource()->getAttribute('shoecolor')->getFrontend()->getValue($_product) ?>
Example 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; ?>
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
这篇关于显示产品属性在list.phtml - Magento的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!