Show product attributes in list.phtml - Magento

前端 未结 4 1817
有刺的猬
有刺的猬 2021-01-03 06:39

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

相关标签:
4条回答
  • 2021-01-03 06:58

    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
    
    0 讨论(0)
  • 2021-01-03 07:00

    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

    Type: Text area
    

    in view.phtml

    echo $_product->get>getdm(); ?>
    
    0 讨论(0)
  • 2021-01-03 07:08

    you can just config it in attribute edit page

    Used in Product Listing -> Yes

    0 讨论(0)
  • 2021-01-03 07:16

    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.

    If your attribute type Text Field ( $_product should loaded ) :

    <?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 :

    <?php
       echo $_product->getAttributeText('shoesize');
    ?>
    
    0 讨论(0)
提交回复
热议问题