We would like to get the order collection of a customer in his/her account, but then filtered on product SKU. So not just all orders and display the SKU’, but bundle all orders based on the SKU, so we do not get duplicate values.
And than also count the total ordered qty of those SKU’s by the customer. We also need to use the pager, so the page only load the first 10 items.
And then we need to load it in the opposite direction, so from the sku we need all the related orders in a foreach with order id.
So we need it in the opposite direction of the default function.
How can we achieve this?
Current code:
public function getOrders()
{
if (!($customerId = $this->_customerSession->getCustomerId())) {
return false;
}
if (!$this->orders) {
$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
'*'
)->addFieldToFilter(
'status',
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
)->setOrder(
'created_at',
'desc'
);
}
return $this->orders;
}