Prestashop 1.6 | Product import through CSV tips

Recently I have been uploading lots of products to the website http://www.assamesebooks.com
The upload was done through uploading a CSV file with all the product details.
The "Sample" CSV file to upload products is provide by Prestashop.

  1. To begin with navigate to the upload product CSV screen from the menu
Catalog -> Products - > click on the small import icon above the search button to navigate to the import CSV screen

Products Menu under Catalog

The import icon as highlighted

The CSV import Page

2. There are few import import settings on this page i.e.
  • Field Separator - This is the separator by how the individual columns in you CSV are separated. By default it is semicolon (;) so please be mindful of changing it if your file is a comma separated one
  • Multiple Value Separator - There are times when you have multiple values for a column. For example multiple Meta-keywords.  In that case you need to use the separator you mention here in the file.
  • Delete All products before import - I think this is self explanatory and a dangerous option. Use wisely as the products get deleted before the import starts. Which means even if there is a failure during the import; the products are already deleted.
  • Force all ID numbers - Use this option in case you want the ID in your CSV file to be used instead of auto generated by the database.
3. The sample CSV file can also be downloaded from this page. You can find it in the lower right corner side of the page. 



4. On the next page you need to MAP the columns in the CSV file to the expected values by Prestashop for product upload. This step is super important. 
Please select the data from the drop down which is represented by the CSV column.
Another important setting here is "Lines to skip". Use this option to skip the header row from your CSV file. If your CSV has no header then give this as 0 to read and process all the rows in the CSV.

You can also save your mapping by giving some name and clicking the save button. This way; next time when you plan to upload the CSV you don't have to do all the mappings.

5. Finally you are ready to start the import process. Click on the IMPORT button the the bottom of
the page.

6. Before we wrap up, I would share some tips of the way data is captured in the CSV file. Most of the columns in the CSV is self explanatory but some need special guidance. Below screen shot has those important column from my CSV file.


  • Tags - A tag is used to group related products with same search term. For EX: if we search for History then books under all categories related to History should come up who are tagged with the term History. It is a multi value column. You can give multiple values separated using the separator.
  • URL rewritten - This is supposed to be used to make SEO friendly URLs but some how populating this value in the CSV gives weird errors. So, I prefer keeping this column empty. In that case Prestashop auto generates the URL rewritten value based on the product name which as per me is a desired solution.
  • Image URLs -  This is again a multi valued column cause a product can have many images and you can give the URL of all those images separated by the separator. The funny thing is how do we get the URL of the images of a product that you are trying to upload.
    What I did is that I created a folder in the root of my server i.e. at public_html named a productImages and uploaded all the images here. Hence, the URL for the images became as "http://assamesebooks.com/productImages/AD00636.jpg". I used this URL in the CSV.
  • Feature(Name:Value:Position) - This is the most complex to understand column and the MOST important one too. This is important cause it helps us upload custom attributes of the product. For example products on http://assamesebooks.com had attributes like pages numbers, Author, Translator, year of publication etc.
    First of all we need to register our custom attributes in Prestashop. This can be done by following menu item i.e.

    Catalog - > ProductFeatures
    Post which you can mention all of these attributes / features along with their values in the same column separated by multi value separator. For example :

    Sub Title:War Book;Author:Anu Barua;Publisher:Purbanchal Prakash;Publication Year:2015;ISBN:978-81-7213-254-5;Language:Assamese;Pages:164;Weight (gms):286


    It took me nice 1 hour to figure out how to do this :-)

Hope these tips help some one save valuable time.. :-P













Fatal error: Maximum execution time of 30 seconds exceeded in PHP

The error stated in the title occurs if a database query / script is taking more than 30 seconds to execute. It is a safe guard mechanism in case you mistakenly ended up running an infinite loop.
However, many times it can be a genuine script taking m,ore time due to certain external factors.
In my case it was because of the database query with number of joins taking extra time.

The issue can be handled in 2 ways i.e.

  1. If you feel that it is just a single one off case taking more time then write the following line just before executing the script. It will increase the script execution time to 5 minute (300 seconds)

    ini_set('max_execution_time', 300); //300 seconds = 5 minutes

  2. But if you want to increase the execution time for the entire application then you will have to edit the PHP.INI file. You will have to update the below setting i.e.

    Find this line:
    max_execution_time

    Change its value to 300:
    max_execution_time = 300

Prestashop || Payment Method based on geographic location

Dear friends,

This is yet another tutorial based on my experiences using Prestashop 1.6 on my application i.e. http:/www.assamesebooks.com

