I want to apply a custom price for the current order. I read that I should use sales_quote_add_item, But its looks like I am doing something wrong. I found some tutorials for magento1 but not for Magento 2. So please let me know what I am doing wrong.


    <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_quote_add_item">
        <observer name="change_hello_magento_display" instance="Myvendor\Addtocart\Observer\Change" />


namespace Myvendor\Addtocart\Observer;

class Change implements \Magento\Framework\Event\ObserverInterface
    public function execute(\Magento\Framework\Event\Observer $observer)
        $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        $new_price = 987;

Let me know please what I am doing wrong. I want to achieve the same thing for Magento 2 given on below link for magento1.


  • hi @rahul whether u would like to add in frontend? Jul 4, 2017 at 4:07
  • whether you would like to change the price after add to cart please confirm thanks Jul 4, 2017 at 4:09
  • hi @rahul i have used checkout_cart_product_add_after event please try and get back with your comments thanks Jul 4, 2017 at 4:30

2 Answers 2


Please follow the below steps:

Step-1: Create an events.xml in the following below path

Note: Here i am considering the module called Ewall_Pricecalculations


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_cart_product_add_after">
<observer name="Ewall_Pricecalculations_Addtocart" instance="Ewall\Pricecalculations\Observer\PricecalculationsAfterAddtoCart" />

Step-2: Next Create a file in the name of PricecalculationsAfterAddtoCart.php keep the below code as shown below.

namespace Ewall\Pricecalculations\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
class PricecalculationsAfterAddtoCart implements ObserverInterface
public function execute(\Magento\Framework\Event\Observer $observer) 
            $writer = new \Zend\Log\Writer\Stream(BP.'/var/log/stackexchange.log');
            $logger = new \Zend\Log\Logger();
            /* Code here */
            $quote_item = $observer->getEvent()->getQuoteItem();
            $price = 400; //set your price here

            $logger->info("success !!!!");

Step 3: please use php bin/magento setup:di:compile

clear cache and page_cache and check the same in the frontend.

  • 1
    checkout_cart_product_add_after this event is not working in case of admin order. Is there any other event to handle this scenario? Jun 19, 2018 at 9:01
  • @RanjitShinde the above event is working at front end after add to cart. Jun 19, 2018 at 11:02
  • @NagarajuKasa, can we set custom taxamount for the quote item using this event? May 15, 2019 at 6:05
  • i am note sure @jafarpinjar i will check and getback to you. May 15, 2019 at 6:21
  • @NagarajuKasa, okay thank you, here is my question, you can update if found anything please,magento.stackexchange.com/questions/274520/… May 15, 2019 at 6:23

Old question, and posted answer is valid for sure

Just wanted to point that the mentioned event (sales_quote_add_item) in question is available in Magento2, and it works fine for the asked customization with very few code

public function execute(\Magento\Framework\Event\Observer $observer)
    // your logic to get $yourPrice
    $quoteItem = $observer->getEvent()->getQuoteItem();

Note that you shouldn't save() QuoteItem object

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.