0

I have Observer Written for admin order i want to remove one product item from my admin cart list i have added 3-4 products i have my product name : test i want to remove that test

i have added 2 products in my order cart from that 2 products i want to remove 1 product i will create one coupon code once admin apply that coupon then test1 product should remove from order item list i have not placed the order i just added to order item list

<sales_quote_item_set_product>
    <observers>
        <namespace_removeproduct_order_observer>
            <type>singleton</type>
            <class>additionalproduct/observer</class>
            <method>removeProduct</method>
        </namespace_removeproduct_order_observer>
    </observers>
</sales_quote_item_set_product> 

observer.php

public function removeProduct($observer)
{
}
  • Hello, your question is not clear at all. You want to remove a product from the cart or from an existing order? – Rajeev K Tomy Jun 22 '17 at 6:40
  • @ranjeev : yes s – magento12345 Jun 22 '17 at 7:19
  • @ranjeev : i updated my question – magento12345 Jun 22 '17 at 7:25
1

Change event to salesrule_validator_process (and flush cache).

If coupon code your_coupon_code is applied the product with SKU test1 is removed from your order:

public function removeProduct(Varien_Event_Observer $observer)
{
    if ($observer->getRule()->getCouponCode() == 'your_coupon_code') {
        $quote = $observer->getQuote();
        foreach ($quote->getAllVisibleItems() as $item) {
            if ($item->getProduct()->getSku() == 'test1') {
                $quote->deleteItem($item);
                break;
            }
        }
    }
}
  • its not working i have added 2 products in my order cart from that 2 products i want to remove 1 product i will create one coupon code once admin apply that coupon then test1 product should remove from order item list i have not placed the order i just added to order item list – magento12345 Jun 22 '17 at 7:24
  • Updated answer. – sv3n Jun 22 '17 at 7:58
  • Fatal error: Call to a member function getCouponCode() on null in – magento12345 Jun 22 '17 at 8:53
  • Have you changed event to salesrule_validator_process and flushed cache? Code is tested. – sv3n Jun 22 '17 at 9:01
  • yes its working now but there is one issue we are not able to track that applied coupon in order why ? – magento12345 Jun 22 '17 at 9:18

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.