I am trying to add a hook in my custom module but it is not fired after I add a customer both in prestashop backoffice or by using the webservice.
The hook name I am trying to register is "actionCustomerAccountAdd".
This is the relevant code of the module. Please could you help me? I am a PHP developer but it is the first time I develop in Prestashop side.
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
return parent::install()
&& $this->createRequiredDBTables()
&& $this->registerHook('actionCustomerAccountAdd');
}
I have this code to check in logs files or page but it is not fired:
public function hookActionCustomerAccountAdd($params)
{
$this->logger->info('Hook action customer account add fired');
echo 'hook fired';
die();
}
Thank you.
The thing is that hook actionCustomerAccountAdd is fired only on front-office, you will need to use actionObjectCustomerAddAfter, dynamic hook executed in classes/ObjectModel.php
Related
I'm actually developing a payment method module for Prestashop 1.7 but now I'm stuck with the postProcess() method on my payment page, the method is being called immediately when the payment page loads. Do you know why this is happening? My payment.tpl its a simple html form to perform a POST request.
Thanks in advance.
Solved. Its needed a validation because the postProcess runs after init() and before initContent():
public function postProcess()
{
if (!empty($_POST))
{
// Magic here!
}
}
I'm using Prestashop 1.7.6.4. I want to render a template in a hook. I'm doing that via the following code:
class MyModuleName extends PaymentModule
{
public function hookActionValidateOrder($params)
{
/**
* Verify if this module is enabled
*/
if (!$this->active) {
return;
}
if (Configuration::get('inline')) {
$this->context->smarty->assign([
'module' => $order->module
]);
return $this->display(__FILE__,
'views/templates/hook/displayStatusOrder.tpl');
}
// more code goes here
}
}
Do note that I've also tried with
return $this->fetch('module:myModule/views/templates/hook/displayStatusOrder.tpl');
results are the same.
However I'm getting the following error:
(1/1) SmartyException
0():Missing '$template' parameter
I'm absolutely sure that my template exists. And it has the correct name.
My folder structure is like so:
myModuleName
views
templates
hook
displayStatusOrder.tpl
I've tried deleting the cache, reinstalling the module, etc etc.
I'm clearly missing something obvious.
hookActionValidateOrder is an action hook, not a display hook, so you can not display a template.
You need to check in your template where you want to display your code which hooks are available.
I'm developping a module for prestashop 1.7.3 which handle price reductions depending on the cart content. I'm using two hooks (1. displayFidelityProgramCartTop and 2. actionCartSave) and perform actions inside the hookActionCartSave($params) method : depending on the result, I need to refresh the data returned by the first hook.
I use the Hook::exec('displayFidelityProgramCartTop', array()) at the end of the hookActionCartSave($params) method but it seems that the hook isn't executed. The hook is correctly called once, at the initialization. How can I manage to refresh the data returned by the hook (= re-executing the hook to update the template) ?
My code :
cart.tpl
..
{hook h='displayFidelityProgramCartTop' mod='programmeproplus'}
..
programmeproplus.php (main module file)
public function install(){
..
$this->registerHook('displayFidelityProgramCartTop') &&
$this->registerHook('actionCartSave')
..
}
public function hookActionCartSave() {
// Perform some actions ..
Hook::exec('displayFidelityProgramCartTop', array());
}
public function hookDisplayFidelityProgramCartTop(){
// Perform some actions ..
return "<p>List of promotions : ".$promotions."</p>";
}
I am building a custom module in prestashop and I need to execute something after payment accepted and after the emails have been sent. In mymodule.php I have the following hooks:
public function hookActionValidateOrder($params) {
$order = $params['order'];
$customer = $params['customer'];
$valuesToinsert="";
$attrValue=array();
etc...
}
Which is executed normally. I tried actionOrderStatusPostUpdate, actionPaymentConfirmation but none of these seems to be called. I dont know whether it is relevant but I am using opc module and the product is free of charge.
This hook is call when an order is placed after a client confirm his cart. The function that triggers this hook is validateOrder from PaymentModule class. It is call by payment modules when client click en confirm button in checkout. Every payment module should call this function in some moment. But, if you don't have a payment module in your specific process due to free product this hook could maybe be never called.
Anyway, you can subscribe to actionObjectOrderAddAfter hook or similar to get notified when a new order is placed:
public function hookActionObjectOrderAddAfter($params)
{
//$params['object'] contains specific object, in this case your Order object
}
If you need information about order status you could subscribe to hook actionOrderHistoryAddAfter too. Hook actionOrderStatusUpdate is only trigger inside changeIdOrderState function. If for some reason order status change with no call to this function you will miss notification.
Good luck
As you have mentioned in your question that the order you are trying is free, in this case any hook that is called on payment, will never call.
Hence the hooks (i.e. actionOrderStatusPostUpdate, actionPaymentConfirmation, hookActionObjectOrderAddAfter etc.) will never be called as they are called from the PaymentModule.php class and it is not called at all in case of a free order.
Unfortunately, there are no hooks that are called when a free order is placed. In case you want to take any action on a Free order then you can only do that by overriding the FreeOrder class or _checkFreeOrder() function in ParentOrderController.php
Old post, but wanted to drop a comment to help others. This function calls after an order is submitted and they get the confirmation page, whether a payment was submitted with it or not:
public function hookDisplayOrderConfirmation($params) { }
I created custom shipping method for magento. And this method needed only for orders created programmatically from others modules.
Question: How i can to hide this method from checkout form without disabling this method in store settings?
I assume the other modules will use your shipping method from admin context; so you could do something like this:
update your collectRates method like this:
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::app()->getStore()->isAdmin())) {
return false;
}
// rest of your code
This way, you should be able to have the shipping method active but only usable in admin context.