【问题标题】:Magento product view page quantity box always adds 1 to the cart issueMagento 产品查看页面数量框总是将 1 添加到购物车问题
【发布时间】:2014-04-11 12:03:40
【问题描述】:

我正在开发一个 magento 商店,在产品视图页面/详细信息页面中,我添加了一个 jquery 数量框。它工作正常。但是当点击添加到购物车按钮时,总是将“1”添加到购物车中,尽管我更改了数量框中的数量。我在每个可能的站点中都搜索了这个问题。但仍然没有运气。我已将输入数量框放在正确的位置。这意味着在表格内。我无法弄清楚问题。希望有帮助。我的 Magento 版本是 1.8。

【问题讨论】:

  • 终于可以自己解决这个问题了。我将此问题标记为已解决。
  • 请发表您的答案并接受。这样每个人都可以解决问题。

标签: magento-1.8


【解决方案1】:

这适用于表单标签...您可以像这样编辑您的 default/theme/template/catalog/product/view/addtocart.phtml。

<form>
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label class="qty_label" for="qty"><?php echo $this->__('Quantity') ?>:</label>
<div class="qty_pan">
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
</form>

【讨论】:

    【解决方案2】:

    从 Magento 1.8 版开始,您需要在 form 中添加 formkey 值。

    如果formkey 未在表单中设置,则始终将默认数量 1 添加到购物车。

    另外,如果您尝试从购物车页面更新数量,它将不会被更新,并且将始终设置为 1。

    要解决此问题,请在&lt;form &gt; 标签内添加以下代码:

    <?php echo $this->getBlockHtml('formkey'); ?>
    

    这段代码类似于:

    <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
    

    产品查看页面

    app/design/frontend/YOUR_PACKAGE/YOUR_THEME/catalog/product/view.phtml

    <form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
        <?php echo $this->getBlockHtml('formkey'); ?>
    

    购物车页面

    app/design/frontend/YOUR_PACKAGE/YOUR_THEME/checkout/cart.phtml

    <form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
        <?php echo $this->getBlockHtml('formkey'); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 2017-05-18
      • 1970-01-01
      相关资源
      最近更新 更多