Reputation: 99
I have Prestashop 1.6. In classes/Product.php there are a function for example:
I want to return date from getImages function in my TPL file. How to do it ? Below I write all code from this function:
/**
* Get product images and legends
*
* @param int $id_lang Language id for multilingual legends
* @return array Product images and legends
*/
public function getImages($id_lang, Context $context = null)
{
return Db::getInstance()->executeS('
SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position`
FROM `'._DB_PREFIX_.'image` i
'.Shop::addSqlAssociation('image', 'i').'
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
WHERE i.`id_product` = '.(int)$this->id.'
ORDER BY `position`'
);
}
Thanks for help. Kind regards.
Upvotes: 1
Views: 2111
Reputation: 314
following your example: with the MVC architecture that Prestashop is based, now you have:
So, you need the Controller, what is the responsible to receive the data from the model, prepare it (if it's necessary) and send this data to the template.
Then, you now need to go to the ProductController.php in controllers/front folder.
In the controllers we have a function called initContent() what her function is create and assign the values to the variables that are going to be used in the template.
So, you need to create a new assignment like this:
$this->context->smarty->assign('images_ex', $this->product->getImages((int)$this->context->cookie->id_lang));
And now you can use the variable {$images_ex} in the product.tpl, that is in activated theme root folder.
Hope it helps you.
Upvotes: 1