cancel
Showing results for 
Search instead for 
Did you mean: 

Chaneg price of item added to cart and update the total after login

Chaneg price of item added to cart and update the total after login

I have integrated functionality if customer belong to wholesale group then price will be 50%.

Now issue is when customer come to site and add to cart without login product will be added with actual price.  On checkout page when customer will login and if customer is from wholegroup then price should go 50% but as he added product with actual price cart and product  price doesn't update.

 

I want to if wholesale customer logged in then decrease 50% price of the item added to cart.

Theoretically, i know i need to load the quote and update the product price but practically i need help how can i start in M2?

3 REPLIES

Re: Chaneg price of item added to cart and update the total after login

Hi @jacktorris,

Please let us know how you did the customization. Is there any event you are using to trigger the observer? may be changing that event properly may help you. Anyway please share more details about your code level implementation.

Re: Chaneg price of item added to cart and update the total after login

I found solution myself to update the price of the item added to cart.

 

Using Object Manager:

 

            $cart = $objectManager->get('\Magento\Checkout\Model\Cart');
           $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
          $items = $cart->getQuote()->getAllItems();
               if($items){
                foreach ($items as $item){
                   // $this->logger->info(print_r($item->getProductId(),true));
                    // echo $item->getPrice()."<br/>";
                    $subprice = $item->getPrice();

                    $subprice = $priceHelper->currency($subprice, false, false);
                    //$price = (100/121) * $subprice;

                    $finalprice = round($subprice,2);
                    // echo $finalprice."<br/>";
                    $item->setCustomPrice($finalprice);
                    $item->setOriginalCustomPrice($finalprice);
                    $item->getProduct()->setIsSuperMode(true);
                   // echo "FinF";
                }
            }

Re: Chaneg price of item added to cart and update the total after login

Thanks for your answer. It works perfectly. Appricate your help