Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on hookActionOrderHistoryAddAfter if no cart is present #5

Open
esbenboye opened this issue Mar 9, 2021 · 0 comments
Open

Error on hookActionOrderHistoryAddAfter if no cart is present #5

esbenboye opened this issue Mar 9, 2021 · 0 comments

Comments

@esbenboye
Copy link

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?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant