如何设置我的捆绑产品中的选项数量?
我有这段代码,它会将 ID 为 171 的捆绑产品添加到购物车,并提供颜色 (23) 洋红色 (63) 的产品选项。有什么方法可以设置选项的数量,比如我们想将数量设置为 2 个具有该颜色的项目?
感谢您的帮助。
$params = array(
'product' => 171,
'bundle_option' => array(
23 => array(
0 => 63
),
),
'qty' => 1,
);
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product');
$product->load(171);
$cart->addProduct($product, $params);
$cart->save();
I have this code, which would add one bundle product with the ID of 171 to the cart, given the option of a product with the color(23) Magenta(63). Is there any way to set a quantity to the option, like say we want to set the quantity to 2 of those items with that color?
Thanks for the help.
$params = array(
'product' => 171,
'bundle_option' => array(
23 => array(
0 => 63
),
),
'qty' => 1,
);
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product');
$product->load(171);
$cart->addProduct($product, $params);
$cart->save();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过拦截对 addtocart 的请求并查看该捆绑包的正常帖子数组是什么样子?这应该会给你你需要的结构。
Have you tried intercepting the request to addtocart and seeing what a normal post array for that bundle would look like? That should give you the structure that you need.