Without having a deeper insight into the exact way you have your data structured this would be my high level approach.
Everything looks good up until step 5, by calling and returning your data via the API connector, you have the opportunity to essentially structure it any way you’d like. That would include modifying the returned data.
On Step 5. I would suggest having a ‘return data from API’ action. Inside of this you can specify a JSON schema which you can build from the response from Algolia. What is nice here, is that you can modify the price based on the Brand, and calculate the new price all without having to do a recursive workflow.
Below is an example of how I’m using the return data from API action.
In my example I’m returning an list of objects which consist of form IDs and form names, when called from the API connector, it allows me to map the data nicely so I can use it in my front-end as a list of things.
What I would try on your end is having your data source something like
[Result of Step X Algolia Search :formatted as text]
Then within your :formatted as text you can structure exactly how you’d like your product object to appear to the front-end. When you get to the price key value pair, this is where you would contain the logic to change the price based on the brand.
Do you know what the data looks like when it comes from Algolia? If the Brand is just a textthen it does change things, if it’s recognized as a database thing from bubble (your Brand table) then it’s a bit simpler.
If it’s recognized as a database object:
"Price”: This Product’s Brand: converted to list: intersect with User’s Discount’s: each item’s Brand: first item’s Discount: defaulting to 1 * This Product’s Price
What this logic is doing is it’s looking at your Brand object (derived from the Algolia product), and it’s converting that object into a list (only 1 thing), then it’s comparing your Brand list and User Discount Brand’s List and returning any values that appear in both lists. If it does, it returns the corresponding matching Brands (in this case it would be only 1 brand), we then return the discount percentage (Assuming it’s a decimal), otherwise it returns 1 if there is no Brand returned. It then multiplies that number by the Product Price (returned from Algolia).
This way you either get a discount if the user has a discount for that Brand, or they see the original price. The reason for this strange logic is that bubble doesn’t allow us to fetch the ‘This Product’s Brand’ within an additional nested ‘Formatted as text’ or ‘filtered’ modifiers which we’d need, so I resorted to doing everything in one statement.
Not sure if this helps but if you provide more info on how the data from Algolia comes back you can message me. Not sure if I totally understood what you were trying to do, however with this workflow you can filter down the results based on the total price.