如何在模块内创建 ubercart 产品内容类型

发布于 2024-09-09 00:48:06 字数 201 浏览 1 评论 0原文

我想从模块内创建产品内容类型。我按照这个非常有用的指南以编程方式创建内容类型。现在我该如何“产品化”它?

如果已经存在一个可以执行此操作的模块可供我学习,请为我指出它的方向。或者也许某个地方有一个指南在漂浮?

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故乡的云 2024-09-16 00:48:06

我想通了。显然,如果您要创建的内容类型也是 ubercart 产品类别,则不能简单地按照我上面链接的教程进行操作,然后“添加”ubercart 内容。根据上面的教程,您需要实现以下挂钩以从模块内创建内容类型:

  • hook_info()
  • hook_perm()
  • hook_access()
  • hook_form()
  • hook_help()

要创建也是产品类的内容类型,您需要对上面的列表进行以下修改:

  • 删除 hook_info()。不确定为什么这会导致问题,但确实如此。
  • 照常使用 hook_perm()、hook_access()、hook_form() 和 hook_help()。
  • 使用 hook_enable() (当模块启用时触发),并包含以下代码:

    函数 uc_yourmodule_enable() {
      db_query("INSERT INTO {uc_product_classes} (pcid、名称、描述) 
                值('%s'、'%s'、'%s')", 
                '产品类别 ID', 
                '产品类别名称', 
                “产品类别描述。”);
    
      节点类型重建();
    }
    

如您所见,该代码段向 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:

  • hook_info()
  • hook_perm()
  • hook_access()
  • hook_form()
  • hook_help()

To create a content type that is also a product class, you need to make the following modifications to the above list:

  • Remove hook_info(). Not sure why this causes a problem, but it does.
  • Use hook_perm(), hook_access(), hook_form() and hook_help() as usual.
  • Use hook_enable() (which fires when the module is enabled), and include the following code:

    function uc_yourmodule_enable() {
      db_query("INSERT INTO {uc_product_classes} (pcid, name, description) 
                VALUES ('%s', '%s', '%s')", 
                'product_class_id', 
                'Product Class Name', 
                'Product Class Description.');
    
      node_types_rebuild();
    }
    

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.

弄潮 2024-09-16 00:48:06

我只是想明白这一点,这似乎工作正常,不幸的是 api 不以官方方式支持这一点。

    function create_uc_product_type ( $name , $pcid , $description )
     {

     $pcid = preg_replace ( array ( '/\s+/' , '/\W/' ) , array ( '_' , '' ) , strtolower ( $pcid ) );


    db_query ( "INSERT INTO {uc_product_classes} (pcid, name, description) VALUES ('%s', '%s', '%s')" , $pcid , $name , $description );
    uc_product_node_info ( TRUE );
    variable_set ( 'node_options_' . $pcid , variable_get ( 'node_options_product' , array ( 'status' , 'promote' ) ) );

    if ( module_exists ( 'comment' ) ) {
        variable_set ( 'comment_' . $pcid , variable_get ( 'comment_product' , COMMENT_NODE_READ_WRITE ) );
    }

    module_invoke_all ( 'product_class' , $pcid , 'insert' );

    if ( module_exists ( 'imagefield' ) ) {
        uc_product_add_default_image_field ( $pcid );
    }



    $type = node_get_types('type', $pcid);
    $type->custom = 1;

    node_type_save($type);

    node_types_rebuild ( );
    menu_rebuild ( );

    drupal_set_message ( t ( 'Product class ' . $pcid . ' created.' ) );

}

I was just figuring this out, this seems to work ok, its unfortunate the api doesnt support this in a official way.

    function create_uc_product_type ( $name , $pcid , $description )
     {

     $pcid = preg_replace ( array ( '/\s+/' , '/\W/' ) , array ( '_' , '' ) , strtolower ( $pcid ) );


    db_query ( "INSERT INTO {uc_product_classes} (pcid, name, description) VALUES ('%s', '%s', '%s')" , $pcid , $name , $description );
    uc_product_node_info ( TRUE );
    variable_set ( 'node_options_' . $pcid , variable_get ( 'node_options_product' , array ( 'status' , 'promote' ) ) );

    if ( module_exists ( 'comment' ) ) {
        variable_set ( 'comment_' . $pcid , variable_get ( 'comment_product' , COMMENT_NODE_READ_WRITE ) );
    }

    module_invoke_all ( 'product_class' , $pcid , 'insert' );

    if ( module_exists ( 'imagefield' ) ) {
        uc_product_add_default_image_field ( $pcid );
    }



    $type = node_get_types('type', $pcid);
    $type->custom = 1;

    node_type_save($type);

    node_types_rebuild ( );
    menu_rebuild ( );

    drupal_set_message ( t ( 'Product class ' . $pcid . ' created.' ) );

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文