如何从外部站点将产品添加到OpenCart?

编程入门 行业动态 更新时间:2024-10-28 08:25:27
本文介绍了如何从外部站点将产品添加到OpenCart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要从网站到ocart的产品添加到购物车中.我正在尝试以下代码.用户单击提交按钮后,我得到的只是购物车为空".

I need to add a product to the shopping cart from a website to ocart. I was trying the following code. All I get is "shopping cart empty" after the user clicks the submit button.

我确保产品ID = 40确实存在. thansk寻求任何帮助

I made sure that the product id = 40 does exist. thansk for any help

<form action="***/purchase/index.php?route=checkout/cart" id="personalVirtualPrivateServerForm" method="post"> <input type="hidden" name="product_id" value="40"> <input type="hidden" name="quantity" value="2"> <input type="submit" alt="Order Now" title=" value="Order Now"> </form>

推荐答案

表单操作应为

***/purchase/index.php?route=checkout/cart/add mind this particular action being called -^^^^

但是我认为这将不起作用,因为称为ControllerCheckoutCart::add()的方法应该与返回JSON响应的AJAX请求一起使用.因此,如果您向该URL提交表单而不显示购物车,它将仅显示JSON响应.

However I think this won't work as the method called ControllerCheckoutCart::add() is expected to work with AJAX request returning the JSON response. So if You submit a form to this URL instead of shopping cart being displayed it will display only the JSON response.

而不是直接提交表单,您应该确保在单击提交"按钮后,该表单是由jQuery AJAX提交的.然后,您可以在成功后将用户重定向到购物车.这是可能的解决方案,请确保填写真实域.未经测试.将此脚本放在存在表单的页面上(假设jQuery已链接到该站点):

Instead of direct submitting the form You should make sure it is submitted by jQuery AJAX after the submit button was clicked. Then You can redirect the user to the shopping cart on success. Here is possible solution, make sure to fill in the real domain. It is not tested. Place this script on the page where the form is present (supposes jQuery is linked to the site):

$(document).ready(function() { $('form#personalVirtualPrivateServerForm input[type="submit"]').click(function(e) { e.preventDefault(); // prevent the form from submitting $.ajax({ type: 'POST', dataType: 'json', url: '.../index.php?route=checkout/cart/add' data: 'product_id=' + $('form#personalVirtualPrivateServerForm input[name="product_id"]').val() + '&quantity=' + $('form#personalVirtualPrivateServerForm input[name="quantity"]').val(), success: function(json) { window.location = '.../index.php?route=checkout/cart'; } }); }); });

更多推荐

如何从外部站点将产品添加到OpenCart?

本文发布于:2023-10-30 21:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544124.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:站点   产品   OpenCart

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!