1

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

如果已经存在一个我可以用来学习的模块,请给我指出它的方向。或者也许有一个指南漂浮在某个地方?

谢谢!

4

2 回答 2

2

我想到了。显然,如果您正在创建一个也是 ubercart 产品类的内容类型,您不能简单地按照我上面链接的教程然后“附加” ubercart 的东西。根据上面的教程,你需要实现以下钩子来从你的模块中创建一个内容类型:

  • 钩子信息()
  • hook_perm()
  • 钩子访问()
  • 钩子形式()
  • 钩子帮助()

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

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

    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();
    }
    

如您所见,该代码段向 uc_product_classes 表添加了一个条目,我想这就是 ubercart 所需要的。

最后,我还在我的模块中进一步实现了一个特定于 ubercart 的钩子:hook_product_types()

我只是在进行过程中弄清楚这一点,所以我很高兴收到更正或建议。

于 2010-07-12T13:26:58.720 回答
1

我只是想明白这一点,这似乎工作正常,不幸的是 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.' ) );

}
于 2011-01-19T05:45:59.993 回答