/** * @param $class * @return mixed */ public function mc_get_obj($class) { return \Magento\Framework\App\ObjectManager::getInstance()->get($class); } /** * TODO UPDATE * @return bool|mixed */ public function update() { $customerId = $this->customerId; //fixme redirect login if (!$customerId) { //Todo @return not login $this->_die(‘not login‘, [], ‘/customer/account/login‘); } //fixme get request $req = $this->setReq()->req; $o = $this->_o; $data = $req[$o]; /** * @var $quoteItem \Magento\Quote\Model\Quote\item */ $quoteItem = $this->mc_get_obj(‘Magento\Quote\Model\Quote\item‘); //req item id $item_id = $req[$o][‘item_id‘]; //GET Quote id $item = $quoteItem->load($item_id); //GET Quote id $quoteId = $item->getQuoteId(); try { /** * @var $quote \Magento\Quote\Model\Quote */ $quote = $this->mc_get_obj(\Magento\Quote\Model\Quote::class)->load($quoteId); $item = $quote->getItemById($item_id); if (!$item) { var_dump(‘Item is empty !‘); die; } $item->setSizeId($data[‘size_id‘]); $item->setSizeType($data[‘size_type‘]); $result = $item->save()->toArray(); $this->_die(‘Success !‘, [ ‘size_id‘=>$result[‘size_id‘], ‘size_type‘=>$result[‘size_type‘], ], ‘‘, 1); } catch (\Exception $e) { $this->_die($e->getMessage()); } }
原文地址:https://www.cnblogs.com/q1104460935/p/10847588.html
时间: 2024-11-01 11:56:39