Products do not save in PS 1.6

Save and Stay button in Prestashop 1.6.0

The “Save and stay” button does not work in product detail in various subversions of Prestashop 1.6.0.9. This problems first appeared with Chrome some time ago. But the button was more or less operational in Firefox – until the March 2019 Firefox update.

There is a nice and easy to install module attempting to resolve the issue. Unfortunately this solution is not 100% reliable. Some customers were greatly satisfied with the module, some reported the problem as still unsolved, even when advised to clear the browser cache.

Thus, the only reliable solution is to upgrade the prestashop version. You may decide for the “big” upgrade to PS 1.7 or for the much easier upgrade to PS 1.6.1. Yes, that is righ, any subversion of PS 1.6.1.X is sufficient, but you will certainly use the last one. let us assume prestashop 1.6.1.24.

Can you keep your customized PS 1.6.0.x default theme when upgrading to latest PS 1.6.1.24 subversion? The answer is yes, with due precautions. These are issues we are aware:

  • Contact form – the contact form in in PS 1.6.1.24 get some extra hidden fields and will not work after upgrade. Get the PS 1.6.1.24 zip file, unpack and replace \themes\default-bootstrap\contact-form.tpl with the same file from the unpacked zip
  • Product page. Check product with combination and special prices. It it does not work properly (the prices do not change as expected), you need to replace both \themes\default-bootstrap\product.tpl and \ themes\default-bootstrap\js\product.js . Do not forget to clear the browser cache

Warning – upgrading Prestashop without upgrading the theme is always risky. On the other hand, I am aware of many shops undergoing such kind of speed upgrade without any several errors.

Invalid token: direct access to this link may lead …. (PS 1.7)

When navigating in the backoffice, the error Invalid token: direct access to this link may lead to a potential security breach pops up.

This problem has been widely discussed and there are several possible solutions:

  • change the php version (possibly to php 7.1 or higher)
  • upgrade all php packages
  • remove unused php packages
  • disable the session IP checking in prestashop backoffice

Recently a client encountered the invalid token problem on Prestashop 1.7.5 – in the products page only. Unfortunately, neither of the approaches mentioned above worked, even the complete upgrade of php libraries had no effect. This error seemed as a nightmare to debug, but luckily enough, I have noticed that the problem disseapears after turning the https off. Thus the cause is clean, at least in this case:

Cause: This server used nginx as reverse proxy to apache. The standard setting does not pass the $_SERVER[‘HTTPS’] variable to php. Prestashop 1.7 (comparing to previous versions) improved the https detection by adding $_SERVER[‘HTTP_X_FORWARDED_PROTO’] in Tools:: usingSecureMode . But this is apearently not sufficient.

Solution: Pass the $_SERVER[‘HTTPS’] into php. It can be done by modifiing nginx configuration, but I have opted for a less direct approach – prepending a file in php.ini. The content of the file is

<?php
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
$_SERVER['HTTPS']='on';
$_SERVER['SERVER_PORT'] = 443;
}
if(isset($_SERVER['HTTP_X_REAL_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}

the added bonus of this approach is fixing the remote address issue (Add my IP in the Maintenance section).

Summary

  • switch off the https protocol: set the Use SSL to No in the backoffice (Configuration / Main), if not possible, set PS_SSL_ENABLED to 0 in the ps_configuration database table)
  • check if the invalid token problem disappears
  • switch the https back
  • alternatively to the steps above, inspect the output of phpinfo() function. Open the page with phpinfo(); function over https protocol. Look for $_SERVER[‘HTTPS’] . If not present, this is your problem.
  • if https is really the culprit, edit the php.ini file and use the auto_prepend_file directive to prepend the file containing the code above and reload apache…. or on a shared hosting, ask your provider

Tweaking prestashop search – searching by products codes (reference)

Prestashop search engine is based on individual words stored in the database. It will return no results for incomplete (partial) words.

This problem was recently encountered on a website selling quad spare parts. Every spare part has a reference number in the form xxxxyyyzzzz where xxxx is specific for group , yyy for subgroup and zzzz for the product itself. Searching for “xxxx polaris” should return all spareparts belonging to the the group “xxxx” and matching the word polaris. But, as mentioned above, “xxxx” is only an incomplete word and will be normally ignored by the search engine. A simple solution is adding several lines of code into the indexation method of the Search class and rebuild the index:

if($key == ‘reference’) {
for($i = 5; $i < 10; $i++) {
if(strlen($value) > $i) {
$words[]=substr($value,0,$i);
}
}
}

Extending tinyMCE editor in prestashop 1.6 – the full story

Tiny MCE is the rich text editor used for editing the large multilangual text fields like product desription or content of CMS pages. The interface used in PS 1.6 is rather a moderate one and many features were ommited. Just take a look at the available buttons in the classic example .

Fortunatelly, adding extra buttons to the default PS 1.6 tiny MCE is not difficult. Specifically, you will need:

1) Modify the tinyMCE settings

Locate the /js/tinymce.inc.js file, open in in a clean text editor and add the required functionality. Simply inspect the source code in the classic example and add plugins and buttons you need. Alternatively, if this seems complicated, you may use the whole /js/tinymce.inc.js file as described in another tutorial , but be sure to complete the steps 2 and 3 as described below.

2) Disable the html validation

by modifiing the prestashop Validate.php class. For several reasons, it is considered a bad practice to modify Prestashop core classes, one of them beeing the fact that these modification will not persitst through the next upgrade. Therefore:

a) in a clean text editor (e.g. notepad), create a clean file named Validate.php and copy paste the following code inside it:

b) copy the file into the directory /override/classes/

c) delete the file /cache/class_index.php

3) In backoffice go to the Preferences :: General and set the option Allow HTML purifier to off . Without it, the HTML purifier will keep removing certain elements – for example, you will be unable to insert a new window link.

Adding YouTube video in Prestashop 1.6

Inability to embed youtube video in Prestashop 1.5 product and CMS pages raised a lot of confusion on prestashop forums and promoted development of various modules.

Fortunatelly, this issue no longer persists in Prestashop 1.6.

1) In backoffice go to the Preferences :: General and set the option Allow iframes on HTML fields to yes . This option is present at least in version PS 1.6.0.9 and higher. You may neet to set the option Allow HTML purifier off as well.

2) Find the video on youtube and click on the Share option. Copy the full code into the clippoard (e.g.

3) In the backoffice, go to the product detail and locate the Description field. Find the Tools button in the editor toolbar, click it to expand and select the Source code button. Paste the youtube code copied in the previous step into the source code pop up window.

4) Press OK to close the source code pop up, press than Save and Stay to actually save the changes. You will see a large questionmark in the place you have copied the video, but this is normal and the video is visible at the frontend.

5) You can use the same approach for CMS pages.