将捆绑产品添加到购物车,而无需指定选项 [英] Add bundle product to cart without having to specify the options

查看:97
本文介绍了将捆绑产品添加到购物车,而无需指定选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有捆绑产品,其中默认选中了3个复选框.我想从页面类别列表(list.phtml)添加捆绑产品,而不必指定选项.我该怎么办?

I have bundle products with 3 checkboxes checked as default. I want to add a bundle product from the page category list (list.phtml) without having to specify the options. How can I do this?

推荐答案

我的项目仅需要显示捆绑产品的一行,购买捆绑时默认选择并购买了隐藏选项.从类别视图可以购买该产品.

My project needed to only show a single line for a bundle product, hidden options default selected and purchased when buying the bundle. The product had be buyable from the category view.

捆绑配置:

  • 具有动态价格的捆绑包
  • 将选项配置为必需,默认值和单选按钮为默认选定值

我进入了自定义类别视图模板,并添加了以下内容:

I went into my custom category view template and added the following:

<form action="<?php echo Mage::$this->helper('checkout/cart')->getAddUrl($product); ?>" method="post" id="product_addtocart_form_<?php echo $product->getId()?>">
<?php

// If we have a bundle:
if ($_product->getTypeId() == 'bundle'){

    $selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection(
           $_product->getTypeInstance(true)->getOptionsIds($_product), $_product
        );

    foreach($selectionCollection as $option) {

        echo '<input type="hidden" name="bundle_option[' . $option->option_id  . ']" value="' .  $option->selection_id . '" />';
        echo '<input type="hidden" name="bundle_option_qty[' . $option->option_id . ']" value="1" />';

    }//end: foreach $selectionCollection

} // end: if $_product == bundle 
?>
<input type="text" name="qty" class="qty" maxlength="4" value="1" />
<button type="button" onclick="this.form.submit()" />
</form>

上面创建了一个购物车表格,如果我们有捆绑商品,则检索捆绑商品的子产品,并默认所有选项. 就像魅力一样!

The above creates a add-to-cart-form, retrieves the bundle sub-products if we have a bundle and defaults all the options. Works like a charm!

这篇关于将捆绑产品添加到购物车,而无需指定选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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