我有捆绑产品,其中3个复选框被选中为默认值。我想从页面分类列表(list.phtml
)添加一个捆绑产品,而无需指定选项。我怎样才能做到这一点?将捆绑产品添加到购物车而无需指定选项
回答
我的项目只需显示捆绑产品的单行,购买捆绑产品时隐藏选项默认选择和购买。该产品可以从类别视图中购买。
捆绑配置:
- 捆绑与动态价格
- 的选项配置要求,默认值和单选按钮默认选择的值
我走进我的自定义类别视图模板和添加以下内容:
<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>
上述创建如果我们有一个包,并且默认所有选项,那么它就是一个附加到购物车的表单,它将检索捆绑子产品。 工程就像一个魅力!
这一张已张贴了一段时间后,但想让你知道这是非常有用的谢谢! – 2012-04-02 14:44:54
同意!谢谢! – 2012-09-06 17:28:13
这不适合我。 Magento 1.7.0.0。当我以这种方式购买捆绑产品时,按钮仅将四个可用选项中的一个选项相关联。似乎工作,但如果你看看订单和股票的选择只有一个已经改变。 – 2012-12-01 20:20:45
好吧,我终于按照我认为应该的方式工作。
Wgenie把我放在正确的方向。
我用这个代码,而不是Wgenie的的,它不仅增加了项目到购物车,但控制束选择股票,并显示不可用,如果一个选项是缺货:
<?php if ($_item->getTypeId() == 'bundle') : ?>
<form action="<?php echo Mage::helper('checkout/cart')->getAddUrl($_item); ?>" method="post" id="product_addtocart_form_<?php echo $_item->getId()?>">
<?php $selectionCollection = $_item->getTypeInstance(true)->getSelectionsCollection(
$_item->getTypeInstance(true)->getOptionsIds($_item), $_item
); ?>
<?php $saleable = true; ?>
<?php foreach($selectionCollection as $option) : ?>
<input type="hidden" name="bundle_option[<?php echo $option->option_id; ?>][]" value="<?php echo $option->selection_id; ?>" />
<input type="hidden" name="bundle_option_qty[<?php echo $option->option_id; ?>][]" value="1" />
<?php
//Stock control for each bundle option
$opt_product = Mage::getModel('catalog/product')->load($option->product_id);
$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
->loadByProduct($opt_product)->getQty();
if($stocklevel<=0)
$saleable = false;
?>
<?php endforeach; ?>
<?php if($saleable): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button" onclick="this.form.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</form><?php else : ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><?php endif; ?>
Btw,Magento 1.7.0.0 – 2012-12-01 21:42:29
是的,这个解决方案更好。 – 2013-10-03 14:54:47
我在Magento 1.7网站上做类似的事情。我可以从产品列表中将捆绑产品添加到购物车,而无需重定向到产品页面。
/app/design/frontend/your_package/your_theme/template/catalog/product/list.phtml
的
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
更换OCCURENCES与
<?php
$productAddUrl = $this->helper('checkout/cart')->getAddUrl($_product);
if ($_product->getTypeId() == 'bundle'):
$bundleOptions = '?';
$selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection($_product->getTypeInstance(true)->getOptionsIds($_product), $_product);
foreach($selectionCollection as $option):
$bundleOptions .= '&bundle_option[' . $option->option_id . ']=' . $option->selection_id;
$bundleOptions .= '&bundle_option_qty[' . $option->option_id . ']=1';
endforeach;
$productAddUrl .= $bundleOptions;
endif;
?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $productAddUrl ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
Joras的解决方案有效,但它可以创造e报价中的多个项目,每个项目都包含相同的捆绑包(具有相同的选项)。原因在于,当将新添加的捆绑包与报价项目进行比较时,Magento(在1.9.2.2上测试)创建了一个由
[product_id] _ [option_id_1] _ [option_qty _] _ [option_id_2] _组成的bundel_identity字符串[option_qty_2] ...
该字符串取决于提交参数的顺序。要遵循在产品设置中指定的顺序使用:
$typeInstance = $product->getTypeInstance(true)
->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $typeInstance->getOptionsCollection($product);
foreach ($optionCollection as $option) {
// build your query string here....
}
而且这是一个相当hacky¡做到这一点的模板中。更好的选择imo
override Mage_Catalog_Block_Product_List::getAddToCartUrl($product, $additional = array())
- 1. 将产品添加到购物车WooCommerce?
- 2. WordPress的购物车添加动态产品到购物车
- 3. 产品未添加到购物车
- 4. 添加产品到购物车Rails
- 5. Magento:Nick-naming产品添加到购物车
- 6. 添加产品选项价格到购物车页面 - Opencart?
- 7. 添加选项价值产品,然后到Magento购物车
- 8. 将产品描述添加到Woocommerce的购物车项目
- 9. magento:无法将产品添加到购物车 - 主钥匙
- 10. 无法将产品添加到购物车virtmart
- 11. 在购物车中将产品添加到自定义评论
- 12. 如何将产品添加到购物车中而无需刷新产品列表?
- 13. 将商品添加到购物车
- 14. Jquery添加购物车产品 - ideasoft
- 15. 添加产品ID到购物车产品分类
- 16. Virtuemart 2 - 产品图像添加到“添加到购物车” -popup
- 17. 添加项目到不同产品类型的购物车
- 18. 双单价为捆绑产品的购物车更新后
- 19. Magento - 将产品添加到购物车时将其他选项添加到订单项
- 20. 是否可以将可配置产品添加到购物车,而无需任何选择?
- 21. 添加到购物车显示“您的购物车中没有产品”?
- 22. Woocomerce变量产品添加到购物车,当点击选择选项
- 23. Magento将可配置产品添加到购物车
- 24. 如何将隐藏的产品添加到magento购物车?
- 25. 将多余的产品添加到购物车(观察员)
- 26. 跟踪客户在Magento中将产品添加到购物车
- 27. 将产品尺寸添加到购物车
- 28. 如何通过钩子将产品添加到购物车woocomerce?
- 29. 将产品添加到购物车后出现403错误
- 30. Magento:将产品添加到购物车后减少库存
你有没有这个运气?我真的需要能够做到这一点,并据我所知,这是一个Magento错误.. – 2011-06-10 09:11:57