Howto update order item's custom option in Magento?

前端 未结 2 1497
Happy的楠姐
Happy的楠姐 2020-12-29 15:59

Is it possible to update a product custom option value from an order? I know it is possible when items are in cart (before checkout), but I\'m not sure if it is possible in

2条回答
  •  清酒与你
    2020-12-29 16:34

    You can do it on addProduct function, before to order.

        try {
            $cart = Mage::getModel('checkout/cart');
            $previousItemCount = $cart->getQuote()->getItemsCount();
    
            if ($previousItemCount <= 0) {
                $cart->init();
            }
    
            $params = $this->getRequest()->getParams();
            $product = Mage::getModel('catalog/product')->load($params['product_id']);
    
            $date = explode('/', $params['product_dtinvoice']);
            $date = array(
                'month' => $date[0],
                'day' => $date[1],
                'year' => $date[2],
            );
    
            $cart->addProduct(
                $product,
                new Varien_Object(array(
                    'product' => $product->getId(),
                    'qty' => 1,
                    'options' => array(
                        '4' => array(
                            'month' => $date['month'],
                            'day' => $date['day'],
                            'year' => $date['year']
                        ),
                        '2' => $params['product_ean'],
                        '3' => $params['product_serialnumber'],
                        '1' => $params['product_seller'],
                    ),
                ))
            );
    
            $cart->save();
    
            if ($previousItemCount < $cart->getQuote()->getItemsCount()) {
                $return = array('result' => true, 'msg' => '');
            } else {
                $return = array('result' => false, 'msg' => 'Did not possible to add this product to cart. Please contact the administrator');
            }
    
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($return));
        } catch(Exception $e) {
            Mage::throwException($e->getMessage());
        }
    

提交回复
热议问题