如何在Magento中更新订单商品自定义选项?

时间:2012-07-27 12:19:28

标签: magento

是否可以从订单更新产品自定义选项值? 我知道物品在购物车中(结账前)是可能的,但我不确定订单是否可行。

我们的应用程序正在销售服务,我们有一个案例,只有在结账后才能获得所需的数据。

1 个答案:

答案 0 :(得分:0)

您可以在订购之前在addProduct函数上执行此操作。

    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());
    }