Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

PrestaShop Module Development
PrestaShop Module Development
PrestaShop Module Development
Ebook443 pages5 hours

PrestaShop Module Development

Rating: 0 out of 5 stars

()

Read preview

About this ebook

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.

LanguageEnglish
Release dateNov 28, 2014
ISBN9781783280261
PrestaShop Module Development

Related to PrestaShop Module Development

Related ebooks

E-Commerce For You

View More

Related articles

Reviews for PrestaShop Module Development

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    PrestaShop Module Development - Fabien Serny

    Table of Contents

    PrestaShop Module Development

    Credits

    Foreword

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. Creating a New Module

    First steps

    Adding the module configuration

    Making a simple configuration form

    Summary

    2. Hooks

    Registering our module on hooks

    Changing the position of your module on a hook

    Using hooks to display templates

    Using the database class to save comments

    Displaying comments

    Triggering hooks

    Adding a hook

    The dynamic hooks

    Summary

    3. Using Context and its Methods

    Looking at the Context object

    Using the translate method

    Adding CSS and JS in your module

    Checking compatibilities and dependencies

    The compatibility check

    The dependency check

    Summary

    4. Building Module Updates

    Creating a database table on module installation

    Deleting a table on uninstallation

    Upgrading your module

    Updating the module code

    Adding a callback to options

    Summary

    5. Front Controllers, Object Models, and Overrides

    Using front controllers to create a new page

    Creating the front controller

    Maintaining compatibility with the Friendly URL option

    Creating a small action dispatcher

    Displaying the product name and comments

    Including CSS and JS media in the controller

    Adding a pagination system

    Creating routes for a module's controller

    Installing overrides with modules

    Creating the override class

    Editing the template file to display grades on products list

    Creating a new method in a native class

    Using object models to create cleaner code

    Creating the ObjectModel class

    Using the ObjectModel class in our module

    Placing all the database requests in our ObjectModel class

    Using HelperForm to make a scalable form

    Cleaning your code using the hook's controller

    Summary

    6. Admin Controllers and Hooks

    Adding an admin controller

    Adding and installing a new tab to your admin panel

    Uninstalling the tab when the module is uninstalled

    Listing comments in your admin controller

    Improving the list view

    Adding actions on the list view

    Creating your own view template

    Configuring your form view

    Using back office hooks

    Attaching your module to a product hook

    Displaying comments in a product hook

    Displaying comments associated with a customer

    Making links between admin sections

    Summary

    7. The Carrier Module

    First step to create a carrier module

    Using web services

    API description

    Module configuration

    Creating new carriers

    Using web services on shipping cost calculation

    Handling carrier update

    Displaying relay points

    Associating the chosen relay point with the cart

    Displaying the customer's choice in the back office

    Summary

    8. The Payment Module

    Creating a payment module

    Creating the payment controller

    Checking the currency

    Validating a cart into an order

    Displaying information on the order confirmation page

    Creating your own order state

    Associating an e-mail with an order state

    Working with a third-party API

    Updating the module's configuration form

    Displaying the new payment method

    Building the validation API controller

    Summary

    9. Multistore

    Configuring the multistore feature on your PrestaShop

    Enabling the multistore feature

    Creating a new shop

    Updating the MySQL table of the module

    Updating the module code

    Updating the ObjectModel class

    Using Context in the get method

    Updating the AdminController class

    Using the Configuration class with multistore

    Summary

    10. Security and Performance

    Securing your module

    Protecting your module against directory listing

    Forbidding direct access to class and controller files

    Protecting your code against SQL injection

    Protecting your templates against XSS

    Verifying the data with MD5 hash

    Searching for malicious code in modules

    Checking for unusual e-mail sending

    Checking for strange URL calls

    Checking the use of eval

    Checking the use of system, exec, and backquotes

    Checking the use of base64_decode

    Wrapping up on this section

    Performance and optimization

    Using Combine, Compress, and Cache

    Using the cache system

    Using the Smarty cache

    Summary

    A. Native Hooks

    The list of all the dynamic hooks

    Definitions of the variables

    Index

    PrestaShop Module Development


    PrestaShop Module Development

    Copyright © 2014 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: November 2014

    Production reference: 1221114

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78328-025-4

    www.packtpub.com

    Cover image by Monirath Pontiac (<monirath.pontiac@gmail.com>), Benjamin Loembet (), and Fabien Serny ()

    Credits

    Author

    Fabien Serny

    Reviewers

    Romain Berger

    Altaf Hussain

    Sandeep Kamlesh Mishra

    Ratko Projkovski

    Bart Sallé

    Commissioning Editor

    Joanne Fitzpatrick

    Acquisition Editor

    Joanne Fitzpatrick

    Content Development Editor

    Arun Nadar

    Technical Editor

    Humera Shaikh

    Copy Editors

    Janbal Dharmaraj

    Merilyn Pereira

    Adithi Shetty

    Project Coordinator

    Priyanka Goel

    Proofreaders

    Simran Bhogal

    Maria Gould

    Ameesha Green

    Paul Hindle

    Indexer

    Hemangini Bari

    Production Coordinator

    Manu Joseph

    Cover Work

    Manu Joseph

    Foreword

    When I founded PrestaShop 7 years ago, I had just one vision for the company. My idea was to create a worldwide community of talented individuals who are fascinated by e-commerce. Tapping into the power of open source, we could democratize the e-commerce industry. This PrestaShop community would build cutting-edge software that enables everyone to participate in the e-commerce revolution.

    Now, PrestaShop has one of the world's largest open source development communities exclusively dedicated to e-commerce. The community includes 700,000 members from more than 200 countries. These numbers change every day, but our software has been downloaded over 4 million times and translated into at least 65 languages; 200,000 e-commerce stores are now running on PrestaShop.

    Since day one, the PrestaShop community has created this extraordinary ecosystem. It plays a key role in our product development. More than 30,000 commits have been performed on GitHub, making it one of the most active open source projects worldwide. We are very proud to provide our users with open source software, and we embrace this philosophy on a daily basis.

    When building the core of PrestaShop, we intentionally architected a flexible and modular system, which enables anyone to extend the software capabilities by developing their own extensions. These extensions are called PrestaShop modules, and more than 10,000 of them are now available for download. From basic additions to the most advanced features, the possibilities are endless.

    Fabien Serny is one of the most talented web developers I've met in my career. We worked together for more than 5 years to provide solutions for developers who wanted to create new PrestaShop modules. Fabien personally contributed to the core software in order to make it easier for all developers to create their own PrestaShop modules.

    This book is truly a must-have for any web developer who is interested in the PrestaShop technology. All of the best practices and tips to build an outstanding PrestaShop module are included here. They have been cleverly translated into this step-by-step tutorial. Now, it is your turn! Create your first PrestaShop module, share it with others, and be a part of this amazing community. I'm sure you will enjoy reading this book as much as I did.

    Bruno Leveque

    PrestaShop Founder

    About the Author

    Fabien Serny is a former core developer at PrestaShop. He has 10 years of experience in web development and e-commerce. He has worked for several big e-commerce companies in France, and then created his own company named 23Prod in late 2010. In 2014, along with two other former core developers from PrestaShop, he launched Froggy Commerce, a platform that sells simple and powerful modules for PrestaShop based on the needs of e-tailers. You can visit his websites http://www.23prod.com and http://www.froggy-commerce.com.

    I'd like to thank my lovely wife, Camille, who supported and pushed me to write this book.

    I'd also like to thank my co-workers, Gregoire Poulain and Alain Folletete from Froggy Commerce; Bruno Leveque, founder of PrestaShop, who encouraged me to write this book; and some of my former colleagues at PrestaShop: Franck (the wise), Raphaël, Vincent, François, Sabrina, Cécile, Mareva, Julien, Tony, and the rest of the development team and the company.

    Lastly, I would like to thank my family (my mum, Claude, Philou, BreeBree, Greg, Milo, Ludovic, Oliver—the boot, Astrid, Enzo, my grandma, and so on) and friends (Nico, Sophie, Caro, Romain alias The Master, Elodie, Tom, Alain, Seb, Mélo, Micka, Gaël, Gégé, Ludo, Béré, Elo Lobster, Jérome, and so on); I would like to mention them all but it would be a very long list. However, I would not like to thank the great caravan that made me sleep during my trip in America instead of letting me work on this book.

    I would also like to specially thank Benjee, Moni, and Julien, who helped me design the cover of this book; my editors Joanne, Arun, and Humera, who did an incredible job helping me on this book; and my reviewers Romain, Altaf, Sandeep, Ratko, Tom, and Bart.

    About the Reviewers

    Romain Berger gained extensive experience of using PrestaShop while working at BBS Concept, a web agency where he worked on several e-commerce websites, including the impressive Stickaz.com. He is now a frontend developer at Dailymotion, the second largest video sharing platform in the world.

    When Romain is not writing code for Dailymotion, you can find him contributing to open source communities or making music.

    Altaf Hussain has worked with numerous different open source web technologies, especially in e-commerce systems such as PrestaShop and Magento. He is a big fan of PrestaShop coding standards. He has been working with PrestaShop for more than 5 years and has developed advanced modules, custom features to modify default behaviors of PrestaShop, and templates.

    Currently, Altaf is working on PrestaShop, Magento, Drupal, Zend, Yii, and cross-platform mobile apps in Titanium. He is also working on website performance techniques using Nginx, Percona DB, PHP-FPM, Zend OPcache, and Varnish Cache.

    Sandeep Kamlesh Mishra is a software engineer on paper and a marketer at heart. He is an e-commerce and m-commerce enthusiast. He has achieved a Bachelor of Engineering degree from Mumbai University. He works as a backend developer. He has good working knowledge of PrestaShop, Magento, Osclass, and native and hybrid mobile application development. He believes in the power of the Internet and wants to explore the world of start-ups.

    Sandeep works as a software engineer with IGATE Corporation, Bangalore, India. He is a Salesforce developer for web and mobile platforms.

    I would like to thank the author for writing such a great book, taking into consideration PrestaShop developers' needs. I would also like to thank Anugya, Binny, and Priyanka from Packt Publishing for their support during the course.

    Ratko Projkovski is the main initiator, cofounder, and CEO of Blue Zone Ltd., Skopje (www.bluezone.com.mk), a company that started as a mobile marketing company and evolved to be a ISO/IEC 20000-1:2005 and ISO/IEC 27001-1:2005 company. It provides various ICT services to Macedonian and other international clients ranging from entrepreneurs and small/medium size companies to huge international corporations and enterprises.

    These days, Ratko is highly focused on finding new business opportunities and international contacts for further growth and expansion of Blue Zone Ltd., Skopje.

    Ratko's professional profile is based on e-business, official training and self-training for software development, system engineering, information security. He has also attended many seminars/events based on customer relationship management, project management, e-business solutions, e-society, e-government, computer crime, European funds for the development of ICT, among others.

    Along with his full-time professional career, he is also actively interested in indie game development for various platforms.

    Bart Sallé is a web developer from the Netherlands who is specialized in HTML5, CSS3, PHP, MySQL, JavaScript, and jQuery.

    He loves open source software and works with TYPO3, WordPress, Joomla!, Drupal GetSimple CMS, PrestaShop, OpenCart, WooCommerce, osCommerce, and VirtueMart.

    Bart was one of the first people in the Netherlands who started to build his webshops using PrestaShop as a base.

    He is still as excited about PrestaShop as he was back then, when the first stable version of PrestaShop was released.

    Bart's company website can be found at www.os-evolution.com and his personal website can be found at www.bartsalle.nl.

    I would like to acknowledge Jolanda, my wife, and my two beautiful kids, Noa and Fenne.

    I would also like to acknowledge my mother, Lies, and my father, Theo, who passed away in January 2013.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    Preface

    This book covers how to develop different modules for PrestaShop 1.6. It will walk you through the widely used best practices and empower you to use these methods while developing various features in PrestaShop. This book will help you create powerful and scalable modules, thereby improving the performance of your shop.

    Throughout the course of this book, you will be introduced to a number of clear, practical examples of PrestaShop concepts (such as hooks) in the form of a tutorial. You will also get acquainted with the best practices of PrestaShop, which will greatly reduce the probability of introducing errors in your future modules.

    By the end of this book, you will be accustomed with PrestaShop best practices and the important concepts to make a great module.

    What this book covers

    Chapter 1, Creating a New Module, covers the first step of module creation. This chapter introduces you to a small module example with a simple configuration form.

    Chapter 2, Hooks, presents the concept of hooks in PrestaShop, including how they work and how they can be used to interact with the software. The use of the database class is also covered with practical examples.

    Chapter 3, Using Context and its Methods, introduces you to the many methods available in PrestaShop, such as the multilingual function or JS/CSS manager.

    Chapter 4, Building Module Updates, introduces you to the native module update system. Some extra functional tips are also revealed.

    Chapter 5, Front Controllers, Object Models, and Overrides, presents the main design patterns of PrestaShop and explains how to use them to construct a well-organized application.

    Chapter 6, Admin Controllers and Hooks, explains how to create new administration tools, use the helper to build forms or

    Enjoying the preview?
    Page 1 of 1