打开购物车版本2,在类别视图中提交的数量 [英] Open Cart version 2, Quantity filed on Category View

查看:89
本文介绍了打开购物车版本2,在类别视图中提交的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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+版.我已经尝试了几种扩展,但是目前除了硬编码和手动编码外,几乎没有其他可行的解决方案,到目前为止,对我来说效果不佳!我要寻找的只是功能,我不担心布局.

I am working with Opencart 2.0 and I am trying to get the quantity field to work from the category page as well as the product pages. I managed to do this fine previously with version 1.5 but the code has changed a lot since. With Opencart V 1.5 I used the solution provided by Siven Sadiyan (http://siven76.com/2013/04/29/opencart-add-a-quantity-box-on-product-list-pages/) who's solution worked beautifully, and just required a tweak to common.js and category.tpl and I was able to apply this to various other pages too such as search results and modules. I have been unable so far to modify this to suit Opencart version 2.0+ as the code and terms have changed. I have tried several extensions but there seems to be little working solutions at the moment except for hard coding it and manually, and so far it is not going well for me! All I am looking for is functionality and I am not worried about the layout.

自从对Opencart先前版本的解决方案以来,common.js文件已更改,并且我知道它涉及以下代码(以下代码从ps滚动到顶部,但是原始代码仅一行更改):

The common.js file has changed since the solution to the previous version of Opencart and I know it involves the following code (ps, scroll to top is removed from the below code but only one line has changed from the original):

 // 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代码(我认为成功更改后可以在其他区域进行更改):

The second file is category.tpl code (which I presume when successfully changed can be altered in other areas):

 <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>

任何对此有解决方案的人,将不胜感激!如果我自己有运气,我会发回邮件,但长时间挠头后我的咖啡不足!

Anyone with a solution for this it would be appreciated! I will post back if I get any luck myself but I'm low on coffee after a long head scratch!

推荐答案

感谢您在Opencart论坛上使用Xyph3r,您的旧版本1.5重新发布了一些线索,为我提供了一个适用于Opencart版本2的替代方法的线索!链接到我的线索: http://forum.opencart.com/viewtopic. php?f = 20& t = 99990 对于其他人,这是我所做的,并且可以将其改编为vqmod或ocmod,因此更新不会覆盖此内容,但这是基础知识: Category.tpl: 找到这一行:

Thank you Xyph3r on Opencart forums, your old post re version 1.5 gave me clues to an alternative that works great for Opencart version 2! Link to my clues: http://forum.opencart.com/viewtopic.php?f=20&t=99990 For others, this is what I did, and it can be adapted into a vqmod or ocmod so updates don't overwrite this but here are the basics: Category.tpl: Find the line:

 <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>

在文件底部,在回显页脚之前添加以下几行,以便文件末尾如下所示:

At the bottom of the file, add the following lines before the echo footer so the end of the file looks like this:

 <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; ?>

希望这对其他人有帮助.请注意,这只会将数量字段放在现有按钮的上方,添加到购物车,愿望清单和比较中,它看起来不会很漂亮,所以一切都取决于您和您的样式(主题)!

Hope this helps others. Note this only puts the quantity field above the existing buttons add to cart, wish list and compare, it won't look pretty so that's all down to you and your style (theme)!

这篇关于打开购物车版本2,在类别视图中提交的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