Wednesday, 8 August 2012

Magento- Adding Short Description to the View Cart page

Magento’s default view cart page includes a  product thumbnail and the product name, as shown below.
What if you wanted to add the short description to the view cart page, to help give customers a better idea of the product they have added to their cart? How would you do that?
The view cart page is controlled by default.phtml, which is located  in app/design/frontend/blank/default/template/checkout/cart/item/default.html. Of course, you will want to place the default.phtml file in your theme folder– app/design/frontend/default/your-theme/template/checkout/cart/item/default.html.
So let’s take a look at the code.

At line 34, Magento begins building the product name, which is displayed in the view cart page,
<h2>
<?php if ($this->hasProductUrl()):?>
<a href=”<?php echo $this->getProductUrl() ?>”><?php echo $this->htmlEscape($this->getProductName()) ?></a>
<?php else: ?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php endif; ?>
</h2>
We want to place the short description right after the product name, so we’ll add the following piece of code right after the closing </h2> tag:
<?php
$custom = Mage::getModel(‘catalog/product’)->load($_item->getProductId());
echo $custom->getShortDescription();
?>

***********************************************************************
Any other information, including custom attributes could also be added, for example if you had a custom attribute called dimension, and you wanted to add it before the short description, the code would look like this (from line 34)–

<h2>
<?php if ($this->hasProductUrl()):?>
<a href=”<?php echo $this->getProductUrl() ?>”><?php echo $this->htmlEscape($this->getProductName()) ?></a>
<?php else: ?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php endif; ?>
</h2>
<?php
$custom = Mage::getModel(‘catalog/product’)->load($_item->getProductId());
echo $custom->getdimensions();
?>
<?php
$custom = Mage::getModel(‘catalog/product’)->load($_item->getProductId());
echo $custom->getShortDescription();
?>
Any attribute you wanted to display on the view cart page could be handled in this manner, so take a look at your View Cart Page, and make it more user-friendly.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.