0

Controller File:

public function editAction()
{                                                                                                                                                         
   $quoteId=$this->getRequest()->getParam("quoteid");
   $quote = Mage::getModel('sales/quote')->load($quoteId);
   Mage::dispatchEvent('checkout_cart_product_add_after', $quote);
}

Observer File:

public function changePrice($observer) {
$item = $observer->getEvent()->getQuote();
echo "<pre>";print_r($item->getProductId());
exit();

How to get Product Id in Observer from Item?

If you have any idea then share here please.

Thank You.

  • Please confirm the magento version – NIPPU Apr 27 '18 at 4:52
  • @NagarajuKasa Thank for the reply. Magento Ver: 1.9.3.3 – Ashish Kacha Apr 27 '18 at 4:53
  • try like this $productId = $item->getProduct()->getId(); – NIPPU Apr 27 '18 at 4:58
  • We get Item Object with $item = $observer->getEvent(); but product Id not exist in it. – Ashish Kacha Apr 27 '18 at 5:08
  • @NagarajuKasa any idea you have? – Ashish Kacha Apr 27 '18 at 6:10
0

Use any of the following according to your requirement

$items = $observer->getEvent()->getQuote()->getAllItems();

or

$items = $observer->getEvent()->getQuote()->getAllVisibleItems();

Both will provide you with the array

foreach($items as item){
    $item->getData(); //this will give you all the necessary information about the item
}
  • thanks for the reply. Not Working for me. – Ashish Kacha Apr 27 '18 at 5:04
  • We get Item Object with $item = $observer->getEvent(); but product Id not exist in it. – Ashish Kacha Apr 27 '18 at 5:14
  • If I am not wrong then, $observer->getEvent(); will give you the event object and not the item object. Check again by using xdebug or var_dump the object. – Anshu Mishra Apr 27 '18 at 5:22
  • Yes, you are right. – Ashish Kacha Apr 27 '18 at 5:25
  • any idea you have? – Ashish Kacha Apr 27 '18 at 6:09

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.