In this step-by-step guide, we'll walk through how to use Xano to build a feature that aggregates the total sales for each product in a company's cart. This is a common requirement for e-commerce applications, and we'll show you how Xano's no-code capabilities can simplify this process.
Before we begin, make sure you have the following:
For this example, we'll use a simplified data model with three tables:
product_id and amount.company_id to filter the results by company.Product table and filter it by the company_id parameter.At this point, you should be able to see the products belonging to a specific company when you test the API endpoint.
To aggregate the sales data for each product, we'll need to use Xano's Add-on feature. Here's how:
In the query builder, click "Create New Add-on" and select the Sales table.
Select "Aggregation" as the add-on type.
In the next step, you'll notice that the product_id and amount fields from the cart array are not available for aggregation. This is because we need to bind the array first.
Click on the add-on in the query builder to open the advanced editor.
Remove the sales_id field from the query and replace it with bind cart.
To make the product_id and amount fields available for aggregation, create two new "evals" by clicking the "+" button next to "Evals." Name one product_id and set it equal to cart.product_id, and name the other amount and set it equal to cart.amount.
Now you can group by product_id and aggregate the amount using the sum function.
Give the add-on a name and save it.
You can now test the API endpoint by providing a company_id. The response should include the products belonging to that company, along with the total sales for each product aggregated from the cart data.
Congratulations! You've successfully built a feature that aggregates sales data for each product in a company's cart using Xano's no-code platform. This is just one example of how Xano can simplify backend development for a wide range of applications.
Whether you're a non-technical user, a citizen developer, or an experienced developer, Xano can help you build and deploy backend services faster and more efficiently. Give it a try and see how it can streamline your development process!
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free