doutu1889 2014-10-21 17:05
浏览 42
已采纳

在Opencart 1.5.6.4中将批量折扣选项添加到购物车

Just wondering if there is a way that I can add discounts to the shopping cart in Opencart.

Basically im wanting customers to be able to select an option, i,e size, then add bulk amounts to the shopping cart. This would then add say 1000 of this item directly to the shopping cart. Im trying to get something like this:

Buy 1000 or more for only £5.00 per unit [Add to cart]

Buy 2000 or more for only £4.50 per unit [Add to cart]

Here is my code so far, unfortunatly Im not sure how to get this working correctly so any help would be great.

Thanks!

<?php if ($discounts) { ?>
<br />
<div class="discount">
  <?php foreach ($discounts as $discount) { ?>
  <div class="discount-item">
  <h3>Buy <?php echo $discount['quantity']; ?> or more for only <?php echo $discount['price']; ?></h3>
  <a onClick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><?php echo $button_cart; ?></a>
  </div>
  <?php } ?>
</div>
<?php } ?>
  • 写回答

1条回答 默认 最新

  • douli0531 2014-10-21 17:14
    关注

    It's unclear exactly what you're asking for. But if it's any help, the addToCart method that comes with the default template accepts an optional second field, which is the quantity. So you could do:

    <a onClick="addToCart('<?php echo $product['product_id']; ?>', <?php echo $discount['quantity']; ?>);" class="button"><?php echo $button_cart; ?></a>

    Edit for items with options:

    I'll assume you're on the product page, as you need to select the options somehow... now we could clone the whole function that submits the data to the cart. But I think this is easier to manage:

    First, change the link to look like this:

    <a class="buy-bulk" data-quantity="<?php echo $discount['quantity']; ?>" class="button"><?php echo $button_cart; ?></a>

    Then add the following near the bottom:

    <script type="text/javascript">
        $(document).ready(function() {
            $('.buy-bulk').on('click', function() {
                var quantity = $(this).data('quantity');
                // change the quantity
                $('input[name="quantity"]').val(quantity);
                // simulate a click on the "add to cart button"
                $('#button-cart').trigger('click');
            })
        });
    </script>
    

    NOTE: untested! :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)