2

I have applied this event in my config.xml but I dont know how to get data from this observer. I googled but no article found.

config.xml--

<sales_quote_product_add_after>
    <observers>
        <po>
            <type>singleton</type>
            <class>po/observer</class>
            <method>updateQuote</method>
        </po>
    </observers>
</sales_quote_product_add_after>

Observer file-

public function updateQuote($observer)
{
    Mage::log("testing");
    $quoteItem = $observer->getEvent()->getItems();
    $quote = $quoteItem->getQuote();
    $id = $quote->getId();
    Mage::log($id."hello testing");
}

Getting only "testing" in log file and not getting "hello testing". How can I get info about product added into quote and info of the quote.

  • the Mage::log syntax is incorrect probably – Manashvi Birla Feb 27 '16 at 13:02
  • That I did consiously to see whether I get data in var $id or not and it show only sdfds in log file. – Shashank Kumrawat Feb 27 '16 at 13:04
  • I want to iterate loop only one time and only for that product that has been added not for all product that have been added before. – Shashank Kumrawat Feb 27 '16 at 14:59
4

This event is written as follow:

Mage::dispatchEvent(‘sales_quote_product_add_after’, array(‘items’ => $items));

Means, we can grab items as follow: $observer->getEvent()->getItems(). And this will be an array of items.

public function updateQuote($observer)
{
    Mage::log("testing", null, 'quote-log.log');
    $items = $observer->getEvent()->getItems();

    foreach($items as $item){
      Mage::log($item->getId()."hello testing", null, 'quote-log.log');

    }
}

Now check file called quote-log.log in your var/log folder.

I haven't tested, but should work.

  • hello Adarsh, I did not get print $item->getId(), only prints hello testing – Shashank Kumrawat Feb 27 '16 at 14:42
  • check my update answer – Adarsh Khatri Feb 27 '16 at 14:47
  • No it did not worked as I need. It prints 2 times for a single product and item id is also null. – Shashank Kumrawat Feb 27 '16 at 14:57
  • do u want to get product id? – Adarsh Khatri Feb 27 '16 at 14:59
  • No, I need item Id from table quote_item – Shashank Kumrawat Feb 27 '16 at 15:00
1

Try $quoteItem = $observer->getEvent()->getItems() instead of $quoteItem = $observer->getEvent()->getQuoteItem();

  • @nimesh..it Did not worked – Shashank Kumrawat Feb 27 '16 at 13:22
  • check function is call by writing echo exit in function – Nimesh Patel Feb 27 '16 at 13:25
  • If function not call then provide config.xml all code – Nimesh Patel Feb 27 '16 at 13:27
  • This event trigger from "<root>\app\code\core\Mage\Sales\Model\Quote.php" function is "addProductAdvanced" line no 1025 – Nimesh Patel Feb 27 '16 at 13:29
  • check my updated question. – Shashank Kumrawat Feb 27 '16 at 14:11

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.