Case Study
The requirement was very simple i.e. there are certain Payment Methods which we did not want to be available in certain delivery locations. For example: We do not want  user to place a Cash On Delivery (COD) order for International delivery locations.

Solution

  1. Prestashop has an inbuilt solution to tackle such problems. Please navigate to following location in Prestashop Admin i.e Modules -> Payment 


  1. On the "Payment" page; scroll to the bottom where you find the section "COUNTRY RESTRICTIONS
  2. As you can see, both the payment gateways from my website are listed here with the options to enable / disable it for a specific country.
  3. Now, you can make changes to the Payment Method based on the geography. :-)

Shipping charge based on location, country, city in Prestashop store

Hello Friends,

I come here with yet another tutorial on Prestashop base on my experiences from my website http://www.assamesebooks.com. This time it is about setting up Shipping Rates based on country / state and different combinations of it. Prestashop is a very versatile platform and it has solution for every requirement. It is just that you need to play with the system and figure out the correct way. I am saying this cause you may have to pay several dollars and buy a Prestashop module for what I am going to tell you here. so let's start..

Use Case
This requirement aroused because of the fact that we were given different Shipping rates for different  Indian States and different countries for international delivery by our shipping partner. Hence, setting up a common Shipping rule would have no way sufficed the requirement.

Solution


  1. Shipping Rule in Prestashop works based on Zones. Zones are nothing but group of Countries / states which will have common shipping rules.
  2. Hence, technically you will have to create a separate Zone for each country / state combination for which you have a different shipping rule.
  3. Zone can be accessed from Prestashop Admin panel under following menu i.e. Localization -> Zones 

  4. Creating a Zone is also very simple. So, start with creating a Zone 
  5. Next, Create a country and make sure that you add it to the zone that you create. 
  6. You can also create State and add that to the County and Zone of your liking.
  7. Once you are done creating the Zone / Country / State then you need to go to the Shipping Page in Prestashop admin panel i.e. Shipping -> Carriers
  8. Choose to create a new Carrier ans select the Zone and provide the Shipping charge for it. The Shipping charge can be either weight based or Order cost based.

  9. Repeat the step of creating Carriers for different Zones which you might have created for different States / Country. You can see in the screen shots below that  I have created a Zone named India to which I have only added the Country India. Thus I can select "India" zone and define the shipping charges which will cover my Domestic Shipping Rule requirement.
    Like wise, there are other Zones for International Locations and I have collectively made them as part of the another carrier.
  10. Domestic Shipping Rule and Carrier

    International Shipping rule and Carrier
  11. Additionally you can also restrict the users from selecting countries in Address creation wizard that are not covered by you by selecting the check box "Country Options - Restrict country selections in Front Office to those covered by active carriers"


    That's it. Now you shall be able to select the carriers only based on the delivery address County / state during checkout. And corresponding shipping charge will get applied to the order.
    See the Carrier name which is for Domestic order


    This is the carrier for Shipping International orders

Changing Email Template in Prestashop

Hello Friends,

I have been lately working on my website http://www.assamesebooks.com which is build on the wonderful open source cart Prestashop v1.6

Case Study
This post is a tutorial on how to change template of the notification emails that are sent from the application. I would be taking the New Order Notification email (new_order)  for the merchant as an example for customization. The missing thing in this notification email is that it does not contain the ORDER STATUS as part of it. Hence, in case an user tried to place an order and decides to cancel it in the payment gateway page; the order gets placed with status as "Payment Error". The notification email says that an order is placed but there is no way to know if the order was successfully placed or not.

Solution

  1. There are various variables that are used in the email template to print the order details. These variable are populated and sent from various PHP files. In this case it is done through the following file i.e. /classes/PaymentModule.php
  2. Unfortunately, this file doesnt pass the order status to the email template. However, the file does have the order status variable declared in it. So all I had to do is pass this variable as well to the list of parameters being passed to the email template. 

    You can see the $order_status variable already declared


    So, all I had to do is pass this variable to the list being sent to email template
  3. Once, this is done we need to update the email template with this variable. The email templates in Prestashop can be access from Localization -> Translations -> email templates -> email module -> new_order menu in Prestashop Admin 











  4. All you have to do is select to edit the template as HTML / Text and add following to print Order status i.e. Order Status: {order_status} order_status is the variable that I set in the PHP to pass the status value 


  5. Now when a new order alert mail comes to your mail box; you can see the order status as well in it 


    That's all... Keep coding.. :-)