3

Steps to reproduce:

1.Please configure tax settings and tax rules as seen in screenshots.

2.Now login in storefront using Demo Customer Access provided by Magento 
  (roni_cost@example.com).

3.Please integrate the below code to apply custom price.

Observer :

namespace Vendor\MyModule\Observer;

use Magento\Framework\Event\ObserverInterface;

class BindPriceToCart implements ObserverInterface
{

public function execute(\Magento\Framework\Event\Observer $observer)
{   
        $price = 100;
        $event = $observer->getEvent();
        $item = $event->getQuoteItem();
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        return $this;
}    

}

Event : checkout_cart_product_add_after

Configurations that needs to be set :

enter image description here enter image description here enter image description here enter image description here

Expected Result : enter image description here

Actual Result : enter image description here

  • did you try using another event? Or maybe a plugin. You could try the event sales_quote_item_set_product. I'm not saying it will work. I just wondering if using checkout_cart_product_add_after is not too late in the process to change the price. – Marius Jun 26 at 14:47
  • @Marius: I have tried "sales_quote_item_set_product" event but still facing the problem. – Sanjay Chaudhary Jun 27 at 5:28
  • If the custom_price and original_custom_price is set as NULL, once the product is added in cart, then calculation is seen fine on cart. May be magento team should empty the custom_price once the product is added in cart but not sure if it might have impact in other areas or not.. – Sanjay Chaudhary Jun 27 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.