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
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating new carriers


Now that we have a working configuration form, we will have to create carriers. In our case, we will create two carriers, one with a classic delivery option and one with relay points.

If you don't know how a carrier works in PrestaShop, I first invite you to create some carriers manually in your administration panel. This will help you understand the method described in the upcoming code.

We will first add the install method in our module's main class, in which we will call a method named installCarriers:

public function install()
{
  if (!parent::install())
    return false;
  if (!$this->installCarriers())
    return false;
  return true;
}

Unfortunately, there is no native method to create carriers, even in the CarrierModule class. So, we will have to create the method ourselves. We will build it step by step:

  1. First, create the installCarriers method:

    public function installCarriers()
    {
    }
  2. Next, in this new function, retrieve the ID of the default language:

    $id_lang_default...