Jump to content

Ordre d'exécution des hooks de paiement


Recommended Posts

Bonjour à tous,

Dans un de mes modules perso, j'ai besoin qu'une action soit exécutée sur le hook hookActionPaymentConfirmation.

Le problème est que mon action est écrasée par le même (ou un autre) hook déclenché par les modules de paiement CB, Paypal...car il semble que leur hooks soit appelés APRES le mien. 

Comment faire pour que le hook de mon module soit appelé en tout dernier ? Comment connaitre tous les hooks concernés par une commande payée et validée et déclencher le mien à la fin ?

Merci de votre aide.

 

 

Link to comment
Share on other sites

 

Comment faire pour que le hook de mon module soit appelé en tout dernier ?

Jouer avec les positions

Comment connaitre tous les hooks concernés par une commande payée et validée et déclencher le mien à la fin ?

c'est très dépendant du moyen de paiement utilisé (différé, immédiat, multiple, ..)

 

Je ne sais pas ce que fait ton module, mais:

- quelle version cibles-tu ?

- de tout les modules de paiement, très peu utilisent hookActionPaymentConfirmation ou hookPaymentConfirm (alias) pour ne pas dire aucun, donc comment pourraient-ils écraser ton traitement?

- les hooks sont exécutés séparément (qu'ils soient les même ou différent), et ne passent pas d'élément les uns aux autres.

- aucune action prestashop n'est atomique. La commande sous-jacente (et ses composants) évolue entre différents hooks

- ton problème semble plus lié à une approche erronée - explique ce que tu cherche à atteindre.

Link to comment
Share on other sites

Bonjour et merci pour ta réponse,

Entre autres mon module doit envoyer un PDF de la commande au fournisseur. Quel que soit le type de paiement. Dès l'instant que la commande passe au statut "paiement accepté". De plus, une fois le mail envoyé, le champ current_state de la table orders doit changer, ainsi que le status de la table order_history.

J'ai testé divers hooks "post commande". Le mail part bien c'est impec. Reste que systématiquement les status_id de la commande ne sont pas ce que je veux, comme si l'action d'un autre hook avait finalement le dernier mot. Dans la table order_history, je vois que mon statut a bien été crée pour la commande, mais le 2 de "paiement accepté" est systématiquement inséré ensuite.

 

Link to comment
Share on other sites

Hook toi sur OrderStatusChange, l'history sera alors remplie.

Mais quand je lis ton use case, je pense qu'il serait bien plus efficace de passer par un cron qui consoliderait toutes les commandes d'une période, ferait le traitement et ensuite mettrait le nouveau statut

Si tu as 2 paiement c'est parce que tu ne laisse pas passer celui avec le drapeau paid. PS ajoute le paiement à chaque fois que l'on passe de unpaid à paid

 

Link to comment
Share on other sites

OrderStatusChange ? Je le vois pas dans les hooks de 1.7.

actionOrderStatusPostUpdate ?

actionOrderStatusUpdate ?

52 minutes ago, doekia said:

Si tu as 2 paiement c'est parce que tu ne laisse pas passer celui avec le drapeau paid. PS ajoute le paiement à chaque fois que l'on passe de unpaid à paid

Euh...je comprends pas...

Link to comment
Share on other sites

Quand tu parle de "drapeau" tu veux parler du status_id ? 2 pour "paiement accepté" etc... ?

Je vais tester le hook actionOrderStatusUpdate parce que oui: j'ai besoin qu'il soit exécuté quand:

1- C'est une commande client avec validation par le module de paiement (CB, Paypal)

2-C'est une validation manuelle par l'admin qui a reçu le paiement (Chèque ou virement)

L'idée que le current_state de la table orders soit modifié (j'ai crée un état avec un ID spécifique) et aussi, bien sûr modifié dans order_history...

Link to comment
Share on other sites

si je fais un tracking des hooks appelé j'ai 

pour une commande passée en front office :

