3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CS-Cart: PHPフックで呼び出される優先度を指定する

3
Posted at

CS-CartにはPHPフックという機構があり、アドオンからコアの振る舞いを変更することができる。フックポイントにアドオンのコールバックを登録しておくと、そのコールバックが呼び出される。

fn_register_hooks(
    'update_product_pre',
    'update_product_post',
);

1つのフックポイントを複数のアドオンで共有するわけだが、コールバックには呼び出される順番がある。上記のように、フックポイントへの登録だけの場合、暗黙的にアドオンのpriorityがコールバック実行の優先度になる。アドオンのpriorityはaddon.xmlで宣言したものだ。

場合によっては、他のアドオンよりも先に(あるいは最後に)コールバックを実行してほしいことがある。そうした場合には、フックポイント名とpriorityのタプルをfn_register_hooksに渡すことで、コールバックの優先度を明示することができる。

fn_register_hooks(
    ['update_product_pre', '1'],
    ['update_product_post', '9999999']
);
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?