Jump to content

How To Query The Database After Payment Witih Smarty/TPL


Recommended Posts

I know how to do the standard SQL query in PHP and echo out the results. 

$query = "SELECT * FROM 'ps_customer' WHERE 'id_customer' ='$WHERE_TO_PULL_FROM'";
$result = mysql_query($query) or die(mysql_error());
while ($row= mysql_fetch_array($result)){
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];

echo out results here...

What I am looking to do is after an order has been placed/paid for, I want to query the database to pull the person's contact and  order information and save it to a file.


Problem I am having with Prestashop (using 1.6) is how do I add this kind of search query on a given page?  I have read several different places to add it to the pages controller file and to the /override/controllers/front folder. 


What should the function/script look like in the controller file and how do I go about echoing that data out? 


Thank you ahead of time for anyone able to help me solve what is becoming a major headache today...


Link to comment
Share on other sites

I see on another post you said the actionValidateOrder does not pull the order# as it is done prior to the order# being generated/assigned.  Why could I not add sql query to say the thank you page that would pull my data instead of going through a building a custom module?

Link to comment
Share on other sites

The Order is created prior to the actionValidateOrder hook being executed, so the order id is available to you.  The order is the second index in the array

// Hook validate order
Hook::exec('actionValidateOrder', array(
    'cart' => $this->context->cart,
    'order' => $order,
    'customer' => $this->context->customer,
    'currency' => $this->context->currency,
    'orderStatus' => $order_status

Perhaps you can provide a link to the topic you are referencing?


Adding SQL code to smarty, or php code in general to smarty templates is a bad design practice.  It is a display tier, not a processing tier.  A module is much more flexible and you won't have to worry about losing your changes when you install or upgrade the theme, or your store.

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