Jump to content

How does referencing work from module to core functions?


Recommended Posts

Hi,

 

Just trying to understanding how a newly created module can interact with other components.

 

Simple Example:

In the core template file product.tpl, you can access the product Reference number as such:

{$product->reference}

 

Now, from my new module, what if I want to grab that reference value first, do something to it (inside the module PHP code) and then spit it out on the same template file (under a different name).

 

I guess it's a 2 step process:

1. How to grab ProductController data from inside the new module. (like {$product->reference})

2. How to show a new module based data into an existing .tpl file (such as product.tlp), like {$ModuleNewReference}?

 

Thank you for any tips and hints.

 

 

Link to comment
Share on other sites

1) you have to create new Product object

$product=new Product(Tools::getValue('id_product'));

 

2) modules dont work like that, you have to create module .tpl file.

if you want to use {$moduleNewReference} somewhere in product.tpl you have to alter productController (create this variable there and pass it to smarty array)

Link to comment
Share on other sites

Thanks for the tip Vekia.

 

Can you give me an example regarding point  2?

 

if you want to use {$moduleNewReference} somewhere in product.tpl you have to alter productController (create this variable there and pass it to smarty array)

 

In modifying the ProductController (Or is it best to use override folder for this?), How would you create the variable there and to pass it to smarty array for use in a new module?

 

Is that the proper logic?:

variable created in ProductController > pass variable into smarty array > access the variable through new module to assign a new value > The output can now appear in product.tpl

 

Thank you

Link to comment
Share on other sites

to the initContent() function inside ProductController you have to add new variable to smarty array, something like:

$this->context->smarty->assign(array('$moduleNewReference'=>'value of variable'));

in fact, this is not how the modules works. You can't pass this variable to module core, smarty array is related to template (.tpl files) - not to the php core. if you want to create global variable to use it anywhere you want, you have to define constant, for example in configuration file.

Link to comment
Share on other sites

Thanks for this Vekia,

 

You are right, I'm not using this module thing properly, for my purposes I think simply playing with the php code directly is more to the point and simpler.  After all all I really want to do is create a new variable available from the ProductController, run some php code on it and then posting it in the product.tpl

 

Thanks for all your input.

Link to comment
Share on other sites

×
×
  • Create New...