moduleRoutes 
actionDispatcherBefore 
actionDispatcher 
actionFrontControllerAfterInit 
actionFrontControllerSetMedia 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetIDZoneByAddressID 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
actionGetProductPropertiesBefore 
actionObjectAddBefore 
actionObjectOrderAddBefore 
actionObjectAddAfter 
actionObjectOrderAddAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectStockAvailableUpdateBefore 
actionObjectUpdateAfter 
actionObjectStockAvailableUpdateAfter 
actionObjectUpdateBefore 
actionObjectStockAvailableUpdateBefore 
actionObjectUpdateAfter 
actionObjectStockAvailableUpdateAfter 
actionUpdateQuantity 
actionUpdateQuantity 
actionObjectAddBefore 
actionObjectOrderDetailAddBefore 
actionObjectAddAfter 
actionObjectOrderDetailAddAfter 
actionObjectAddBefore 
actionObjectOrderCarrierAddBefore 
actionObjectAddAfter 
actionObjectOrderCarrierAddAfter 
displayProductPriceBlock 
displayProductPriceBlock 
actionValidateOrder 
actionOrderStatusUpdate 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionOrderStatusPostUpdate 
actionObjectAddBefore 
actionObjectOrderHistoryAddBefore 
actionObjectAddAfter 
actionObjectOrderHistoryAddAfter 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionOrderHistoryAddAfter 
actionEmailSendBefore 
sendMailAlterTemplateVars 
actionEmailAddBeforeContent 
actionEmailAddAfterContent 
actionGetExtraMailTemplateVars 
actionEmailSendBefore 
sendMailAlterTemplateVars 
actionEmailAddBeforeContent 
actionEmailAddAfterContent 
actionGetExtraMailTemplateVars 

moduleRoutes 
actionDispatcherBefore 
actionDispatcher 
actionObjectAddBefore 
actionObjectPrestaShopLoggerAddBefore 
actionObjectAddAfter 
actionObjectPrestaShopLoggerAddAfter 
actionFrontControllerAfterInit 
actionFrontControllerSetMedia 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetIDZoneByAddressID 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
overrideMinimalPurchasePrice 
additionalCustomerFormFields 
overrideMinimalPurchasePrice 
filterHtmlContent 
actionBuildFrontEndObject 
displayHeader 
displayOrderConfirmation 
displayPaymentReturn 
DisplayOverrideTemplate 
overrideLayoutTemplate 
overrideLayoutTemplate 
displayAfterBodyOpeningTag 
displayBanner 
displayNav1 
displayNav2 
overrideMinimalPurchasePrice 
displayTop 
displayNavFullWidth 
displayWrapperTop 
displayContentWrapperTop 
displayProductPriceBlock 
displayOrderConfirmation1 
displayOrderConfirmation2 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
actionGetProductPropertiesBefore 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductPriceBlock 
displayProductListReviews 
displayContentWrapperBottom 
displayWrapperBottom 
displayFooterBefore 
displayFooter 
displayMyAccountBlock 
displayFooterAfter 
displayBeforeBodyClosingTag 
actionOutputHTMLBefore 
actionDispatcherAfter 

 

 

 

pour la validation de la commande en back office :

moduleRoutes 
actionDispatcherBefore 
actionDispatcher 
displayBackOfficeHeader 
displayBackOfficeTop 
actionAdminControllerSetMedia 
actionPaymentConfirmation 
actionOrderStatusUpdate 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectConditionUpdateBefore 
actionObjectUpdateAfter 
actionObjectConditionUpdateAfter 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionObjectAddBefore 
actionObjectOrderInvoiceAddBefore 
actionObjectAddAfter 
actionObjectOrderInvoiceAddAfter 
actionObjectUpdateBefore 
actionObjectOrderCarrierUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderCarrierUpdateAfter 
actionSetInvoice 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionObjectAddBefore 
actionObjectOrderPaymentAddBefore 
actionObjectAddAfter 
actionObjectOrderPaymentAddAfter 
actionPaymentCCAdd 
actionOrderStatusPostUpdate 
actionObjectAddBefore 
actionObjectOrderHistoryAddBefore 
actionObjectAddAfter 
actionObjectOrderHistoryAddAfter 
actionObjectUpdateBefore 
actionObjectOrderUpdateBefore 
actionObjectUpdateAfter 
actionObjectOrderUpdateAfter 
actionOrderHistoryAddAfter 
actionPDFInvoiceRender 
actionInvoiceNumberFormatted 
displayPDFInvoice 
displayInvoiceLegalFreeText 
actionEmailSendBefore 
sendMailAlterTemplateVars 
actionEmailAddBeforeContent 
actionEmailAddAfterContent 
actionGetExtraMailTemplateVars 
actionAdminOrdersListingFieldsModifier 
actionGetIDZoneByAddressID 
actionGetProductPropertiesBefore 
actionGetProductPropertiesAfter 
actionDeliveryPriceByWeight 
actionDeliveryPriceByWeight 
displayAdminOrderContentOrder 
displayAdminOrderContentShip 
displayAdminOrderTabOrder 
displayAdminOrderTabShip 
displayInvoice 
displayBackOfficeOrderActions 
actionInvoiceNumberFormatted 
actionInvoiceNumberFormatted 
actionInvoiceNumberFormatted 
displayAdminOrderLeft 
displayAdminOrderRight 
displayAdminOrder 
actionInvoiceNumberFormatted 
actionInvoiceNumberFormatted 
displayAdminView 
displayAdminOrdersView 
displayDashboardTop 
displayAdminNavBarBeforeEnd 
displayAdminAfterHeader 
displayBackOfficeFooter 
actionDispatcherAfter 

