1

我正在使用 Opencart 2.0,我正在尝试让数量字段从类别页面和产品页面中工作。我之前在 1.5 版中设法做到了这一点,但此后代码发生了很大变化。对于 Opencart V 1.5,我使用了 Siven Sadiyan 提供的解决方案(http://siven76.com/2013/04/29/opencart-add-a-quantity-box-on-product-list-pages/) 谁的解决方案效果很好,只需要对 common.js 和 category.tpl 进行调整,我也能够将其应用于各种其他页面,例如搜索结果和模块。由于代码和条款发生了变化,我至今无法修改它以适应 Opencart 版本 2.0+。我已经尝试了几个扩展,但目前似乎没有什么可行的解决方案,除了硬编码和手动,到目前为止它对我来说并不顺利!我所寻找的只是功能,我不担心布局。

自从解决之前版本的 Opencart 以来,common.js 文件发生了变化,我知道它涉及以下代码(ps,从下面的代码中删除了滚动到顶部,但仅与原始代码更改了一行):

 // Cart add remove functions
 var cart = {
     'add': function(product_id, quantity) {
         jQuery.ajax({
             url: 'index.php?option=com_mijoshop&route=checkout/cart/add&format=raw&tmpl=component',
             type: 'post',
             data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
             dataType: 'json',
             beforeSend: function() {
                 jQuery('#cart > button').button('loading');
             },
             success: function(json) {
                 jQuery('.alert, .text-danger').remove();

                jQuery('#cart > button').button('reset');

                if (json['redirect']) {
                    location = json['redirect'];
                }

                if (json['success']) {
                    jQuery('#content_oc').parent().before('<div class="shopnotification"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button      type="button" class="close" data-dismiss="alert">&times;</button></div>');

                    jQuery('#cart-total,#cart > a > span').html(json['total']);

                    jQuery('.shopnotification').fadeIn(1000).delay(3000).fadeOut(1500);

                    jQuery('#cart > ul,#module_cart > ul').load('index.php?option=com_mijoshop&route=common/cart/info&format=raw&tmpl=component ul li');
                }
             }
         });
     },

第二个文件是 category.tpl 代码(我假设成功更改后可以在其他区域进行更改):

 <div class="button-group">
     <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
     <button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>
     <button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button>
 </div>

任何对此有解决方案的人将不胜感激!如果我自己运气好的话,我会回帖,但是在长时间的头抓伤之后,我的咖啡量很低!

4

1 回答 1

2

感谢 Opencart 论坛上的 Xyph3r,您的旧帖子重新版本 1.5 为我提供了一个非常适合 Opencart 版本 2 的替代方案的线索!链接到我的线索: http: //forum.opencart.com/viewtopic.php ?f=20&t=99990 对于其他人,这就是我所做的,它可以适应 vqmod 或 ocmod 所以更新不会覆盖这个但这里是基础知识: Category.tpl: 查找行:

 <div class="button-group">
     <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

将其更改为:

 <input type="text" value="1" size="2" class="item-<?php echo $product['product_id']; ?>" />
 <div class="button-group">
     <button type="button" value="<?php echo $button_cart; ?>" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

在文件底部,在 echo 页脚之前添加以下行,使文件末尾如下所示:

 <script type="text/javascript"><!--
 function addQtyToCart(product_id) {
     var qty = $('.item-' + product_id).val();
     if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
         qty = 1;
     }
     cart.add(product_id, qty);
 }
 //--></script> 
 <?php echo $footer; ?>

希望这对其他人有帮助。请注意,这只将数量字段放在现有按钮上方添加到购物车、愿望清单和比较,它看起来并不漂亮,所以这完全取决于您和您的风格(主题)!

于 2015-02-21T08:09:11.067 回答