モジュール内から製品コンテンツ タイプを作成したいと考えています。この非常に役立つガイドに従って、コンテンツ タイプをプログラムで作成しました。では、どうすればそれを「製品化」できますか?
学習に使用できるモジュールが既に存在する場合は、その方向を教えてください。それとも、どこかにガイドが浮かんでいるのでしょうか?
ありがとう!
私はそれを考え出した。どうやら、ubercart製品クラスでもあるコンテンツタイプを作成している場合は、上記でリンクしたチュートリアルに従って、ubercartのものを「タックオン」することはできません。上記のチュートリアルによると、モジュール内からコンテンツタイプを作成するには、次のフックを実装する必要があります。
製品クラスでもあるコンテンツタイプを作成するには、上記のリストに次の変更を加える必要があります。
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()
私はこれを理解しているだけなので、訂正や提案を喜んで受け取ります。
私はちょうどこれを考え出していました.これはうまくいくようです.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.' ) );
}