Magento.如何使用自定义选项以编程方式在购物车中添加简单产品 [英] Magento. How to add simple product in cart programmatically with custom options

查看:77
本文介绍了Magento.如何使用自定义选项以编程方式在购物车中添加简单产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在购物车中添加带有自定义选项的简单产品.

I am trying to add my simple product with custom options in cart.

    $post = $this->getRequest()->getPost();
    $_product = Mage::getModel('catalog/product')->load(8);
    $QuoteId= Mage::getModel('checkout/cart_api')->create('default');
    $storeId = Mage::app()->getStore()->getId();
    $arrProducts = array(
        array(
            "product_id" => 8,
            "qty" => 1,
            "options" => array(
                '1' => array(
                    'sku' => 'cheese'
                )
            )
        )
    );
    $cart = Mage::getSingleton('checkout/cart');
    $cart->addProduct($_product, $arrProducts);
    $cart->save();
    Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

但不幸的是,产品没有添加到购物车中. 我有错误

but unfortunately product dont adding in cart. i have got error

"请指定产品所需的选项"

我做错了什么?我有两种产品选择.选项1 ID为1,SKU奶酪...

what i am doing wrong ? I have two options for product. option 1 id is 1 and sku cheese ...

推荐答案

我认为您的数组太多了:

I think you've got a array too much:

$arrProducts = array(
    array(
        "product_id" => 8,
        "qty" => 1,
        "options" => array(
            'option_id' => 'option_value'
        )
    )
);

应该做这项工作.

这篇关于Magento.如何使用自定义选项以编程方式在购物车中添加简单产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