Jump to content

Error when assigning a variable from a display_category code snippet


disco_ii_disco

Recommended Posts

Hi all,

 

I have created a simple mysql table (related_articles) and a simple code snippet (code below) which has the display_category trigger:

{php}

if ($related_articles = $GLOBALS['db']->query('SELECT `id` AS articleId, `description` AS articleDescription, `url` AS articleUrl, `type` AS articleType  FROM `related_articles` WHERE `type` = "cat" AND item_id = '.$category['cat_id'].' ORDER BY `id` DESC')) {
	
  foreach ($related_articles as $related_article) {
		$related_article_vars[]	= $related_article;
	}
  	
$GLOBALS['smarty']->assign('RELATED_ARTICLES', $related_article_vars);

}

{/php}

However, I am getting this error message in my logs:

PHP Fatal error: Call to a member function assign() on a non-object in /includes/extra/snippet_1679091c5a880faf6fb5e6087eb1b2dc.php on line 15

It appears the $GLOBALS['smarty']->assign() is not working as it should. All the sql is fine.

 

I have been battling with this for a few hours now so hopefully someone can point out an obvious error!

 

Kind regards,

 

Chris

 

 

Link to comment
Share on other sites

The snippet is triggered from 'class.cubecart.display_category' which is in the Catalogue class, displayCategory() function. In this function, the statement just preceding the hook statement is a smarty->assign() command. So, for PHP to complain is very strange.

 

And PHP is complaining about a statement on line 15 of the snippet.

 

Please find the actual snippet in the /includes/extra/ folder. The code you have provided does not have 15 lines in it.

Link to comment
Share on other sites

Hi bsmither,

 

Your advice pointed me in the right direction.

 

The php error message related to a different code snippet (which I had deleted from admin but was still in the includes/extra folder).

 

Once I realised there was no error caused by the snippet I looked more closely at the output code and realised I had typed it in to a section which is only visible if the category has no image!

 

Three hours wasted but another few CubeCart 5 lessons learned!

 

Regards,

Chris

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...