disco_ii_disco Posted November 1, 2014 Share Posted November 1, 2014 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 1, 2014 Share Posted November 1, 2014 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. Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 1, 2014 Author Share Posted November 1, 2014 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 Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 1, 2014 Author Share Posted November 1, 2014 Oops.. spoke to soon. There is still a problem with the sql and getting the category id in to it. When I substitute: '.$category['cat_id'].' for: 217 (for example) it works. Can $category['cat_id'] be used in display_category triggers? Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 1, 2014 Share Posted November 1, 2014 Hooks are executed 'inline' with the code. The displayCategory() function does not have a variable named $category, so the answer is no. But the function does have a variable named $catData, so try using: $catData['cat_id'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.