1

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 ?

1 Answer 1

3

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();
1
  • Many thanks for answer, but I am working with configurable product and $productID = $_item->getProductId(); returns always parent id. Is any way to get child product id in cart ?
    – paicubes
    May 5, 2014 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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