4 tips to update your module for PrestaShop 1.7

Few weeks ago, PrestaShop announced the availability of PrestaShop 1.7 Beta 1 during the PrestaShop Day Paris. Finally developers can have a look at the new draft of PrestaShop, implementing Symfony 2 and Twig, but in the end, what does it change for developers ? For now on, not too much, only a few pages has been rewritten with Symfony and Twig so you most likely not going to be in trouble (yet).

Here is a list of 4 things I noticed when I tried my modules.

Admin Orders tab

The new back-office template adds some new menu and re-organisation. If your module adds a new tab in the Order menu, then you should be careful with the new SELL tab :

SELL tab

Indeed, in PrestaShop 1.7, the parent tab for your new tab will be AdminParentOrders instead of AdminOrders. If you set your parent tab as AdminOrders then your order page will just be replaced by your new tab.

$tab->id_parent = (int)Tab::getIdFromClassName('AdminAdmin');

Smarty strings are escaped

From a note in build.prestashop.com :

  • Smarty’s strings are now automatically escaped :
  • You should remove all your |escape:'html':'UTF-8' (FOR FRONT OFFICE TEMPLATES ONLY).
  • You should add the nofilter tag if you print HTML.

This might be a problem if you call some HTML code with Ajax, it will simply come as RAW HTML output. To fix this, use the nofilter tag as specified in this note

<h3>{$header_title|escape:'none' nofilter}</h3>

Product tab - hookDisplayAdminProductsExtra

Parameters are not in the QUERY_STRING anymore wichi means there is no more parameters in the URL. So if you had :

$id_product = (int)Tools::getValue('id_product');

It is not gonna work anymore, a workaround would be :

public function hookDisplayAdminProductsExtra($params)
    $id_product = (int)Tools::getValue('id_product', $params['id_product']);

If Tools::getValue() does not find 'id_produt' in the $\_GET then we just ask the function to return $params['id_product'] instead.

jQuery 2

Not really a tip but just a warning as one should be careful with the new method .prop() which works a little differently than .attr(), sometimes you will not have the same return from .attr() in PrestaShop 1.7.

In my use case, .attr() and .prop() are used really simply, so I came up with a little workaround, for example to check a radio button (with chaining method) :

$(this).find('input[type=radio]', context).attr('checked', true).prop('checked', true).change();

I use both .attr() and .prop() to make sure my radio button is well updated.

Also, here is a useless implementation of .prop() just to avoid the "Uncaught TypeError: $(...).prop is not a function(…)" :

if ('function' !== typeof($.fn.prop)) {

            prop: function() {
                return this;


And you, did you find other code improvment tips or would like to give more details about one listed ?

Blog Comments powered by Disqus.