Magento API:将预先存在的简单产品分配给可配置产品
我有一个包含大量库存商品的客户数据库,这些商品作为简单产品上传到 Magento。
现在我需要将它们分组并将它们分配给可配置产品,其尺寸和颜色是其可配置属性。
Magento API 有一个 Product_Link 类,具有一个看起来很有前途的方法:catalogue-product-link.assign (link),但我一生都无法弄清楚我需要哪些参数才能使其与可配置产品一起工作,前提是分配就是这样用过的。
I've got a client database with a large range of stock items, which are being uploaded to Magento as simple products.
Now I need to group them up and assign them to configurable products with their size and colour being their configurable attributes.
The Magento API has a Product_Link class, with a promising looking method: catalogue-product-link.assign (link), but I can't for the life of me figure out what arguments I need to make it work with configurable products, providing this is how assign was meant to be used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我这是一个未经教育的猜测,但我认为现有的 API 无法完成您的要求。 您必须自己编写或直接访问数据库。
I this is an un-educated guess, but I think what your asking for can't be done with the existing API. You will have to write your own or just got directly to the DB.
这是我直接使用 PHP 完成此操作的 hack-y 方法。 共有三个相关表。 我使用颜色和大小作为我的属性。
我的父产品(可配置)实际上并不存在于我的目录中。 它们本质上是型号级别,然后产品是 SKU 级别。
所以 LIKE 'parentproductsku%' 适合孩子们。
Here is the hack-y way that I did this straight with PHP. There are three related tables. I was using color and size as my attributes.
My parent products (configurable) don't actually exist in my catalog. They are essentially model level and then the products are the SKU level.
So LIKE 'parentproductsku%' works out for the children.
令人惊讶的是,如果所有简单产品的价格相同,这会起作用:
Surprisingly, this works, if all your simple products share the same price:
@aeno 的解决方案对我来说不起作用,所以我对其进行了一些改进。 已使用通过
Mage::getModel( 'catalog/product' )->load()
方法实例化的产品对此进行了测试。@aeno's solution did not work for me, so I refined it a bit. This has been tested using a product instantiated via the
Mage::getModel( 'catalog/product' )->load()
method.好吧,这里的注释帮助我运行了这个。 因此,我想与您分享将简单产品添加到现有可配置产品的代码。
此代码假设简单的产品是可以添加的有效产品,我不确定如果不是的话会发生什么。
Well the notes here helped me get this running. So I thought I'd share with you the code to add a simple product to an existing Configurable Product.
This code assumes the simple product is a valid one to add, I'm not sure what would happen if it wasn't.
Scimon 接受的答案中的代码在最新版本的 magento 中不再起作用(至少在 1.7 中)。 但幸运的是,您只需要一个小修复即可使其再次工作:
The code from the accepted answer by Scimon does not work anymore in recent versions of magento (at least in 1.7). But fortunately, you need just a small fix to get it working again:
我现在正在努力做这件事。
到目前为止,我发现这些项目作为参考很有帮助:
我会发布我的到目前为止的代码,希望在它工作后更新它。
好吧,这使用“item_size”作为区分“简单”产品的属性。 此外,这还假设“可配置”父 SKU 是子 SKU 的根。 例如,ABC001 是父级,而 ABC001-SMALL 和 ABC001-LARGE 是简单子级。
希望对某人有帮助。
I'm working on doing this right now.
So far I've found these items helpful as references:
I'll post my code so far, and hopefully update it once it works..
Okay, this uses 'item_size' as the attribute that differentiates the "simple" products. Also, this assumes that the "configurable" parent SKU is the root of the child SKU. For example, ABC001 is the parent while ABC001-SMALL and ABC001-LARGE are the simple children.
Hope that helps someone.