Jump to content

How to place php code (select, insert, etc) within the. Tpl theme

Recommended Posts

I wonder how I can do to show in the "product details" (product.tpl) for example, data from another DB.

I tried to put {php} {/ php} but does not work, I tried to put an include but not good either, I tried to call. Php in the header.php Prestashop and store the result into variables, and have even tried to call a. tpl thinking that this would open before the show of the same name. php does not work in any way.

Anyway, I am desperate because I find no way to put PHP code within. Tpl is very important, I'm working with 1.3.7 because the 1.4 could not even put {php}

Any ideas?

Thank you very much.


Link to comment
Share on other sites

Ok, I understand, but if I want to show 1 data in a table id Prestashop according to the product in product-list.php, as I get 1, go to the file. Php (codigo.php) and how do I save variables and can use them.

Moreover, as I get if you run a SELECT like: "SELECT * FROM ... WHERE id = $ product.id_product" ... that is, how do I call from my file id_product. Php

Thank you very much for your answer, but you did not know how to do it correctly.

A Saud.

Link to comment
Share on other sites

Ok, then I say what I mean if you can throw me a cable:

- Here there must appear, the number of comments that there are (hyperlinked to the product details)
- The average valuation of output showing the total ratings (hyperlink to the product sheet).
- The different retailers selling the product (Example shows an Acer Computer Model A1, the computer is sold in Prestashop but from different vendors, one of 600 € to 650 € and another, since the name is the same, I would like to ALL show retailers selling this product, price, and hyperlinked to the corresponding product sheet).

- Aque must also appears as to whether there are different dealers selling the product, showing a kind of table with the logos of distributors, name and price.

Supplier.tpl and manufacturer
- Here I display the logo, description and a section of "valuation" and "comments" (the same style of valuation used in the product details and comments).

As you can see except the last thing that is very important and not as I will have to do, the rest is not that complicated doing with PHP code and wondered how to do that, however, if someone could help me to put the code otherwise and place it as a contribution to the Forum that works for most people the truth would be appreciated.

Thank you very much for everything.


Link to comment
Share on other sites

As Dapur mentioned, you need to edit the Controller (Product, Category, etc) and add you PHP code there, then assign the value to the tpl file

For example, /controllers/ProductController.php

   public function process()
       global $cart;

       if (!$id_product = (int)(Tools::getValue('id_product')) OR !Validate::isUnsignedId($id_product))
           $this->errors[] = Tools::displayError('Product not found');
           if (!Validate::isLoadedObject($this->product)
               OR (!$this->product->active AND (Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct'.$this->product->id))
               || !file_exists(dirname(__FILE__).'/../'.Tools::getValue('ad').'/ajax.php')))
               header('HTTP/1.1 404 page not found');
               $this->errors[] = Tools::displayError('Pproduct is no longer available.');
           elseif (!$this->product->checkAccess((int)(self::$cookie->id_customer)))
               $this->errors[] = Tools::displayError('You do not have access to this product.');
                           // Add you php code here, for example create a manufacturer list
                           $manufacturer_array = array(.....);
                           // Now assign it as a smarty variable
                           self::$smarty->assign('manufacturer_array_tpl',$manufacturer_array );

You need to populate $manufacturer_array with the values you wish, and it will be available in product.tpl as $manufacturer_array_tpl

Link to comment
Share on other sites

  • 2 weeks later...

I finally got to put the code. Php without problems. Tpl, however, I want to get other data from the DB and I want to be shown on list.tpl product-testing it need to use (if I'm wrong) file: CategoryControllers.php, the problem is that code. php place it there and I want to consult according to the product ID, so you do not know how to do it since there can not be obtained because it is changing.


For example, as if to put the number of comments on the product in the product list.


Any ideas or suggestions?


Had thought to put that code in an external page, and put an iframe, but of course, remain something wrong.


A greeting and thanks.

Link to comment
Share on other sites

ok now the first sync with update function runs over 372 sata hdds ;) when all works fine with the first 3000 products ill zip all my work.


ill know thats the code not optimized at this moment but ill think it helps u all. self the html details from ingram ill get now ;) when ingram have html details.


when u want take a look, then look here : http://www.multimedia-webshop.de/30-sata

Link to comment
Share on other sites

  • 1 year later...

Here is very simple example put the PHP code manually and read it on tpl


php file:


$var='welcome'; // php variable declaration

global $smarty;

$smarty--->assign('intro', $var); // or $smarty->assign('intro', 'welcome');

// now smarty variable 'intro' holds the value 'welcome'



on tpl file (for example 'header.tpl'):


{$intro} to our shop!


output: welcome to our shop


Note: be sure of put the code if u r create new file u should hav knowledge where to store. or otherwise just try it on 'Product.php' and tpl file should be any product page's tpl

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