Magento2 updated quote_item table - 更新quote_item 表自定义字段

复制代码
    /**
     * @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());
        }
    }
复制代码

 

posted @   徐锅  阅读(367)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2018-05-11 服务铝料门窗基本资料
2018-05-11 微信小游戏发布注意事项

点击右上角即可分享
微信分享提示