moduleRoutes 
actionDispatcherBefore 
actionDispatcher 
displayBackOfficeHeader 
displayBackOfficeTop 
actionAdminControllerSetMedia 
actionAdminBefore 
actionAdminGamificationControllerBefore 

Link to comment
Share on other sites

Sauf que le cerveau de prestashop a le statut_old, statut_new qu'il devrait appliquer, tu lances ton code qui change le statut (avec l'état paid) statut_old, statut_special, là ajout d'un paiement et tu rends la main à prestashop qui compare avec _old et _new et vois passage en paiement, ajout d'un paiement (encore!)

ActionOrderStatusUpdate == OrderStatusChange vois table hook_alias

Tu ne dois pas modifier directement order_history mais faire un new OrderHistory(), addWithMail()

 

Je ne crois pas que tu ais de use case valide pour ne pas faire en cron.

Avantage du cron, pas de dépendant a un service tiers pendant la validation, pas de risque de plantage de la cxreation de la commande, possibilité de reprendre où on veut après un plantage, pas de risque de non atomicité des données vues.

Link to comment
Share on other sites

A Coeos: merci c'est super ! Ces hooks sont exécutés dans cet ordre là ?

A Doekia: effectivement l'idée du cron n'est pas bête, je vais creuser. Tu parles de faire un orderHistory->addWithMail , ok mais ça va renvoyer un mail au client en plus de ceux qu'il a déjà reçus via les modules de paiement classiques ?

Link to comment
Share on other sites

Mail envoyé, si et seulement si tu as associé un mail et son template à ton statut

Par contre tu as l'air de vouloir faire un truc un peu complexe, alors il serait bien que tu lises le code du coeur avant de poser toutes ces questions

 

Link to comment
Share on other sites

  • 4 months later...

Bonjour à tous,

Après avoir lu consciencieusement tous vos posts, vérifié l'ordre des hooks, testé des centaines de fois en local, je reviens sur ce post.

Rappel: j'ai crée un statut de commande particulier( id 23) pour un certain type de commande. Je veux que le order_history et le order current_state soient implémentés avec ce statut.

J'ai testé 3 hooks, en commande admin, avec le statut 2, paiement accepté.

ActionValidateOrder, ActionOrderStatusUpdate et ActionOrderStatusPostUpdate. Voici le bout de code (ne tenez pas compte de $params, c'est OK)

 

		public function hookActionOrderStatusPostUpdate($params){	
			$id_order = $params['id_order'];
			
			if(!empty($params['newOrderStatus'])) {
			$status = $params['newOrderStatus']->id;
			$goodStatuses = array(1,2,9,11);
				
				if(in_array($status, $goodStatuses)){
					
					if($this->OrderOkPourMoi($id_order)){
						
						$order = new Order($id_order);
						$history = new OrderHistory();
						$history->id_order = (int)$id_order;
						$history->changeIdOrderState(23, $order, false);
						$history->addWithemail();
					
					
					}
				}
			}
		}

Et au final, dans order_history j'ai bien mon statut 23 mais toujours avant (donc pas dans le current_state)  le statut 2 paiement accepté.

Et ce quel que soit le hook utilisé parmi les 3.

Pourquoi je peux jamais avoir:

1- paiement accepté N° 2 à 12h00:01

2- mon statut perso N° 23 à 12h01:05

????

Edited by renaud2263 (see edit history)
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...