1

How to add extra product while creating order from admin only. Let's say I added "test1" product from admin, so "test2" product will be added automatically to that order.

I have created Observer for that.

1 Answer 1

4

For your sales_quote_item_set_product event try this:

public function addProduct(Varien_Event_Observer $observer)
{
    $product = $observer->getProduct();
    if ($product->getSku() == 'test1') {
        $added = false;
        $quote = $observer->getQuoteItem();
        foreach ($quote->getQuote()->getAllVisibleItems() as $item) {
            if ($item->getProduct()->getSku() == 'test1') {
                $added = true;
                break;
            }
        }

        if (!$added) {
            $addProduct = Mage::getModel('catalog/product');
            $addProduct->load($addProduct->getIdBySku('test2'));
            $quote->getQuote()->addProduct($addProduct);
        }
    }
}

If this should be for admin only make sure sales_quote_item_set_product is not set globally - it should be placed here:

<adminhteml>
    <events>
        <sales_quote_item_set_product>
            ...
7
  • but there is an issue if we are removing that test1 product its adding one more time ? Commented Jun 20, 2017 at 9:02
  • Mhhh? Can't reproduce ... I can remove "test1" w/o any problems? Maybe another observer?
    – sv3n
    Commented Jun 20, 2017 at 9:44
  • after product add to order click on apply coupon button on that button click also that test2 products qty is increasing on every click its changing qty & price Commented Jun 20, 2017 at 9:56
  • Please try updated code.
    – sv3n
    Commented Jun 20, 2017 at 10:37
  • After add product to order first remove test2 product individually & then remove test 1 product individually you will see on remove test 2 product is adding there Commented Jun 20, 2017 at 10:48

Your Answer

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

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