Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 如何在模块内创建ubercart产品内容类型_Drupal_Drupal 6_Ubercart - Fatal编程技术网

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

Drupal 如何在模块内创建ubercart产品内容类型,drupal,drupal-6,ubercart,Drupal,Drupal 6,Ubercart,我想从模块中创建产品内容类型。我遵循非常有用的指南以编程方式创建内容类型。现在我如何“生产”它 如果已经存在这样一个模块,我可以用来学习,请告诉我它的方向。或者某个地方有个向导在游荡 谢谢 我明白了。显然,如果您创建的内容类型也是ubercart产品类,那么您不能简单地遵循我上面链接的教程,然后“附加”ubercart内容。根据上面的教程,您需要实现以下挂钩,以便从模块中创建内容类型: hook_info() hook_perm() hook_access() hook_form() hook

我想从模块中创建产品内容类型。我遵循非常有用的指南以编程方式创建内容类型。现在我如何“生产”它

如果已经存在这样一个模块,我可以用来学习,请告诉我它的方向。或者某个地方有个向导在游荡


谢谢

我明白了。显然,如果您创建的内容类型也是ubercart产品类,那么您不能简单地遵循我上面链接的教程,然后“附加”ubercart内容。根据上面的教程,您需要实现以下挂钩,以便从模块中创建内容类型:

  • hook_info()
  • hook_perm()
  • hook_access()
  • hook_form()
  • hook_help()
要创建同时也是产品类的内容类型,需要对上面的列表进行以下修改:

  • 拆下挂钩信息()。不确定这为什么会导致问题,但确实如此
  • 像往常一样使用hook\u perm()、hook\u access()、hook\u form()和hook\u 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特定的钩子:


我只是在继续的过程中弄明白了这一点,所以我很高兴收到更正或建议。

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

}