Book Image

PrestaShop Module Development

By : Fabien Serny
Book Image

PrestaShop Module Development

By: Fabien Serny

Overview of this book

Table of Contents (19 chapters)
PrestaShop Module Development
About the Author
About the Reviewers

Handling carrier update

If you have played a bit with the carrier system in the PrestaShop administration panel, you might have noticed that when you update a carrier, the carrier ID changes. In fact, when you update a carrier, PrestaShop will create a new carrier by copying the one you want to update and applying your changes. It will then delete (set the flag deleted to 1) the old carrier.

So if we think about it and if a merchant updates a carrier attached to our module, the carrier ID saved in the configuration table won't match anymore. Do not worry, we can handle this very simply.

First, we will hook our module on the actionCarrierUpdate hook, which, as the name indicates, is called when a carrier is updated. So, add the following code in the install method of your module's main class:

if (!$this->registerHook('actionCarrierUpdate'))
  return false;

As usual, we will create the matching hook method in mymodcarrier.php:

public function hookActionCarrierUpdate($params)