Show product attributes in list.phtml - Magento

Hello, I read a lot of posts about this, and so far it has not fully worked.

For instance; Attribute 1 = shoes and attribute 2 = color of shoes. Both are in the drop-down list, and I would like to indicate all the possible attribute colors for each product on the category pages.

Problem: when I test the code, it will display only the first color of the shoe, and not all posibilites. What am I doing wrong here?

Here are 3 examples of what I have. All code works, but only shows the first color of the attribute. 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; ?> 
+4
source share
4 answers

Here is the name and value of the get get attribute that does not belong 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 
+1
source

you can just customize it on the attribute edit page

Used in product listing → Yes

+14
source

Another way

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

If you create an attribute like your shoes, you can access by following the code.

If your attribute type is Text Field ($ _product must be loaded):

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

If your attribute type is Multiple Select or Dropdown to get all attribute values:

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

Try the following:

 $_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

 Type: Text area 

in view.phtml

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

Source: https://habr.com/ru/post/1387564/


All Articles