Jump to content

How to create a new button/tpl for all product pages


aliocha07

Recommended Posts

Hello guys,

 

I'm new to Prestashop (only started 10 days ago), so please bear with me :)

 

I have to call an external module through a button (or a link) that would be added to my product page(for all products).

 

1) A php code snipped builds the url, with various variables (like token, product_image, product_image_path etc)

2) then the built url is sent to the module which opens a new page and does the appropriate treatment.

 

3) I've already coded the php snippet buiding the url and the html code for the button.

 

And my problem is: how to integrate them?

 

For the html, I've already saw some suggestions to add the code to the product.tpl of my theme, but I'm reluctant to do so because it would imply some maintenance each time there would be an upgrading of the theme.

 

For the php, I just don't know where to put it and how to make sure the code will be called by the button.

 

Furthermore, since I'm calling Prestashop classes in it (like Tools), I'm not sure what to include at the beginning of the file.

 

Any further help to this beginner would be greatly appreciated.

 

Thank you very much in advance.

Link to comment
Share on other sites

 

 

For the html, I've already saw some suggestions to add the code to the product.tpl of my theme, but I'm reluctant to do so because it would imply some maintenance each time there would be an upgrading of the theme.

 

there is no other way to insert this button easily. why not this method?

  • Like 1
Link to comment
Share on other sites

Create a module and register one of these hooks:

 

http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5

 

  • displayProductButtons
  • displayFooterProduct
  • displayLeftColumnProduct
  • displayProductTab

Then you can do it from a module and not a theme. Your module install() method would have something like this:

$this->registerHook('displayProductButtons');

And then would need to add a method to the module like this:

public function hookDisplayProductButtons($params) {
    return "Test";
}
Edited by krisives (see edit history)
  • Like 1
Link to comment
Share on other sites

I'm very grateful for your answers and your will to help. I've read so many things the past 3 days - on smarty and all - that your guidance is really precious to me.

 

To krisives:

I suppose your post answers to my reluctance to change anything within the theme, in case my client upgrades it. I also thought it was the only way and may do it after I try implementing it the other way (including the button directly in product.tpl - which would probably go quicker).

Thanks a lot for the advice on the hooks I should use though. Though I fairly understood their use, I'm too much of a young Prestashop user to have understood all the differences yet.

 

To vekia:

I suppose krisives's post answers the question

 

To both of you:

For the moment, I'm opting for a 'quick fix' because I may run into other problems with this external module later on (it's a virtual mirror for glasses)

 

Re: my php code:

 

What it does is only build an url with variables and many of them are already available and accessible in the template itself:

 

Here are the variables I need:

 

Available in the template:

 

frameName = product name - given by: {$product->name}

frameFile = image name -given by:  {$cover.id_image}-medium_default.jpg

frameLoc = image location - partially given by: {$link->getImageLink($product->link_rewrite, $cover.id_image, 'medium_default')},

partially because this parameter must include the complete path without the image file name, so I may have to treat the resulting string.

 

Not available:

 

session_id, which from what I read is not used in Prestashop, so I may have to define a php sesssion cookie to get the session id.

 

Now this imply that I may probably not be able to 'do it all' within the .tpl, since the {php} tag is depreciated in Smarty 3.0, so my questions are:

 

- Should I add a php function to the ProductController (as I did to display ajax for instance)?

- Should I assign my variables within product.tpl?

 

Thank you very much for your guidance and help. Fact is, I just need a roadmap :) to implement this button without a module..
 

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