There are two ways we can get all products a Customer has ordered in SAP Hybris:
- The API
- Creating a FlexibleSearch
Using the API to get all products
This is a psedocode:
- Create an new empty Set to hold the Products
- Get the currentCustomer
- Get the Orders from the Customer object. For each Order:
- Get the OrderEntries. For each OrderEntry
- Get the Products. For each Product
- If the Product is not in the Set we created above, add to it.
- Otherwise go to the next Product
- Get the Products. For each Product
- Get the OrderEntries. For each OrderEntry
As you can tell, this is not a very efficient approach.
To use an efficient approach, look at the following approach:
Using FlexibleSearch to get all products
By using Flexible Query inside our DAO, we can make this process much faster. This is the query that will get the Products:
SELECT DISTINCT {pk} FROM { Product AS p LEFT JOIN OrderEntry AS e ON {e.product} = {p.pk} LEFT JOIN Order AS o ON {e.order} = {o.pk} } WHERE {o.user} = ?user
When executing this query, we would need to pass in the CustomerModel as queryParameter with key “user”
To view all of our posts on SAP Hybris, please click here.
For more information about FlexibleSearch, view the documentations.
0 Comments