Threef Posted May 5, 2014 Share Posted May 5, 2014 (edited) Hi everyone,I am currently using PrestaShop 1.6.0.5 at work, and because I'm newbie at PrestaShop it's not going too easy.I'm trying to show additional info about product in product-list.tpl file using Smarty, but I'm doing something wrong.Let's say, I want default category name under product name. So I added : <span class='custom_cat'>{$product.category_name|truncate:45:'...'|escape:'html':'UTF-8'}</span> under product name in product-list.tpl but of course category_name don't exists, so I tried to create this variable, and that's where I encountered problems. I'm not sure where I should do this.I tried in Product.php in __construct() function adding $this->category_name = 'test'; but it didn't worked. Note: value doesn't matter. I just need to display it.I even defined category_name as public variable, and added it to $definition['fields'] but nothing helps. Next I tried ProductController.php in initContent() function: $this->context->smarty->assign(array( (...) 'category_name' => 'test', (...) )); It's 4 days and I'm stuck here. I tried much more things, and most of them too dumb to show. Where should I add my variables? I'm always working on override files. Edited May 5, 2014 by Threef (see edit history) 1 Link to comment Share on other sites More sharing options...
vekia Posted May 5, 2014 Share Posted May 5, 2014 if you're creating variables in that way - you can use it as a variable "category_name" $this->context->smarty->assign(array( (...) 'category_name' => 'test', (...) )); {$category_name} $product variable is an array, and it's defined in different way, its a result of function which retrieve products from database Link to comment Share on other sites More sharing options...
Threef Posted May 6, 2014 Author Share Posted May 6, 2014 Thanks for answer, but this does not work. $product variable is an array, and it's defined in different way, its a result of function which retrieve products from database That's what I'm looking for. But is it an array or Smarty references directly to Product obiect? Do I always need to use $this->context->smarty->assign() to create Smarty vars? On product-list.tpl I can see: {foreach from=$products item=product name=products} And it iterates through the $products array, but that array comes from parent file. I'm searching whole PS for that array. Looking at SceneCore class right now. To ask more precisely: Where I can change and add values to $products array? Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2014 Share Posted May 6, 2014 Thanks for answer, but this does not work. variable that you created (category_name) is a part of smarty array, and it's a individual variable. Not a part of products variable. This code (smarty assing command) will work only in hook where you want to display contents, so it just mean that you have to use it in function which displays contents. regarding to your question about products variable. In this case everything depends on what part of shop you're viewing. for example, product-list.tpl is used by several controllers, like category controller (to display products associated with categories), in best sales controller, new products controller, manufacturer controller, tags controller .... as you can see, a lot of things to change (add,remove etc) fields from $product array you have to modify these controllers. Each controller in a bit different way. in this case, you need to specify about what part of shop you're talking 2 Link to comment Share on other sites More sharing options...
Threef Posted May 6, 2014 Author Share Posted May 6, 2014 Ok, that helps a lot. So all assigning to Smarty needs to go into individual controller of each element. I just made it into CategoryController and it works. Thanks, and have a nice day. Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2014 Share Posted May 6, 2014 that's correct but you probably want to add additional variable to $product array, right? or i missed something ? Link to comment Share on other sites More sharing options...
Threef Posted May 6, 2014 Author Share Posted May 6, 2014 Now everything works great. I'm adding my properties in getProductProperties() function in Product class. Then I can use them in my .tpl files (almost) wherever I'm working on products. Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2014 Share Posted May 6, 2014 that's correct so, my knowledge is useless at the moment, you can change almost everything now Link to comment Share on other sites More sharing options...
calzadilla Posted May 30, 2016 Share Posted May 30, 2016 Hola Vekia, siento escribirte por aquí... en este hilo quiero decir... ya que es en inglés.. si no lo ves correcto dímelo por favor. El tema es que quiero usar el id de la categoría en el product-list.tpl para poder difenciar por categorías.. valga la redundancia, y así mostrar un texto debajo del precio en los productos asignados a esa categoría... lo que pasa es que no se si tengo que pasarle la variable $category al tpl o en la variable $product está contenida alguna como $product.category que pueda usar. Mil gracias de antemano. Y lo dicho. Si no lo ves correcto dímelo y abro hilo o lo que sea. Link to comment Share on other sites More sharing options...
PF22 Posted July 1, 2019 Share Posted July 1, 2019 Sorry to start again that threat but I have the same kind of problem as @Threef. Actually in product-list for each product of a specific category I want to show an audio tag with a specific file to be listened to. So my question is for creating, calculating and passing a variable with the name of the right file, which controller do I have to override ? CategoryController ? Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now