Magento:添加“假”产品到购物车/报价
我了解如何以编程方式创建产品并将其添加到购物车。我知道这可能听起来很愚蠢,但是否可以即时生成产品并将其添加到购物车/报价中,但实际上从未将其保存在数据库中。
我们想要创建一个定制界面,我想最后它可以添加一个包含所有选择的捆绑产品,但该捆绑产品实际上不会存在于后端。
我想只要你能确保报价和订单具有产品所需的内容就可以了,但显然可能有很多与在特定 sku 或 ID 上的数据库中查找内容相关的内容。我知道,如果您删除一个产品,然后在管理员中查看导致问题的订单,至少对于我正在处理的这个场景来说是这样的。
我正在考虑创建一个巨大的捆绑产品,其中包含 6 个不同的捆绑商品,每个商品可能有 500 种产品,然后根据用户的选择,以编程方式将捆绑商品添加到购物车。但后来我不确定拥有这样一个巨大的捆绑产品是否也会产生负面影响。
更新: 我认为这不会起作用,显然数据库中有很多与产品相关的信息,我们设置了一个测试,然后我们立即收到 $item->getProduct() 的错误。我们正在推进创建一个巨大的捆绑产品以及动态添加自定义选项的通用产品,安达在下面指出了这一点。任何其他建议将不胜感激。
I understand how to programmatically create a product and also add to cart. I know this might sound dumb but is it is possible to generate a product on the fly and add that to the cart/quote but never actually save it in the database.
We want to create a made to order interface and I was thinking at the end it could add a bundle product with all the selections but that bundle product wouldn't actually exist in the backend.
I figured as long as you can make sure the quote and order has what it needs in terms of the product it would be ok, but obviously there is probably a lot that is tied to looking up stuff in the db on a specific sku or ID. I know that if you delete a product and then look at an order in the admin that causes issues, at least it did for this one scenario I was dealing with.
I was thinking of creating a giant bundle product that had like 6 different bundle items and each item could potentially have like 500 products and then based on what the user selects I programmatically add the bundle to cart. But then I wasn't sure if there would be a negative affect with having a gigantic bundle product like that as well.
UPDATE:
I don't think this will work, obviously there are a lot of information tied to the product in the database and we setup a test and right away we get an error for $item->getProduct(). We are moving forward with creating a giant bundle product and also the generic product with adding custom options on the fly, which Anda pointed out below. Any other suggestions will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定 Clockworkgeek 的方法是否有效。在每次页面加载时,Magento 都会从购物车加载商品,以确保它们仍然有效(有货、价格正确等),并修改购物车以反映这些值。我过去对系统的理解是,购物车中的产品需要有相应的数据库值才能在这个过程中生存。
“巨型捆绑产品”方法很痛苦,但在过去一直是我发现的最好方法。尝试更改产品的值(例如价格或属性)将被购物车检查覆盖,因此您需要具有最大灵活性的产品,例如过度定制的捆绑产品或可配置产品。
希望有帮助!
谢谢,
乔
I'm not sure that clockworkgeek's approach is going to work. On every page load, Magento loads the items from the cart to make sure that they are still valid (in-stock, prices correct, etc), and amends the cart to reflect those values. My understanding of the system in the past has been that a product in the cart needs to have a corresponding database value to survive this process.
The "giant bundle product" approach is a pain, but in the past has been the best approach I have found. Attempting to change the values of the product (such as price or attributes) will be overridden by the cart checks, so you need a product w/ maximal flexibility, such as an overly-customized bundle product or configurable product.
Hope that helps!
Thanks,
Joe
为什么不在数据库中创建通用产品,然后根据用户选择将产品自定义设置为自定义选项(additional_options)。您可以将自定义选项添加到产品(实际上是报价项目),而无需将它们保存在数据库中。我曾经为一个销售处方眼镜的网站做过一次。处方被添加为一个选项。
Why not create a generic product in db and then set the product customization as custom options (additional_options) on the fly depending on the user selection. You can add custom options to the product (actually to the quote item) without having to save them in the database. I did this once for a website that sells glasses with prescription. The prescription was added as an option.
您可以通过编程方式创建
Mage_Sales_Model_Quote_Item
并将其添加到购物车。您已经注意到它需要一种产品来匹配它的产品 ID,但它不一定是有用的产品。它可能是一个空白的、禁用的产品,也是用代码创建的。所需要的只是一个存根。购物车所需的物品存储在报价项目中 - 名称、价值和数量等字段。然后,这些字段将直接复制到订单中,而无需使用产品。
You can programmatically create
Mage_Sales_Model_Quote_Item
s and add them to the cart. You've noticed it needs a product to match it's product ID but it needn't be a useful one. It could be a blank, disabled product, also created in code. All that's needed is a stub.The necessary stuff for the cart is stored in the quote item - fields like name, value and quantity. Those fields are then copied directly to the order without using a product.
创建一个新产品。您可以通过执行以下操作将其添加到购物车:
您可以在数据库中以catalog_product_...开头的表中找到产品属性,或者获取已创建的产品,并查看它在_data数组中具有哪些属性(使用调试器或只是 print_r($product->getData))
creates a new product. you can add it to a cart, by doing something like this:
product attributes you can find in the DB in tables that start like catalog_product_... or take an already created product, and see what attributes it has in the _data array (with debugger or just print_r($product->getData))