如何在模块内创建 ubercart 产品内容类型
我想从模块内创建产品内容类型。我按照这个非常有用的指南以编程方式创建内容类型。现在我该如何“产品化”它?
如果已经存在一个可以执行此操作的模块可供我学习,请为我指出它的方向。或者也许某个地方有一个指南在漂浮?
谢谢!
I'd like to create a product content type from within a module. I followed this very helpful guide to programmatically create a content type. Now how do I "productize" it?
If there already exists a module that does this that I can use to learn from, please do point me in it's direction. Or perhaps there is a guide floating around somewhere?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。显然,如果您要创建的内容类型也是 ubercart 产品类别,则不能简单地按照我上面链接的教程进行操作,然后“添加”ubercart 内容。根据上面的教程,您需要实现以下挂钩以从模块内创建内容类型:
要创建也是产品类的内容类型,您需要对上面的列表进行以下修改:
使用 hook_enable() (当模块启用时触发),并包含以下代码:
如您所见,该代码段向 uc_product_classes 表添加了一个条目,我想这就是 ubercart 所需要的。
最后,我还在我的模块中进一步实现了 ubercart 特定的钩子: hook_product_types( )
我只是在进行过程中弄清楚这一点,所以我很高兴收到更正或建议。
I figured it out. Apparently, if you're creating a content type that is also an ubercart product class, you cannot simply follow the tutorial that I linked to above and then "tack on" ubercart stuff. According to the tutorial above, you need to implement the following hooks to create a content type from within your module:
To create a content type that is also a product class, you need to make the following modifications to the above list:
Use hook_enable() (which fires when the module is enabled), and include the following code:
As you can see, the snippet adds an entry to the uc_product_classes table, and I guess that's all ubercart needs.
Finally, I've also implemented an ubercart-specific hook further down in my module: hook_product_types()
I'm just figuring this out as I go along, so I'm happy to receive corrections or suggestions.
我只是想明白这一点,这似乎工作正常,不幸的是 api 不以官方方式支持这一点。
I was just figuring this out, this seems to work ok, its unfortunate the api doesnt support this in a official way.