Magento动态属性/选项保存到购物车 [英] Magento dynamic attribute/option save to cart

查看:50
本文介绍了Magento动态属性/选项保存到购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将产品添加到购物车时,我需要向购物车项目动态添加选项选择.呈现给购物者的选择可能因产品而异,因此有必要使其具有动态性.但是,选项将始终相同.例如,选项1"对于一个产品可能具有值"a,b,c",而对于另一种产品可能具有"x,y,z"值.我不需要将选项保存到产品中,仅需要购物车即可.选择的内容需要显示在购物车以及订单管理,收据等中.

I need to dynamically add option choices to the cart items at the time a product is added to the cart. The choices presented to the shopper can change from product to product, so it is necessary that they are dynamic. However, the options will always be the same. For example "Option 1" might have values "a, b, c" for one product and "x, y, z" for another product. I do not need the options saved into the product, only the cart. The selections need to be displayed in the cart and in the order administration, receipt, etc.

我从此答案中学到了我可以使用$cart->addProduct($product, $params)来为购物车项目设置自定义选项.

I learned from this answer that I can use $cart->addProduct($product, $params) in order to set custom options to the cart item.

我发现我可以在此博客文章.我能够将产品动态添加到购物车中.但是,我对如何向产品添加动态属性值感到困惑.在调用$cart->addProduct($product, $params)之前,我尝试在$params中设置'options'和'super_attribute',但它没有将值保存到购物车项目中.

I found that I can override the Cart controller at this blog post. I was able to dynamically add the product to the cart. However, I am stuck on how to add dynamic attribute values to the product. I tried setting 'options' and 'super_attribute' in $params before calling $cart->addProduct($product, $params) but it's not saving the values to the cart item.

最后,某些选项的选择将需要影响产品价格.我也不知道该怎么解决.

Finally, some of the option choices would need to affect the product price. I am not sure how to account for this either.

在此先感谢您的帮助!

推荐答案

过去,我结合使用文本字段和下拉选项(用于影响价格的选项)以及自定义javascript和隐藏字段来解决此问题问题.请看下面的示例,当您更改不同的橱柜宽度时,总尺寸和价格将被更新.此信息也将添加到购物车/管理员订单中

In the past I have use a combination of text field and drop-down option (for options which affect price) along with custom javascript and hidden field to solve this issue. Take a look at the example below, as you change the different cabinet width the total dimension and price will be updated. This information will also be add to cart/admin order

参见示例@ 假设您使用的是简单产品.

Assuming that you are using simple product.

要添加其他选项,请参见 要更改产品价格,请参见 查看全文

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