Skip to main content
Typo fix: $_product->load($_product->getId()) updated to ->setProduct($_product->load($_product->getId()))
Source Link
jiheison
  • 632
  • 3
  • 6

The block class Mage_Catalog_Block_Product_View_Attributes expects to get a product object out of the registry:

    function getProduct()
    {
        if (!$this->_product) {
            $this->_product = Mage::registry('product');
        }
        return $this->_product;
    }

A PLP doesn't register a product (since there are many), so the attributes block has no data to work with.

I tried setting a product in the createBlock call, but it looks like Mage_Catalog_Block_Product_View_Attributes is not written in a way that makes this possible. This is the code that does not work for me.

<?php
        echo $this->getLayout()->createBlock('catalog/product_view_attributes')
       ->setProduct($_product->load($_product->getId()))
       ->setTemplate('catalog/product/view/attributes.phtml')
       ->toHtml(); 
?>

Note that $_product here comes from the main loop in catalog/product/list.phtml. Since it is a member of a collection rather than a directly loaded product object, I had to load it explicitly. This comes with a significant performance hit.

You may be able to customize your Magento to make this work, but I don't think it is the best approach. It would be better to load the attributes that you want to see with the PLP product collection, i.e. via their "Used in Product Listing" setting. Then adapt the catalog/product/view/attributes.phtml template content for use in your PLP template, using the $_product object that is available.

The block class Mage_Catalog_Block_Product_View_Attributes expects to get a product object out of the registry:

    function getProduct()
    {
        if (!$this->_product) {
            $this->_product = Mage::registry('product');
        }
        return $this->_product;
    }

A PLP doesn't register a product (since there are many), so the attributes block has no data to work with.

I tried setting a product in the createBlock call, but it looks like Mage_Catalog_Block_Product_View_Attributes is not written in a way that makes this possible. This is the code that does not work for me.

<?php
        echo $this->getLayout()->createBlock('catalog/product_view_attributes')
       ->setProduct($_product->load($_product->getId())
       ->setTemplate('catalog/product/view/attributes.phtml')
       ->toHtml(); 
?>

Note that $_product here comes from the main loop in catalog/product/list.phtml. Since it is a member of a collection rather than a directly loaded product object, I had to load it explicitly. This comes with a significant performance hit.

You may be able to customize your Magento to make this work, but I don't think it is the best approach. It would be better to load the attributes that you want to see with the PLP product collection, i.e. via their "Used in Product Listing" setting. Then adapt the catalog/product/view/attributes.phtml template content for use in your PLP template, using the $_product object that is available.

The block class Mage_Catalog_Block_Product_View_Attributes expects to get a product object out of the registry:

    function getProduct()
    {
        if (!$this->_product) {
            $this->_product = Mage::registry('product');
        }
        return $this->_product;
    }

A PLP doesn't register a product (since there are many), so the attributes block has no data to work with.

I tried setting a product in the createBlock call, but it looks like Mage_Catalog_Block_Product_View_Attributes is not written in a way that makes this possible. This is the code that does not work for me.

<?php
        echo $this->getLayout()->createBlock('catalog/product_view_attributes')
       ->setProduct($_product->load($_product->getId()))
       ->setTemplate('catalog/product/view/attributes.phtml')
       ->toHtml(); 
?>

Note that $_product here comes from the main loop in catalog/product/list.phtml. Since it is a member of a collection rather than a directly loaded product object, I had to load it explicitly. This comes with a significant performance hit.

You may be able to customize your Magento to make this work, but I don't think it is the best approach. It would be better to load the attributes that you want to see with the PLP product collection, i.e. via their "Used in Product Listing" setting. Then adapt the catalog/product/view/attributes.phtml template content for use in your PLP template, using the $_product object that is available.

Source Link
jiheison
  • 632
  • 3
  • 6

The block class Mage_Catalog_Block_Product_View_Attributes expects to get a product object out of the registry:

    function getProduct()
    {
        if (!$this->_product) {
            $this->_product = Mage::registry('product');
        }
        return $this->_product;
    }

A PLP doesn't register a product (since there are many), so the attributes block has no data to work with.

I tried setting a product in the createBlock call, but it looks like Mage_Catalog_Block_Product_View_Attributes is not written in a way that makes this possible. This is the code that does not work for me.

<?php
        echo $this->getLayout()->createBlock('catalog/product_view_attributes')
       ->setProduct($_product->load($_product->getId())
       ->setTemplate('catalog/product/view/attributes.phtml')
       ->toHtml(); 
?>

Note that $_product here comes from the main loop in catalog/product/list.phtml. Since it is a member of a collection rather than a directly loaded product object, I had to load it explicitly. This comes with a significant performance hit.

You may be able to customize your Magento to make this work, but I don't think it is the best approach. It would be better to load the attributes that you want to see with the PLP product collection, i.e. via their "Used in Product Listing" setting. Then adapt the catalog/product/view/attributes.phtml template content for use in your PLP template, using the $_product object that is available.