Jump to content

Email notifications to customer via webservice updates to an order not working


tehy

Recommended Posts

Hi!

 

The store (Prestashop version 1.5.4.0, it's a client's store so can't update it myself or anything like that) is setup so that if shipping method X is used, an email notification is sent to the customer when a tracking code is added. If shipping method Y is used, the notification is sent when the order is put into a certain state (a variation of the SHIPPED state).

 

Neither of these notifications happen if the update is done via the webservice. The tracking code is added by adding the tracking code via order_carriers of the order and the order status is changed via order_history (which also changes the current_state of the order object). To my knowledge these are the correct ways to do these changes.

 

I know of the sendemail=1 addition to the resource. I'm using the webservice directly via PHP's cURL, as the Prestashop Webservice Library causes gray hairs. As such the URL of the order_history for example is: www.storeurl.com/api/order_histories?sendemail=1 but it still doesn't work. I also added that to the tracking code addition URL, though I don't even know if it is supposed to work with that call exactly like that.

 

So, while everything else works, the email notifications via webservice updates do not. What could I do to get this to work?

Link to comment
Share on other sites

  • 2 weeks later...

In PS v1.5.4.1 (and I assume v1.5.4.0), the "in_transit" email is sent by the "AdminOrdersController" postProcess function.  It does this when the tracking number is added via the order detail page in the back office.

 

Specifically, the code updates the order->shipping_number and the order_carrier->tracking_number records.

 

It then executes the "actionAdminOrdersTrackingNumberUpdate" hook.

 

It appears to do this for all orders and for all carriers regardless of the orders status.

 

So I suspect changes have been made to this store to support carriers X and Y.  So can you be more specific about changes you have made to Prestashop to support these features?

 

Now regarding the webservice API, I suspect the issue is that the webservice API does not invoke that hook "actionAdminOrdersTrackingNumberUpdate", and obviously does not invoke AdminOrdersController postProcess function.  Searching the codebase for 'tracking_number' also does not result in anything that would suggest an email would be sent using the API.

 

So unfortunately I think you would need to trace the webservice API code and locate the best place to either

1) add custom code to perform the task

2) execute the actionAdminOrdersTrackingNumberUpdate hook, and then you can develop a module that registers this hook and performs the task

Link to comment
Share on other sites

Thanks for the reply.

 

Strange part is that the sendemail=1 addition seems to have worked for some people when adding an order history event, but I wonder why it does nothing in this case.

 

The carriers X and Y are just normal shipping methods really, it's just that they have specific states the orders are set to depending on the selected carrier. Also accordingly carrier Y is a method that never has a tracking code as defined by the shop owner's internal process, so while technically giving it one via the back office would send the email, it's never added.

 

It just would've been nice to have simple solution for this. It wouldn't be too hard to send a mail from the script that accesses the webservice, except for the part where Prestashop automatically sends the mail in the correct language and so forth.

Link to comment
Share on other sites

  • 6 months later...

I found a way to make it work in Prestashop 1.4.5.1

Just create /override/classes/OrderHistory.php

<?php
	// on étend la classe OrderHistory pour pouvoir modifier les paramètres WebService et faire en sorte que les mails soient envoyés.
	
class OrderHistory extends OrderHistoryCore
{

	function __construct()
	{
		$this->webserviceParameters['objectMethods'] = array('add' => 'addWithemail');
	}
}
?>

You need to do that because by default, the orderHistory class doesn't specify the objectMethods parameters.

So the webService classe uses the default add() method to save the order history, and not the saveWithemail() method.

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