简体   繁体   English

更新数量框产品列表magento

[英]Update Quantity box product list magento

How do i get it to work so its updates with AJAX, it does on view.phtml? 我如何使其工作,以便它在AJAX上进行更新,并且在view.phtml上进行? It now reloads the whole page. 现在,它将重新加载整个页面。

I have added a quantity box to my product list. 我已经在我的产品列表中添加了一个数量框。 this is what i added on list.phtml: 这是我在list.phtml上添加的内容:

<form action="<?php echo $this->getAddToCartUrl($_product) ?>” method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>> 
    <?php if(!$_product->isGrouped()): ?> 
        <label for="qty"><?php echo $this->__('Qty') ?>:</label> 
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>” /> 
    <?php endif; ?> 

    <button type="button" class="button btn-cart” onclick="this.form.submit()">
        <span>    
            <span><?php echo $this->__('Add to Cart') ?></span>
        </span>
    </button> 
</form>

Here are my files: 这是我的文件:

list.phtml -> http://pastebin.com/UJ0YvUq9 view.phtml -> http://pastebin.com/7pQtYvfe list.phtml-> http://pastebin.com/UJ0YvUq9 view.phtml-> http://pastebin.com/7pQtYvfe

Hope that the community can help me! 希望社会各界帮助我!

You will be Genius. 您将成为天才。

The best approach for this is using jQuery ajax. 最好的方法是使用jQuery ajax。 Ofcourse your code is reloading the page since the form is submitted, that's what you're programming :) 当然,由于提交了表单,您的代码正在重新加载页面,这就是您正在编程的内容:)

Since the view.phtml has a whole other structure and actions binded to update the cart and updating the QTY we must add some things to the list template and write some jQuery. 由于view.phtml具有绑定的其他结构和操作来更新购物车和更新数量,因此我们必须在列表模板中添加一些内容并编写一些jQuery。

Write the jQuery ajax (post! that's important) call to the add to cart url and append the current product data, It's the best do this on $('button').click() and doing an event.preventDefault() to prevent the page reloading. 编写对添加到购物车网址的jQuery ajax(重要!)调用,并附加当前的产品数据,最好在$('button').click()执行一个event.preventDefault()来防止页面重新加载。 Retrieve errors, or success notices and display the updated QTY at the product, also be aware to update the mini-cart (if displayed) in the header or other place on your website. 检索错误或成功通知并在产品上显示更新的数量,还应注意更新网站顶部或其他位置的微型购物车(如果显示)。

After posting with the QTY and other required product options, the product is being added to the cart. 使用数量和其他必需的产品选项过帐后,该产品将被添加到购物车中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM