Magento - 添加到购物车的数量字段Upsell产品
问题描述:
我试图让我的Upsell产品,我使用而不是相关的产品上的view.phtml,与数量字段前面的工作添加到购物车按钮。我也使用AheadWorks Ajax AddToCart Pro 2.5扩展。Magento - 添加到购物车的数量字段Upsell产品
眼下,我'加入产品无数量字段在这个片段:
<form action="<?php echo $this->getAddToCartUrl($_link) ?>" method="post" id="view_addtocart_form_<?php echo $_link->getId(); ?>"><button onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')" class="greenbutton" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button></form>
这个伟大的工程,但我不能在数量变化,由于缺乏量场。然后,我尝试使用这个从我list.phtml的正常工作,在分类视图:
<script type="text/javascript">
function setQty(id, url) {
var qty = document.getElementById('qty_' + id).value;
document.getElementById('cart_button_' + id).innerHTML = '<button type="button" class="greenbutton-small" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Læg i kurv</span></span></button>';
}
</script>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_product->getId(); ?>" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_product->getId(); ?>, '<?php echo $this->getAddToCartUrl($_product) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_product->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
现在,有趣的是,如果我尝试在upsell.phtml使用它,这并不工作,但我无法弄清楚为什么?这可以在类别视图的AW中使用Ajax Cart Pro完美实现。
答
在upsell.phtml
产品对象被称为$_link
每下面的代码:
<?php if($_link=$this->getIterableItem()): ?>
如果你想在您的upsell.phtml
你的代码,那么你就必须改变$_product
到$_link
这样的:
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty_<?php echo $_link->getId(); ?>" id="qty_<?php echo $_link->getId(); ?>" maxlength="12" value="1" onkeyup="setQty(<?php echo $_link->getId(); ?>, '<?php echo $this->getAddToCartUrl($_link) ?>');" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<span id="cart_button_<?php echo $_link->getId(); ?>">
<button type="button" class="greenbutton-small" onclick="setLocation('<?php echo $this->getAddToCartUrl($_link) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
应该在以下行的后面去:
<?php if($_link=$this->getIterableItem()): ?>
你值得拥抱..从某人热! ;) 呵呵。这真的拯救了我的一天。非常感谢,这么一件小事,甚至都没有想过。非常感谢你。 – 2013-03-26 18:30:47