2
votes

I created a presta module and use the actionCartSave hook. But when I print string in hookActionCartSave function, it display double result I dont know why, can you explain for me that?

My code:


    public function hookActionCartSave()
    {
        if (!$this->active || !Validate::isLoadedObject($this->context->cart) || !Tools::getIsset('id_product')) return;

        print_r('expression');
    }

The result is:


    expressionexpression

Thank you

1
The cart is saved more of one time during the navigation, so the the hook is called more of one time :) - marsaldev
Can I run it 1 time? - phinq

1 Answers

2
votes

The hook ActionCartSave is called in add and update method of Cart class.

public function add($autodate = true, $null_values = false)
{
    /* ... */
    Hook::exec('actionCartSave');

    return $return;
}
public function update($null_values = false)
{
    /* ... */
    Hook::exec('actionCartSave');

    return $return;
}

So if you search in various controller you discover that the cart is saved more times, so the hook is called more of one times :)