[英]How can i add two product in cart onlclick add to cart buton?
I want to add two product in cart when i click the add to cart button. 单击添加到购物车按钮时,我想在购物车中添加两个产品。
I have modified the code of 'Add to cart' button. 我已经修改了“添加到购物车”按钮的代码。 But it is adding only one product in cart.
但是它只在购物车中添加一种产品。
<button type="button"
title="<?php echo $this->__('Add to Cart') ?>"
class="button btn-cart"
onclick="setLocation(
'<?php echo (string)Mage::helper('checkout/cart')->getAddUrl(
Mage::getModel('catalog/product')->load($Id1,$Id2))?>'
)">
<span><span>
<?php echo $this->__('Add to Cart') ?>
</span></span>
</button>
Only Id1 product is added in the cart.But i want id1 and id2 product both. 购物车中仅添加了ID1产品。但是我想同时使用ID1和ID2产品。
the function load() has two parameters: id and field. 函数load()有两个参数:id和field。
Mage::getModel('catalog/product')->load($Id1,$Id2)
this is not correct, because the second parameters is not interpreted as an ID. 这是不正确的,因为第二个参数未解释为ID。
You probably should make an observer on the 'checkout_cart_add_product_complete' event, but for answering your question you can simply modify your code to get it works: 您可能应该使“ checkout_cart_add_product_complete”事件成为观察者,但是要回答您的问题,您只需修改代码即可使其生效:
declare your _ids and the _addToCart urls: 声明您的_id和_addToCart网址:
<?php
$id1 = your_1st_id;
$id2 = ypur_2nd_id;
$_addCart1 = (string)Mage::helper('checkout/cart')
->getAddUrl(Mage::getModel('catalog/product')
->load($id1));
$_addCart2 = (string)Mage::helper('checkout/cart')
->getAddUrl(Mage::getModel('catalog/product')
->load($id2));
?>
declare the button, you will need a js function to pop-out two links with one click: 声明按钮,您将需要一个js函数来一键弹出两个链接:
<button type="button"
title="<?php echo $this->__('Add to Cart') ?>"
class="button btn-cart"
onclick="pageloader();">
<span><span><?php echo $this->__('Add to Cart') ?></span></span>
</button>
and the js function can be like this: js函数可以像这样:
<script>
function pageloader()
{
window.open("<?php echo $_addCart1; ?>", "_blank");
window.open("<?php echo $_addCart2; ?>", '_blank');
}
</script>
all this code can be placed in a template.phtml file, but this in my opinion is not the correct way for doing what you are asking for. 所有这些代码都可以放置在template.phtml文件中,但是我认为这不是完成所要求的正确方法。 I recommend to create an Observer and elaborate your data there.
我建议创建一个观察者,并在那里详细说明您的数据。 Hope to solve your problems.
希望能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.