You are previewing PrestaShop Module Development.
O'Reilly logo
PrestaShop Module Development

Book Description

Develop and customize powerful modules for PrestaShop 1.5 and 1.6

In Detail

The number of e-commerce websites has drastically increased in these past few years. Building your own web store is a complex and expensive task; that's why open source solutions such as PrestaShop have become so successful in tackling this issue. The main interest with open source solutions is that you can easily add or edit features by creating modules.

This practical, hands-on guide provides you with a number of clear, step-by-step exercises to help you understand how PrestaShop works, and also help you add and edit features.

Starting with the basics, this book takes you through complete module development in an effective manner. You will learn about module architecture, what a hook is, and how to use it to add functionalities to PrestaShop. You will also see how to build payment and carrier modules and make your module multistore-ready. Develop PrestaShop modules the right way and make them secure and compliant with different versions of PrestaShop.

What You Will Learn

  • Code your own module from scratch
  • Explore best practices for database table creation
  • Use hooks or implement overrides
  • Discover the many native methods available in PrestaShop
  • Make new administration tools
  • Create fully functional payment modules
  • Develop carrier modules
  • Secure and optimize your modules
  • Build functionalities compliant with the multistore feature
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. PrestaShop Module Development
      1. Table of Contents
      2. PrestaShop Module Development
      3. Credits
      4. Foreword
      5. About the Author
      6. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      9. 1. Creating a New Module
        1. First steps
        2. Adding the module configuration
        3. Making a simple configuration form
        4. Summary
      10. 2. Hooks
        1. Registering our module on hooks
        2. Changing the position of your module on a hook
        3. Using hooks to display templates
        4. Using the database class to save comments
        5. Displaying comments
        6. Triggering hooks
        7. Adding a hook
        8. The dynamic hooks
        9. Summary
      11. 3. Using Context and its Methods
        1. Looking at the Context object
        2. Using the translate method
        3. Adding CSS and JS in your module
        4. Checking compatibilities and dependencies
          1. The compatibility check
          2. The dependency check
        5. Summary
      12. 4. Building Module Updates
        1. Creating a database table on module installation
        2. Deleting a table on uninstallation
        3. Upgrading your module
        4. Updating the module code
        5. Adding a callback to options
        6. Summary
      13. 5. Front Controllers, Object Models, and Overrides
        1. Using front controllers to create a new page
          1. Creating the front controller
          2. Maintaining compatibility with the Friendly URL option
          3. Creating a small action dispatcher
          4. Displaying the product name and comments
          5. Including CSS and JS media in the controller
          6. Adding a pagination system
          7. Creating routes for a module's controller
        2. Installing overrides with modules
          1. Creating the override class
          2. Editing the template file to display grades on products list
          3. Creating a new method in a native class
        3. Using object models to create cleaner code
          1. Creating the ObjectModel class
          2. Using the ObjectModel class in our module
          3. Placing all the database requests in our ObjectModel class
        4. Using HelperForm to make a scalable form
        5. Cleaning your code using the hook's controller
        6. Summary
      14. 6. Admin Controllers and Hooks
        1. Adding an admin controller
          1. Adding and installing a new tab to your admin panel
          2. Uninstalling the tab when the module is uninstalled
          3. Listing comments in your admin controller
          4. Improving the list view
          5. Adding actions on the list view
          6. Creating your own view template
          7. Configuring your form view
        2. Using back office hooks
          1. Attaching your module to a product hook
          2. Displaying comments in a product hook
          3. Displaying comments associated with a customer
          4. Making links between admin sections
        3. Summary
      15. 7. The Carrier Module
        1. First step to create a carrier module
        2. Using web services
          1. API description
          2. Module configuration
        3. Creating new carriers
        4. Using web services on shipping cost calculation
        5. Handling carrier update
        6. Displaying relay points
        7. Associating the chosen relay point with the cart
        8. Displaying the customer's choice in the back office
        9. Summary
      16. 8. The Payment Module
        1. Creating a payment module
        2. Creating the payment controller
        3. Checking the currency
        4. Validating a cart into an order
        5. Displaying information on the order confirmation page
        6. Creating your own order state
        7. Associating an e-mail with an order state
        8. Working with a third-party API
          1. Updating the module's configuration form
          2. Displaying the new payment method
          3. Building the validation API controller
        9. Summary
      17. 9. Multistore
        1. Configuring the multistore feature on your PrestaShop
          1. Enabling the multistore feature
          2. Creating a new shop
        2. Updating the MySQL table of the module
        3. Updating the module code
          1. Updating the ObjectModel class
          2. Using Context in the get method
          3. Updating the AdminController class
        4. Using the Configuration class with multistore
        5. Summary
      18. 10. Security and Performance
        1. Securing your module
          1. Protecting your module against directory listing
          2. Forbidding direct access to class and controller files
          3. Protecting your code against SQL injection
          4. Protecting your templates against XSS
          5. Verifying the data with MD5 hash
        2. Searching for malicious code in modules
          1. Checking for unusual e-mail sending
          2. Checking for strange URL calls
          3. Checking the use of eval
          4. Checking the use of system, exec, and backquotes
          5. Checking the use of base64_decode
          6. Wrapping up on this section
        3. Performance and optimization
          1. Using Combine, Compress, and Cache
          2. Using the cache system
          3. Using the Smarty cache
        4. Summary
      19. A. Native Hooks
        1. The list of all the dynamic hooks
          1. Definitions of the variables
      20. Index