0

I am using magento 1.7 and i need to display description of related products on product page. I am getting name ,image and URL of related products through related.phtml but not getting description.

And i also want add to cart button there which will add that related product to the cart.

Thanks in advance,

  • what will $_item->getDescription() give you? – Mufaddal May 20 '13 at 11:00
3

Ok description is not loaded by default so what I had do was ugly way of displaying description on related product.

In foreach loop you can get product id from this $_item->getEntityId()

And from id load product model $product = Mage::getModel('catalog/product')->load($_item->getEntityId());

$product->getDescription() give you description of product.

And for add to cart button remove your checkbox input field put something like this

<a href="<?php echo Mage::getBaseUrl() ?>checkout/cart/add/product/<?php echo $_item->getId();?>">Add to cart </a>

thus you can have individual add to cart link.

4

To me, its inefficient to load the product in its whole when u can get a smaller option.

$this->helper('catalog/output')->productAttribute($_item, nl2br($_item->getDescription()), 'description');

The above would also do the trick and doesn't require loading the whole product object. The processing would be the same as short_description. Yes, this isn't loaded by default but you can just use the attribute by enabling product listing on the attribute you need.

For the record, if you are planning on using larger descriptions you might want to cut them off. I usually do something like this:

<?php echo Mage::helper('core/string')->truncate($this->helper('catalog/output')->productAttribute($_item, nl2br($_item->getDescription()), 'description'),240) ?>
  • interesting that I cannot make this work with the short_description attribute even when enabling product listing - any thoughts? – philwinkle Jun 19 '14 at 2:40
  • @philwinkle will take a look at this tommorow, haven't tried it with short_description yet. Thanks for the feedback! – Toon Van Dooren Jun 20 '14 at 8:05
  • @philwinkle i noticed it is not in the default collection but you can add it trough layout.xml or code by using addAttribute / addAttributeToSelect, I haven't found out why yet because it is present in flat tables. It's like its being treated as a "custom attribute" – Toon Van Dooren Nov 6 '14 at 22:39
2

I needed the short description in the Related Products list after my 'virtual' product description (1 column layout). This worked for me.

<div class="product-details">

<?php echo $this->helper('catalog/output')->productAttribute($_item, nl2br($_item->getShortDescription()), 'short_description'); ?>

</div>

  • This was in the "related.phtml" file. – user3231256 Feb 14 '14 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.