Jump to content

How do assign result of a query to smarty for use in template file


Caroline W

Recommended Posts

I have a function in a php file (for a module) that looks like this:

//Function to get all available combinations from the DB
//Returns an array with combination info

public function getAllProductCombinations(){

//Get all DB info for available combinations
$result = Db::getInstance()->ExecuteS('

SELECT *
FROM `'._DB_PREFIX_.'attribute_lang` a
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination`p ON (p.`product_attribute_combination.id_attribute` = a.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'stock_available`s ON (p.`id_product_attribute` = s.`id_product_attribute`)
WHERE a.`quantity` >= 1 AND a.`id_lang` = 1
ORDER BY `id_product`
');
//Create an array for the comb data
$combinations = array();

foreach ($result as $row) {
$combinations[$product->id] = $result;
}

return $combinations;
}

Now I need this result to be accessible in the tpl file. I have tried different approaches to assign it to smarty, but it's not working.
I have tried assigning it in the function after return $combinations; like;
$smarty->assign('combinations', $combinations);

I have also tried adding "return $this->display(__FILE__, 'product.tpl'); " or $this->context->smarty->assign.

The $combinations variable comes back empty in the tpl file. How can I get this result to use in my template file (part of a module)?

PS v 1.5.6.1

Link to comment
Share on other sites

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...