I want to get the list of products from the order within the hook actionObjectOrderAddAfter however the function $order->getProducts() returns an empty array. Calling the same function from a different hook (for example hookAdminOrder) works fine. What am I missing? Thanks
public function hookActionObjectOrderAddAfter($params)
{
$order_id = $params['object']->id;
$order = new Order((int) $order_id);
$products = $order->getProducts()
/*
...
*/
}
Ok, I figured it out. In this hook you need to get the products from the cart - not from the order itself.
public function hookActionObjectOrderAddAfter($params)
{
$order_id = $params['object']->id;
$order = new Order((int) $order_id);
$cart = new Cart((int) $order->id_cart);
$products = $cart->getProducts()
/*
...
*/
}