Magento – add extra field with product on cart.phtml magento

magento-1.8

I want to show attachment link with every product which is in cart. I only need product id on cart.phtml, but product are rendering with this code

   <?php foreach($this->getItems() as $_item): ?>
       <?php echo $this->getItemHtml($_item) ?>                                      
    <?php endforeach ?>`

and I am unable to fetch product Id, how can I get product Id so that I can show link with every product in cart.

I am working with configurable product and $productID = $_item->getProductId(); returns always parent id. Is any way to get child product id in cart ?

Best Answer

When you turn on hints in System>Config>Developer (on the bottom of the left list), you'll see that each line item in the cart is a reference to an instance of cart/item/default.phtml. (this is what getItemHtml() is generating on this pYou'll also see, at the top of this file, a line of code along the lines of:

$_item = $this->getItem();

$_item is of type Mage_Sales_Model_Quote_Item, so we can access quote variables from it, for instance:

$productID = $_item->getProductId();
Related Topic