I m trying to remove the group of item from the cart and adding another group of product to the cart. My error is, price is displaying only for first item not other items in cart page after doing the replace in cart..
Friends pls help me out..In new to magento
Below is my code
use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\RequestInterface; use Magento\Catalog\Model\ProductFactory; use Magento\Customer\Model\Url; class UpdatePost extends Action { protected $cart; protected $product; protected $_customerSession; protected $_catalogProduct; protected $checkout_session; public function __construct( Context $context, ProductFactory $catalogProduct, \Magento\Customer\Model\Session $customerSession, \Magento\Catalog\Model\Product $product, \Magento\Checkout\Model\Cart $cart, \Magento\Checkout\Model\Session $checkout_session ) { $this->_customerSession = $customerSession; $this->_catalogProduct = $catalogProduct; $this->cart = $cart; $this->product = $product; $this->checkout_session = $checkout_session; parent::__construct($context); } public function execute() { $params = $attr = array(); $productInfo = array(); $params = $this->getRequest()->getParams(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); if(isset($params['item_id']) && count($params['item_id']) > 0){ /* remove item cart starts */ for ($i=0; $i cart->removeItem($item_id)->save(); $quoteItem = $this->getItemModel()->load($item_id); $quoteItem->delete(); /* remove the exiting product from cart ends*/ } /* remove item cart ends */ for ($i=0; $i $opt_val) { $attr['options'][$opt_key] = $opt_val; } } } /* add current product to cart starts*/ $_product = $this->_catalogProduct->create()->load($product_id); if ($_product) { $this->cart->addProduct($_product, $attr); $this->cart->save(); } /* add current product to cart ends*/ } $this->messageManager->addSuccess(__('Cart Updated successfully.')); }else{ $this->messageManager->addError(__('Invalid Item. Please select item in cart!')); } return $this->goBack($this->_redirect->getRefererUrl()); }