Jump to content

PHP function launched at each purchase


Gary Host
 Share

Recommended Posts

Hi guys,

 

I need a little help, regarding the development of several scripts in my Prestashop module.

 

I have a PHP script, that needs to be launched at each purchase. In which file do I need to put it, to be able to get the purchase detailes (I need the item number) once the purchase is done ?

 

Thank you very much, have a good day.

 

EDIT : I've seen a "order-confirmation.php" file, is this it ? If yes, how do I get the purchase information and the user info ? Thank you !

Edited by Gary Host (see edit history)

Share this post


Link to post
Share on other sites

you can do it with module (you need to create own module) or with modification of the controller.

 

second method

open file controllers/front/OrderConfirmationController.php

 

you've got there function:

public function initContent()
	{
		parent::initContent();

		$this->context->smarty->assign(array(
			'is_guest' => $this->context->customer->is_guest,
			'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
			'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()
		));

		if ($this->context->customer->is_guest)
		{
			$this->context->smarty->assign(array(
				'id_order' => $this->id_order,
				'reference_order' => $this->reference,
				'id_order_formatted' => sprintf('#%06d', $this->id_order),
				'email' => $this->context->customer->email
			));
			/* If guest we clear the cookie for security reason */
			$this->context->customer->mylogout();
		}

		$this->setTemplate(_PS_THEME_DIR_.'order-confirmation.tpl');
	}

and you can modify this function to run script you want

 

customer data you have in $this->context->customer variable (this is object)

  • Like 1

Share this post


Link to post
Share on other sites

there is two ways to achieve what you want

 

1) own module

2) modification of the controller

 

by "you need to create own module" I mean that you can create own module to run own php code while order is confirmed. 

To do this - in module you have to use use "orderConfirmation" hook

Share this post


Link to post
Share on other sites

I wouldn't recommend editing controllers to achieve functionality you can get by using available hooks, esp if you're developing several scripts. If you're not familiar with creating custom modules I suggest you read
 

http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module

The hook you're looking for in this case is, as vekia pointed out, displayOrderConfirmation.

Edited by jgullstr (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

All the information you need is available at the page i linked to earlier;

Any PrestaShop module, once installed on an online shop, can interact with one or more "hooks". Hooks enable you to "hook" your code to the current View at the time of the code parsing (i.e., when displaying the cart or the product sheet, when displaying the current stock...). Specifically, a hook is a shortcut to the various methods available from the Module object, as assigned to that hook.

http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Technicalprinciplesbehindamodule

Share this post


Link to post
Share on other sites

hook is a place or "action" where you can attach modules and run any code you want.

it mean, that prestashop has got hook named "orderConfirmation" and it is executed right after order confirmation.

 

with module you can run any code you want in this "hook"

Share this post


Link to post
Share on other sites

Allright, thanks guys.

 

Other question : Which controller handles the user creation and edition ? Because I need to sync the user database of my prestashop with another website...

 

Assuming you mean customers, you could override the add() and update() methods of the Customer class.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More