How to create a Prestashop module

Creating a new prestashop modules is not difficult as it seems. To create a simple module there are 4 easy steps to follow.

Let us create an image slider for the home page

1. Add a new row for the new module in the ps_module table

name: blockslider

active: 1

2. Create the .php file

Create a folder named blockslider in the prestashop modules directory and create blockslider.php file within the directory with below code.

3. Create the .tpl file

Here you can use any JQuery based slider or create your own. Just remember to copy the relevant JS and CSS files along with any images to the modules folder and just call the JS and CSS files in the .tpl file.

Create blockslider.tpl file in the same directory as above.

4. Transplant the module

Once the module is created, it will appear in the Front Office Features section.

Make sure it is installed and enabled

Just transplant the module to Homepage content

Integrating Prestashop shopping cart with existing PHP -MySQL Authentication

Assumptions

Here we are assuming that you are using PHP – MySQL and you have an existing list of clients/users already maintained in a seperate table.

You have your own registration, login and logout mechanisms

Step 1: Prestashop cookies

First let us understand little bit about Prestashop cookies

A customer login prestashop cookie is as below

Cookie name: ps

Cookie content:id_guest%7C1%C2%A4id_customer%7C1%C2%A4customer_lastname%7CLASTNAME%C2%A4customer_firstname%7CFIRSTNAME%C2%A4logged%7C1%C2%A4passwd%7CMD5_PASSWORD%C2%A4email%7CEMAIL%C2%A4

Note: there can be some other parameters as well in the cookie but I have included only the ones which we are interested.

The cookie is ofcourse not readable. It is encrypted and decrypted using Rinjdael or Blowfish.

Apart from that there is also a SALT phrase which is added through the settings.inc.php file

Just for demonstration purposes I have removed the SALT phrase in settings.inc.php (in the config directory) as below

I disabled the cookie encryption and decryption process in Cookie.php file (in the classes directory) as shown below

Comment below lines

 

After doing the above changes, try to login again. If everything is done correctly, you should be able to login successfully. After you login the cookie generated will be readable.

Just to make the cookie bit more clear to us, let us run PHP urldecode

Here’s the output

id_guest|1¤id_customer|1¤customer_lastname|LASTNAME¤customer_firstname|FIRSTNAME¤logged|1¤passwd|MD5_PASSWORD¤email|EMAIL¤

Now this cookie is quite readable and easy to follow.

id_guest=1, id_customer=1, customer_lastname=LASTNAME, etc

Step2: Import your existing users to the prestashop customer table

Export all users from your database and include fields like memberid,firstname, lastname, username, md5(password), salutation and import it into the ps_customer table in prestashop.

Step 3: Single sign on

Once the import-export is done, achieving the single sign on is very easy

All you need to do is when a user logs in on your website apart from the usual cookie which you create, you also need to create one more cookie for the prestashop login (even better is to combine the cookie and name is as ps which might need a corresponding change in your authentication code). The format of this cookie would be same as the one obtained after the urldecode above in Step 1. Cookie name would be ps

Step 4: Enable cookie encryption

Note that we turned off all cookie encryptions in Step 1. We can turn on cookie encryption and decryption provided you are able to replicate the same through a function on your existing site when you create the cookie.

Step 5: Close all loops

A. Disable password reset through Prestashop and send users to your website password reset process and in that process make sure you update password in both the tables

B. When a new user registers make sure you add a new entry in the Prestashop table as well (ps_customer and ps_customer_group)

C. When people login on prestatshop, the form action URL can be changed so that it goes to your custom authentication code which enables you can create the necessary cookies