Gary Host Posted September 10, 2013 Share Posted September 10, 2013 (edited) 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 September 10, 2013 by Gary Host (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted September 10, 2013 Share Posted September 10, 2013 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) 1 Link to comment Share on other sites More sharing options...
Gary Host Posted September 10, 2013 Author Share Posted September 10, 2013 Allright, that sounds good, thanks. Just a question though, what do you mean by "(you need to create own module)" ? Thanks for the quick answer. Link to comment Share on other sites More sharing options...
vekia Posted September 10, 2013 Share Posted September 10, 2013 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 Link to comment Share on other sites More sharing options...
jgullstr Posted September 10, 2013 Share Posted September 10, 2013 (edited) 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 September 10, 2013 by jgullstr (see edit history) 1 Link to comment Share on other sites More sharing options...
vekia Posted September 10, 2013 Share Posted September 10, 2013 yea i totally agree with you, changing controllers isn't good idea, but sometimes override is the only way to achieve something... in this case, module is better solution. Link to comment Share on other sites More sharing options...
Gary Host Posted September 10, 2013 Author Share Posted September 10, 2013 Something I just don't quite understand :What is you call a "hook" ? Link to comment Share on other sites More sharing options...
jgullstr Posted September 10, 2013 Share Posted September 10, 2013 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 Link to comment Share on other sites More sharing options...
vekia Posted September 10, 2013 Share Posted September 10, 2013 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" Link to comment Share on other sites More sharing options...
Gary Host Posted September 11, 2013 Author Share Posted September 11, 2013 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... Link to comment Share on other sites More sharing options...
jgullstr Posted September 11, 2013 Share Posted September 11, 2013 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. Link to comment Share on other sites More sharing options...
Gary Host Posted September 11, 2013 Author Share Posted September 11, 2013 Yes, this is perfect thanks ! Link to comment Share on other sites More sharing options...
Gary Host Posted September 26, 2013 Author Share Posted September 26, 2013 Hi, Coming back to this question, is it possible to access the product ID while in the function initContent(), in the controller OrderConfirmationController ? Link to comment Share on other sites More sharing options...
vekia Posted September 26, 2013 Share Posted September 26, 2013 the question is what produt id from where? from cart? and what if there is several products? Link to comment Share on other sites More sharing options...
Gary Host Posted September 26, 2013 Author Share Posted September 26, 2013 You're right, I just wanna check if one of the products in the cart is a defined product, after the confirmation of the order. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now