在 Magento 中向属性选项添加新值
我正在尝试使用脚本向 Magento 中的属性选项添加新值以加快该过程,因为我有 2,000 多个制造商。
I am trying to add new values to an attribute option in Magento using a script to speed up the process since I have over 2,000 manufacturers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是我用来执行此任务的一段代码。创建一个自定义模块(使用 ModuleCreator 作为工具),然后创建一个
mysql4 -install-0.1.0.php
在 sql/modulename_setup 文件夹下。它应该包含以下内容(当然,适应您自己的数据!)。如果需要,请参阅 Magento wiki 的更多文档。
如果您不想在自定义模块中执行此操作,您可以创建一个以以下内容开头的 php 文件:
Here is a piece of code that I used to perform exactly this task. Create a custom module (using ModuleCreator as a tool) and then create a
mysql4-install-0.1.0.php
under the sql/modulename_setup folder. It should contain the following (adapted to your own data, of course!).More documentation on the Magento wiki if you want.
If you don't want to do it in a custom module, you could just create a php file that starts with:
乔纳森的回答是正确的。但是,如果您想在没有安装程序的情况下执行它,即在任何其他代码中,那么您可能会发现这很有帮助:
可以找到更多信息此处。
Answer of Jonathan is correct. But if you want to perform it without installer i.e in any other code, then you might find this helpful:
More information can be found here.
我创建了一个函数来动态向属性添加选项
您可以通过提供代码和选项值向属性添加选项
I have created a function to dynamically add option to attribute
You can add an option to your attribute by providing code and option value
重要!(希望这对某人有帮助,因为我在这个问题上被困了 2 个小时)
如果您使用特殊字符(例如 ä、ö、ü、ß、×、...),请确保对它们进行正确编码!
Important! (Hopefully this helps somebody, cause I was stuck like 2h with this issue)
If you are using special characters (such as ä, ö, ü, ß, ×, ...) make sure to encode them properly!
这是一个简单且非常快速的方法...
删除选项
添加或更新选项
Here a simple and very fast way....
Delete an option
Add or update an option
Arvind Bhardwaj 的回答在此处输入代码是正确的。但是,如果您想在没有安装程序的情况下执行它,即在任何其他代码中,那么您可能会发现这很有帮助:
同意 Arvind 但它仅适用于插入单个选项值,如果您想执行插入多个选项值,那么您只需要替换“$option['value'][$key.''.$manufacturer] = $manufacturer;”中的代码到“$option['values'][$key.''.$manufacturer] = $manufacturer;”对此。
下面是最终的代码
,我希望它适用于插入多个选项。
Answer of Arvind Bhardwaj enter code here is correct. But if you want to perform it without installer i.e in any other code, then you might find this helpful:
Agree with Arvind but it's only works for insert the single option value and if you want to perform insert multiple option value then you just needs to replace the code from "$option['value'][$key.''.$manufacturer] = $manufacturer;" to "$option['values'][$key.''.$manufacturer] = $manufacturer;" to this.
below is the final code
I hope its works for insertion multiple option.
如果你想为不同的商店添加新值,你可以尝试这个
If you want to add new values for differ store, you cat try this