Table of contents
Developer tips and tricks
How to check whether a user is logged to PrestaShop or not
You can easily perform this check by using the
isLoggedBack() method provided in the
Employee class (
This example assumes your file is located in the administration folder:
isLoggedBack() method was located in the
Cookie class in PrestaShop 1.4.x, and was moved to
Employee class in v1.5.x.
How to find the speed bottleneck on a site
Try to enable the profiling feature, it will highlight which part of the code is slowing down your server.
- Put your store in maintenance mode.
- In your PrestaShop v1.5.x store, edit the
- On line 44, replace
- Go to your store homepage and reload the page.
You should now be able to see how much time is consuming each function and SQL query.
How to retrieve the carrier's id
In PrestaShop 1.4, you could use
The same result can be achieved in PrestaShop 1.5 with
How to retrieve the cart's id
You have several ways to retrieve the Cart ID from the current visitor, the easiest one is to use the Context.
/modules/blockcart/ajax-cart.js file and look for this line:
Below this line, add this:
Create a file named
/modules/blockcart/ with the following code inside:
How to import products from a XML file
With PrestaShop you can easily import your data using one of these options:
- By using the "CSV Import" feature in your Back-office
- By using the PrestaShop Web-service (custom development required)
- By using the existing classes (custom development required)
Below is a quick code snippet that is working with a specific XML document (stored as a heredoc string). It will create or update all the products, and take into account their price, availability, name, description, weight, etc.
Please note that:
- This code MUST be adapted to your own XML needs!
- This code will is not designed to work with combinations (color, sizes, etc.)
- This code does not create categories for you, and is adding all the products to the "Home" category