下面是这种情况:
我使用的是AJAX添加到购物车extention产品添加到购物车无需刷新页面。
我已经修改了list.phtml文件有一定的数量递增函数,它增加了一个“+”和“ - ”加号和减号按钮输入。 (来源: http://jigowatt.co.uk/blog/magento-quantity-increments-jquery-edition/ )。
问题2个不同的看法解释说:
1 /如果我通过点击+按钮输入增加数量,数量正确改变,因为我看到价值在输入框中改变,但后来我点击添加到购物车按钮,而且也只有1产品加入。 不管有多少次我点击+按钮来获得我想要的数量,增加数量,车始终为1。
第二/如果我在数量框中键入所需量数手动,5例如,没问题:购物车被刷新与5个项目。
所以基本上只对增量键+点击时,不添加物品的数量,只有一个被添加。
下面是它增加了增值功能,并增加了+和代码 - 按钮:
jQuery("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
jQuery(".plus").click(function()
{
var currentVal = parseInt(jQuery(this).prev(".qty").val());
if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;
jQuery(this).prev(".qty").val(currentVal + 1);
});
jQuery(".minus").click(function()
{
var currentVal = parseInt(jQuery(this).next(".qty").val());
if (currentVal == "NaN") currentVal = 0;
if (currentVal > 0)
{
jQuery(this).next(".qty").val(currentVal - 1);
}
});
现在,有AJAX添加到与list.phtml数量输入框车按钮的工作,一些修改不得不作出(来源: http://forum.aheadworks.com/viewtopic.php?f=33&t=601 )
必须更换原来的代码是:
<!-- Find this block of code: -->
<?php if($_product->isSaleable()): ?>
<button type="button" class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
它必须与下面这段代码来替代,如上面贴的论坛链接解释说:
<!-- And replace it with this block of code: -->
<?php if($_product->isSaleable()): ?>
<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="button" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"><span><span>Add to Cart</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="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></span>
<?php else: ?>
我不知道为什么手动键入值时加入购物车的数量是唯一正确的。 我需要使用正(+)时,也添加到购物车正确的数量或 - (减号)按钮。 出于某种原因,数量在输入框中的变化,但这个值是不是一个在车后添加到购物车点击(总是1个产品加入购物车)。
是什么原因造成这个问题? 而这将是解决这个问题的解决? 我很想了解和解决这个问题,因为我一直在这整个下午的努力。 非常感谢。