Rest api to get related products

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
traiyani75
Advanced
Posts: 114
Joined: 08 Nov 2019, 11:56

Rest api to get related products

Post by traiyani75 » 28 Nov 2019, 12:51

Hello,

We are using aimeos rest apis into a mobile application for android and ios. We want to show related products with product details.
We have checked that in admin we have a feature to add similar products, But we have an issue in that.

Like in case, we need to show only 4-5 related products with the current one and if there are more products then we need to show "show more" options. How do we achieve this using rest apis.

Regards
Tejas

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Rest api to get related products

Post by aimeos » 29 Nov 2019, 12:04

You can only retrieve all related products for a product using "/jsonapi/product/<id>?include=product" because the JSON:API standard doesn't support limiting related resources. Thus, you should use it mainly at the product detail page where only the current product with its related products is shown and the list of related products shouldn't be exessive. If the user clicks on "show more", you can display the remaining related products immediately without delay.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

traiyani75
Advanced
Posts: 114
Joined: 08 Nov 2019, 11:56

Re: Rest api to get related products

Post by traiyani75 » 30 Nov 2019, 06:42

If we call API to get related products using product id, and we have related products about 30+ in counts.
So, do we have an API call to get the number of related products and also does that API will give pagination support? ?

traiyani75
Advanced
Posts: 114
Joined: 08 Nov 2019, 11:56

Re: Rest api to get related products

Post by traiyani75 » 30 Nov 2019, 12:50

Hello, Along with this, if we will have 100+ similar products with one product then how can we get all those in the list that instead of manually add-in admin? Even, In admin, we need to add the product into a similar list on both sides which is also time-consuming.

Can we have any way to show all products into a similar list that belongs to the same subcategory or category?

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Rest api to get related products

Post by aimeos » 30 Nov 2019, 18:52

If you don't want to show really related products but products from the same category, then use the product endpoint with the f_catid parameter. Then, you also have pagination and counts and don't need to populate the related products.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

traiyani75
Advanced
Posts: 114
Joined: 08 Nov 2019, 11:56

Re: Rest api to get related products

Post by traiyani75 » 04 Dec 2019, 08:02

Now, In product details, we used this API
{product_url}?id=18&include=attribute,media,price,product/property,text

Using the above API, we are getting a response but we also need to return catalog details into the response. Like product belongs to which catalog. How do we achieve that thing?
We need catalog id because we are showing related products in the bottom of the product details screen

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Rest api to get related products

Post by aimeos » 04 Dec 2019, 16:27

If the customer viewed the product list from the category, you know the category ID and can pass it as f_catid value.

If you need the categories the product is included in, you can retrieve them using the catalog endpoint and the "catalog:has" search function:

Code: Select all

.../catalog?filter[!=][catalog:has("product","default",<prodid>)]=
Afterwards, you can use the product endpoint to fetch the paginated product list using the "f_catid" parameter.

For this, you need:

Code: Select all

composer req aimeos/ai-controller-frontend:2019.10.x-dev aimeos/ai-client-jsonapi:2019.10.x-dev
In dev-master, there's already code available to get the categories directly along with the products.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

traiyani75
Advanced
Posts: 114
Joined: 08 Nov 2019, 11:56

Re: Rest api to get related products

Post by traiyani75 » 28 Dec 2019, 12:27

How do I get the catalog into product details directly? We want to open product details via notification and same time we will need to show related products too. So, We need to return catalog id into product details api too.

Also, there are some cases where the product list doesn't have catalog id. So, that time also when clicking on a product from the list, we need catalog id to have into the response.

How do I get catalog id direct from product details api?
Like for example api end point: {BASE_URL}/product?id=28&include=attribute,media,price,product,product/property,text

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Rest api to get related products

Post by aimeos » 29 Dec 2019, 10:08

The product endpoint doesn't return the categories by default. You need to extend the JsonApi endpoint to fetch the categories for the products and add them to the response in the template:
- https://github.com/aimeos/ai-client-jso ... d.php#L315
- https://github.com/aimeos/ai-client-jso ... #L106-L133
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply