I'm having an issue with this plugin. If changes are made to an order status and no cart is present, it throws an error about trying to get the property of a non-object.
How to reproduce?
Place an order as you normally would
Find said order in the backoffice
Change the status
Error is thrown
[Symfony\Component\Debug\Exception\ContextErrorException code 0]: Notice: Trying to get property 'id_lang' of non-object
I've traced it back to the hookActionOrderHistoryAddAfter method of trustpilot.php.
The code expects $params['cart'] to be present, but it is not.
I have only worked with Prestashop for a short time, but as far as I can tell, the following code should resolve the issue by first checking if the cart is present in the event, and if it is not, then use the id_lang of the order associated with the order history.
public function hookActionOrderHistoryAddAfter($params)
{
$id_lang = $params['cart'] ?
$params['cart']->id_lang :
(new Order($params['order_history']->id_order))->id_lang;
$newOrderStatus = new OrderState((int) $params['order_history']->id_order_state, (int) $id_lang);
$transformedParams = array('newOrderStatus' => $newOrderStatus, 'id_order' => $params['order_history']->id_order);
$this->sendBackendInvitation($transformedParams, 'actionOrderHistoryAddAfter');
}
I have not submitted a PR since I'm not sure if this is the best solution.
Hi,
I'm having an issue with this plugin. If changes are made to an order status and no cart is present, it throws an error about trying to get the property of a non-object.
How to reproduce?
Error is thrown
I've traced it back to the
hookActionOrderHistoryAddAfter
method oftrustpilot.php
. The code expects$params['cart']
to be present, but it is not.I have only worked with Prestashop for a short time, but as far as I can tell, the following code should resolve the issue by first checking if the cart is present in the event, and if it is not, then use the
id_lang
of the order associated with the order history.I have not submitted a PR since I'm not sure if this is the best solution.