Magento - 通过查询字符串将产品添加到购物车
我知道可以通过 Magento 中的查询字符串添加产品。
模式:
/path/to/app/checkout/cart/add?product=[id]&qty=[qty]
如果我有一个必需的自定义选项:
/path/to/magento/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
如果自定义选项是例如“field”或“drop_down”,那就很简单;
我的问题是:如果自定义选项之一是文件类型,如何通过查询字符串添加产品?
我想添加一个文件作为自定义选项值,该文件已使用 AJAX 上传到服务器上(在将产品添加到购物车之前)。
能做到吗?又如何呢?
感谢您提供任何解决方案。
I'm aware that a product can be added via querystring in Magento.
Pattern:
/path/to/app/checkout/cart/add?product=[id]&qty=[qty]
And if I have a required custom options:
/path/to/magento/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
If custom option is for example "field" or "drop_down", it's simple;
My querstion is: How to add a product via querystring if one of custom option is a file type?
I would like to add a file, as custom option value, that is already uploaded on server with AJAX (before product is added to cart).
Can it be done? And how?
Thank you for any solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件必须使用 POST 请求上传,而不是 GET(查询字符串)。如果不修改控制器,您就无法以这种方式使用内置的添加到购物车 url,这不是一个好主意。相反,您可以制作自己的“添加到购物车”控制器,并从核心操作中复制代码,然后调整它以接受查询字符串中的文件名。
但是,我有一种感觉,您只是想将产品添加到购物车而不加载新页面。你想实现什么目标?
Files must be uploaded with POST requests, not GET (query string). You cannot use the built in add to cart url in that way without modifying the controller, which is not a good idea. Instead maybe make your own add to cart controller and copy the code from the core action and adjust it to accept filenames in the query string.
However, I have a feeling you are just trying to add products to cart without loading a new page. What are you trying to accomplish?
您的自定义选项应该是文件名(或文件的其他唯一引用),而不是文件本身。任何需要操作该文件的代码都可以使用该文件名来获取实际文件,因为它已经在您的服务器上。
Your custom option should be a filename (or some other unique reference to the file), not the file itself. Any code that needs to operate on the file can then use the filename to get to the actual file since it is already on your server.