Jump to content

PHP errors in Block info and Block viewed


Recommended Posts

Hi in my error log I get several php errors everyday (about 20) relating to Block info and block viewed

[19-Oct-2010 19:45:32] PHP Warning: Invalid argument supplied for foreach() in /home/stormjew/public_html/modules/blockviewed/blockviewed.php on line 92
[19-Oct-2010 21:16:52] PHP Warning: Invalid argument supplied for foreach() in /home/stormjew/public_html/modules/blockinfos/blockinfos.php on line 108

block info code is below:

    {
       global $smarty, $cookie;

       $cms = CMS::listCms($cookie->id_lang, $this->id);
       $id_cms = array();
       foreach($cms AS $row)
           $id_cms[] = intval($row['id_cms']);
       $smarty->assign('cmslinks', $id_cms ? CMS::getLinks($cookie->id_lang, $id_cms) : array());
       return $this->display(__FILE__, 'blockinfos.tpl');
   }



This is line 108

    foreach($cms AS $row)



and block viewed code

            $productsViewedObj = array();
           foreach ($productsViewed AS $productViewed)
           {
               $obj = (object)'Product';
               if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
                   continue;
               else
               {



Line 92 is

foreach ($productsImages AS $pi)



Any help on this will be sooooo appreciated!!

Louisa

Link to comment
Share on other sites

I've never seen those error messages before. Did you delete all your CMS pages? It seems that the following line isn't returning an array of CMS pages like it should:

$cms = CMS::listCms($cookie->id_lang, $this->id);



and the following on line 78 also isn't returning an array like it should:

$productsImages = Db::getInstance()->ExecuteS('
SELECT i.id_image, p.id_product, il.legend, p.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product)
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = i.id_image)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default)
WHERE p.id_product IN ('.$productIds.')
AND pl.id_lang = '.intval($params['cookie']->id_lang).'
AND cl.id_lang = '.intval($params['cookie']->id_lang).'
AND i.cover = 1'
);



That's means one of the tables ps_product, ps_product_lang, ps_image, ps_image_lang or ps_category_lang is missing information. You should check these tables and also ps_cms and ps_cms_lang and make sure they aren't empty.

Link to comment
Share on other sites

Hi Rocky,

Thanks, as always, for getting back to me. I haven't deleted any cms pages as far as I know.

I don't really know anything about php, but I went into myphp admin and checked those tables and they all have things in it. (don't know how to tell if something is missing tho)

I do have some products which don't actually have a category because I deleted the category but not the products (just haven't got round to it) could that be anything to do with the problem?

Thanks again
Louisa

Link to comment
Share on other sites

Go to the configuration page of information block and make sure that you have CMS pages ticked there. If you do, I suggest that you add code to debug the queries. For example, temporarily change lines 82-86 of classes/CMS.php (in PrestaShop v1.3.2) from:

$result = Db::getInstance()->ExecuteS('
SELECT c.id_cms, cl.link_rewrite, cl.meta_title
FROM '._DB_PREFIX_.'cms c
LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.intval($id_lang).')
'.(($selection !== NULL) ? 'WHERE c.id_cms IN ('.implode(',', array_map('intval', $selection)).')' : ''));



to:

echo '
SELECT c.id_cms, cl.link_rewrite, cl.meta_title
FROM '._DB_PREFIX_.'cms c
LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.intval($id_lang).')
'.(($selection !== NULL) ? 'WHERE c.id_cms IN ('.implode(',', array_map('intval', $selection)).')' : '');
$result = Db::getInstance()->ExecuteS('
SELECT c.id_cms, cl.link_rewrite, cl.meta_title
FROM '._DB_PREFIX_.'cms c
LEFT JOIN '._DB_PREFIX_.'cms_lang cl ON (c.id_cms = cl.id_cms AND cl.id_lang = '.intval($id_lang).')
'.(($selection !== NULL) ? 'WHERE c.id_cms IN ('.implode(',', array_map('intval', $selection)).')' : ''));



The SQL query should then be displayed on your website. Copy it into the SQL tab in phpMyAdmin to run it and see what gets returned. You can do a similiar thing with the viewed products code.

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...