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

Looking at the Context object


The Context objectis a directory containing a list of objects. It is available in controllers and modules, and you can access it this way:

$this->context;

If you are not in a controller or a module, you can retrieve it by using the getContext method. The Context class uses a singleton and this function will return the instance of the Context object:

$context = Context::getContext();

Note

In a few words, if you don't know what a singleton is, it's a system that restricts the instantiation of a class to one object. Although this is not mandatory, it's a good idea for you to read some articles, such as the Wikipedia article about it at http://en.wikipedia.org/wiki/Singleton_pattern .

Here is the list of objects available in the Context class:

  • cart: This object contains the Cart object of the customer in the front office. This object is not available in the back office:

    $this->context->cart;
  • customer: This object is filled with the Customer object in the front...