Loading...

Add-on Connection

We no longer maintain the Knowledge Base since version 4.3.x. All the latest user and developer documentation for 4.3.x and newer versions is now available at docs.cs-cart.com.

  • This article applies to CS-Cart versions:
  • 3.0.x

Addon Connection by Means of Hooks

To display results of an addon operation, it is not necessary to check for addon availability (for example: {if $settings.Addons.affiliate == "Y"}) and create a code that would display these results. Now hooks are used to connect an addon.

In order to create a hook it is necessary to do the following:

  1. Create the hooks directory (if it isn't there) in the addon directory.
  2. In the hooks directory create a directory and give it the name of the controller where the hook will be called.
  3. In this directory create a template with the following name format: hook_name.action_performed_with_hook_code.tpl
    action_performed_with_hook_code can have three options:
    - post – result is added after the hook is declared
    - pre – result is added before the hook is declared
    - override – result overrides the hook block
    For example: product_info.post.tpl
  4. Create the block function hook with the parameter name in the template to which the addon should be connected. The name value is specified in the following way: (name of the directory where hook template is located; it is defined in point 2):(hook_name)
Be careful when changing the existing hook templates, they can be connected in several places.

Examples

1. Use of the pre and post actions. There are two hook templates:

  • rma/hooks/orders/xxx.pre.tpl generates the code <p>Front</p>
  • rma/hooks/orders/xxx.post.tpl generates the code <p>Back</p>

The hook is declared:

1
2
3
{hook name="orders:xxx"}
<p>Middle</p>
{/hook}

 

The following output is generated:

1
2
3
<p>Front</p>
<p>Middle</p>
<p>Back</p>

 

2. Use of the override action. There is a hook template:

  • rma/hooks/orders/xxx.override.tpl generates the code <p>Substitute</p>

The hook is declared:

1
2
3
{hook name="orders:xxx"}
<p>Replaceable</p>
{/hook}

 

When the addon RMA is enabled, the following code is generated:

1
<p>Substitute</p>

 

Home / Docs / Add-ons / Add-on Connection