why checkout_cart_update_items_before after update custom price show in every currency same price?

magento.stackexchange https://magento.stackexchange.com/questions/321454

  •  14-04-2021
  •  | 
  •  

Question

 public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $items = $observer->getCart()->getQuote()->getItems();
        $info = $observer->getInfo()->getData();        
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');     
        foreach ($items as $item) { 
            //$price = $item->getProduct()->getFinalPrice();    
            $price = $priceHelper->currency($item->getProduct()->getFinalPrice(), false, false);            
            $gross_price = $priceHelper->currency($item->getProduct()->getPrice(), false, false);
            //$gross_price = $item->getProduct()->getPrice();
            if($price != $gross_price){
                $qty = $info[$item->getId()]['qty'];
                if($info[$item->getId()]['qty'] >= 10){
                     $price = (floor($gross_price*.95) + (($price- $gross_price) * .95));
                } elseif($info[$item->getId()]['qty'] >= 5){
                     $price = (floor($gross_price*.97) + (($price- $gross_price) * .97));
                }
                
                //$gross_price = $priceHelper->currency($gross_price, false, false);
                //$price = $priceHelper->currency($price, false, false);                
                $item->setCustomPrice($price);
                $item->setOriginalCustomPrice($price);
                $item->getProduct()->setIsSuperMode(true);
                $item->save();
            }
        }
    }

after currency change show the same price

enter image description here

enter image description here

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top