freuxbang Posted February 6, 2015 Share Posted February 6, 2015 Hi, I need to call in "shopping-cart-product-line.tpl" the value that returns a function located within a module. What should I write in the file "shopping-cart-product-line.tpl"? Name module: Pippo /modules/Pippo/controllers/front/actions.php public function pipposhow() { $pipposhow= 2; echo $pipposhow ; } /themes/mytheme/shopping-cart-product-line.tpl I want to draw the function result pipposhow thank you Link to comment Share on other sites More sharing options...
zombie process Posted February 7, 2015 Share Posted February 7, 2015 assign it to smarty. Link to comment Share on other sites More sharing options...
freuxbang Posted February 8, 2015 Author Share Posted February 8, 2015 Thank you for responding Could you show me how to assign the module smarty? What should I write inside the module Pippo? /modules/Pippo/controllers/front/actions.php public function pipposhow() { $pipposhow= 2; echo $pipposhow ; } /modules/Pippo/pippo.php Here I have to assign the variable smarty? /themes/mytheme/shopping-cart-product-line.tpl I want to draw the function result pipposhow you kindly tell me what to put in these files? thank you Link to comment Share on other sites More sharing options...
zombie process Posted February 8, 2015 Share Posted February 8, 2015 (edited) You don't assign a module to smarty, you assign a variable. In the pipposhow method: public function pipposhow() { $pipposhow= 2; $this->context->smarty->assign('pipposhow', $pipposhow) ; } Then you invoke the variable in the tpl: {if isset($pipposhow)}{$pipposow|intval}{/if} That said, you'd better, in this case, transfer the logic (ie the piposhow method) to the module itself (ie not a module controller) and make it a hook that you can invoke from the shopping-cart-product-line.tpl. Modify your module's constructor in order to register a new hook (pippoShow, for instance). And put the hook method: public function hookPippoShow() { $pipposhow= 2; return $pipposhow; } or public function hookPippoShow() { $pipposhow= 2; $this->context->smarty->assign('pipposhow', $pipposhow) ; return $this->display(__FILE__, 'pipposhow.tpl') } which is probably better if you decide to have a more elaborate display in mind. Reinitialise your module. Then call the hook directly from the shopping-cart-product-line template: {hook h='pippoShow' mod='Pippo'} Edited February 8, 2015 by zombie process (see edit history) Link to comment Share on other sites More sharing options...
freuxbang Posted February 8, 2015 Author Share Posted February 8, 2015 (edited) Thank You I tried to enter the code as you suggested, but I can not get the tick value $pipposhow in shopping-cart-product-line.tpl What I do is this /modules/pippo/pippo.php public function hookPipposhow() { $pipposhow= 2; $this->context->smarty->assign('pipposhow', $pipposhow) ; return $this->display(__FILE__, 'pipposhow.tpl') } Then I go on shopping-cart-product-line.tpl and insert {hook h='pipposhow' mod='pippo'} But I do not check any value... Edited February 8, 2015 by freuxbang (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted February 8, 2015 Share Posted February 8, 2015 Have you register that hook in install method with $this->registerHook('pipposhow') and in back office Module > Positions do you see module "hooked" there ? Link to comment Share on other sites More sharing options...
zombie process Posted February 8, 2015 Share Posted February 8, 2015 Check that the hook has been properly registered. Be sure to include the registerhook call in the module's install method (ie function). Remember that your value is to be used in the pipposhow.tpl that you have to place in your module's views/hook directory. pipposhow.tpl could be like {l s='Pippo show value:' mod='pippo'} {if isset($pipposhow)}{$pipposhow|intval}{/if} the output is then injected into shopping-cart-product-line Link to comment Share on other sites More sharing options...
freuxbang Posted February 10, 2015 Author Share Posted February 10, 2015 (edited) Ok thanks, I was able to check the value, what I was missing was the part of the installation of the block. I realized, however, that using this system can not be printed for each line of the cart a different value. On shopping-cart-product-line I added: {hook h='pipposhow' mod='pippo'} I attach a picture to help you understand On each line of product I always print the contents of pipposhow.tpl How should I do to print a different value on each line of the product? Edited February 10, 2015 by freuxbang (see edit history) Link to comment Share on other sites More sharing options...
zombie process Posted February 10, 2015 Share Posted February 10, 2015 What is the value (or, more generally, the type of data) you want to output? On what is it based? If it's, for instance, based on the product, you can pass the product (or whatever variable you want) as parameter: {hook h='pipposhow' mod='pippo' product=$product othervar=varvalue} In your hook code, you can retrieve the product like so: $product = $params['product'] don't forget, though, to add the $params parameter to the definition of the hook method: public function hookPipposhow($params) { $product = $params['product']; $othervar = $params['othervar']; your code } Link to comment Share on other sites More sharing options...
freuxbang Posted February 10, 2015 Author Share Posted February 10, 2015 Do not think I've got it right. Let me give an example of what I want to achieve. I have on my cart 2 products ID Prodotto1 = 22ID Prodotto2 = 262 This is what I put on pippo.php public function hookPipposhow($params){ $products = $this->context->cart->getProducts(); foreach ($products as $key => $val ) { $id_product = $products[$key]['id_product'] ; $this->context->smarty->assign( array('id_product' => $id_product)); } return $this->display(__FILE__, 'pipposhow.tpl'); } I put this on pipposhow.tpl {$id_product} I put this on shopping-cart-product-line.tpl {hook h=‘pipposhow’ mod=‘pippo’} The result is this: I would like famished this: Obviously this is an example, actually I should check to other values. Link to comment Share on other sites More sharing options...
zombie process Posted February 10, 2015 Share Posted February 10, 2015 You don't have to get the cart products each time because you already have them (the hook is invoked from the shopping-cart-product-line and the cart's products have already been assigned to smarty). You just need a reference to the current product being displayed. {hook h='pipposhow' mod='pippo' product=$product} public function hookPipposhow($params){ $product = $params['product']; $this->context->smarty->assign(array('id_product' => $product['id_product'])); return $this->display(__FILE__, 'pipposhow.tpl'); } 1 Link to comment Share on other sites More sharing options...
freuxbang Posted February 10, 2015 Author Share Posted February 10, 2015 Exactly what I wanted. I'm working on a project and I think I will open other topik. :D Thank you so much you have been very kind And forgive me for my poor english. Link to comment Share on other sites More sharing options...
PF22 Posted June 26, 2019 Share Posted June 26, 2019 On 2/8/2015 at 8:23 PM, razaro said: Have you register that hook in install method with $this->registerHook('pipposhow') and in back office Module > Positions do you see module "hooked" there ? Hi there. I tried those modification because I have the same kind of need, but I can't see the new Hook I created in my module... I have a module and in the install function I added !$this->registerHook('ecoute') so below I added that code public function hookEcoute() { $ecoute=2; $this->context->smarty->assign('ecoute', $ecoute) ; return $this->display(__FILE__, 'ecoute.tpl'); } and then create an ecoute.tpl file. in the end I can't see the new hook, in modules/positions, and I can't show $ecoute value in product-list.tpl where I call {hook h='ecoute' mod='homefeatured'} ... any help is welcome! Link to comment Share on other sites More sharing options...
razaro Posted June 26, 2019 Share Posted June 26, 2019 Hi @Pat_07 This code was for an older version of PrestaShop it may not work in the latest 1.7. But check modules/positions and check to display all hooks. And your module is called homefeatured ? If not try to use your module name in {hook h='ecoute' mod='homefeatured'} Link to comment Share on other sites More sharing options...
PF22 Posted June 26, 2019 Share Posted June 26, 2019 Thank you @razaro. Ideed it is about 1.6 PRestatshop... Link to comment Share on other sites More sharing options...
PF22 Posted June 27, 2019 Share Posted June 27, 2019 On 2/8/2015 at 10:46 PM, zombie process said: pipposhow.tpl could be like {l s='Pippo show value:' mod='pippo'} {if isset($pipposhow)}{$pipposhow|intval}{/if} I have the same kind of problem but with an array. so what should $pipposhow|intval become ? $pipposhow|array ? 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