mardi 5 septembre 2017

Prestashop error Fatal error: Call to a member function getPageLink() on null in ......file.blockcart.tpl.php

After writing a new controller displaying all products in a shop i got this error message.
don't go so fat, check if you did the same mistake as me
    public function init()
           /parent::init();  //it's required

The controller was written under ps 1.6

mercredi 14 juin 2017

Prestashop add keywords from tags for products

Here is a little code to be added to header.tpl if you want to add the meta keywords ofr a product page


  {if isset($product->tags) AND $product->tags}
   {if isset($product->tags[$cart->id_lang]) AND $product->tags[$cart->id_lang]}
    <meta name="keywords" content="
     {foreach from=$product->tags[$cart->id_lang] item=foo}
     " />

mercredi 13 juillet 2016

Prestashop combinations prices and images

great snippet

    @id_image := ifnull(pai.id_image, pi.id_image) as id_image,
            ifnull(shop_domain.value, 'domain'),
            if(CHAR_LENGTH(@id_image) >= 5,
                concat(SUBSTRING(@id_image from - 5 FOR 1), '/'),
            if(CHAR_LENGTH(@id_image) >= 4,
                concat(SUBSTRING(@id_image from - 4 FOR 1), '/'),
            if(CHAR_LENGTH(@id_image) >= 3,
                concat(SUBSTRING(@id_image from - 3 FOR 1), '/'),
            if(CHAR_LENGTH(@id_image) >= 2,
                concat(SUBSTRING(@id_image from - 2 FOR 1), '/'),
            if(CHAR_LENGTH(@id_image) >= 1,
                concat(SUBSTRING(@id_image from - 1 FOR 1), '/'),
            '.jpg') as image_url,
        SEPARATOR ', ') as combination,
    ROUND(p.price, 2) as price,,
    ps_product p
        LEFT JOIN
    ps_product_attribute pa ON (p.id_product = pa.id_product)
        LEFT JOIN
    ps_stock_available pq ON (p.id_product = pq.id_product
        AND pa.id_product_attribute = pq.id_product_attribute)
        LEFT JOIN
    ps_product_lang pl ON (p.id_product = pl.id_product)
        LEFT JOIN
    ps_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute)
        LEFT JOIN
    ps_attribute_lang pal ON (pac.id_attribute = pal.id_attribute)
        LEFT JOIN
    ps_product_attribute_image pai ON (pa.id_product_attribute = pai.id_product_attribute)
        LEFT JOIN
    ps_image pi ON p.id_product = pi.id_product
        LEFT JOIN
    ps_configuration shop_domain ON = 'PS_SHOP_DOMAIN'
    pl.id_lang = (
        ORDER BY id_lang ASC
        LIMIT 1
    pal.id_lang = pl.id_lang
GROUP BY pa.reference
ORDER BY p.id_product , pac.id_attribute;

dimanche 24 avril 2016

Php script to to close unclosed HTML tags in text

When displaying the few words or characters of a post,
we usually use
echo substr($string,0,numberOfChars);

The problem is that if the text was extracted from a rich edited post, some unclosed tags will impact the display of your site, since the extracted characters may contain unclosed HTML tags.

The solution is to use that little code found at
written by

That's great

function closetags($html) {

    preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);

    $openedtags = $result[1];

    preg_match_all('#</([a-z]+)>#iU', $html, $result);

    $closedtags = $result[1];

    $len_opened = count($openedtags);

    if (count($closedtags) == $len_opened) {

        return $html;


    $openedtags = array_reverse($openedtags);

    for ($i=0; $i < $len_opened; $i++) {

        if (!in_array($openedtags[$i], $closedtags)) {

            $html .= '</'.$openedtags[$i].'>';

        } else {

            unset($closedtags[array_search($openedtags[$i], $closedtags)]);



    return $html;


jeudi 25 février 2016

Prestashop Affectation tous les produits à un entrepot | Warehouse product affectation

In prestashop if we want to affect all products to one warehouse automatically, we ca use this little snippet.
Note that you have to backup warehouse_product_location table before any data modification.
You have to change id_warehouse=> XXX with the new warehouse id
The script is launches two instructions : 1- Affect simple product to warehouse then 2- Affect products with combinations to warehouse
 * Wassim JIED
 * (2016)
 * Well made in 619
 */ header("Cache-Control: no-cache, must-revalidate");
  function processMoveToWareHouse()
   Logger::addLog('Affecting warehouses',1);
   $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product';
   echo 'running : '.$sql .'
   if ($results = Db::getInstance()->ExecuteS($sql))
   foreach ($results as $row){
    Db::getInstance()->insert('warehouse_product_location', array(
    'id_product' => (int)$row['id_product'],
    'id_product_attribute' => 0,
    'id_warehouse'=> 2
   Logger::addLog('Done with products without combinations ... gonna continue',1);
   $sql = 'SELECT id_product,id_product_attribute FROM '._DB_PREFIX_.'product_attribute';
   echo 'running : '.$sql .'
   if ($results = Db::getInstance()->ExecuteS($sql))
   foreach ($results as $row){
    Db::getInstance()->insert('warehouse_product_location', array(
    'id_product' => (int)$row['id_product'],
    'id_product_attribute' => (int)$row['id_product_attribute'],
    'id_warehouse'=> 2
   Logger::addLog('Done with warehouses... going to die',1);

Note lase that this script can be run on mysql script window using this command:
  insert into `ps_warehouse_product` (`id_product`,`id_product_attribute`,`id_warehouse`) 
    select p.id_product,0,2 from ps_product_attribute p;
insert into `ps_warehouse_product_location` (`id_product`,`id_product_attribute`,`id_warehouse`) select pa.id_product,pa.id_product_attribute,2 from ps_product_attribute pa ;