Get products count into cart

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)
traiyani75
Posts: 31
Joined: 08 Nov 2019, 11:56

Get products count into cart

Post by traiyani75 » 11 Feb 2020, 11:14

Hello, we are using laravel apis to connect aimeos into mobile applications.
We need API to get products list count in cart. So we can show count over the cart icon.

Thanks

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

Re: Get products count into cart

Post by aimeos » 12 Feb 2020, 13:08

Use the basket endpoint and count the products in the basket. Thus, you can also display a small basket immediately in the frontend when a user clicks on the icon. To minimize the transfered data, you can add

Code: Select all

include=basket/product
to retrieve the products but not the address and service items and you can use

Code: Select all

fields[basket]=order.base.price&fields[basket/product]=order.base.product.name,order.base.product.mediaurl,order.base.product.price
to limit the fields sent to the client
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

traiyani75
Posts: 31
Joined: 08 Nov 2019, 11:56

Re: Get products count into cart

Post by traiyani75 » 15 Feb 2020, 07:38

I have tried this api, but it returning all data every time.
{base-url}/default/jsonapi/basket?include=basket/product

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

Re: Get products count into cart

Post by aimeos » 16 Feb 2020, 09:19

Sorry, forgot the "include" parameter and there was a problem filtering related basket fields. Please run "composer update" and use an URL like that:

Code: Select all

http://127.0.0.1:8000/jsonapi/basket?included=basket/product&fields[basket]=order.base.price&fields[basket/product]=order.base.product.name,order.base.product.mediaurl,order.base.product.price
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

traiyani75
Posts: 31
Joined: 08 Nov 2019, 11:56

Re: Get products count into cart

Post by traiyani75 » 25 Feb 2020, 11:50

It only filters products from the basket, But still, it returns all data into products object

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

Re: Get products count into cart

Post by aimeos » 26 Feb 2020, 08:44

Did you run "composer update"? Both, 2019.10.4 and dev-master only return the fields mentioned in the "fields[basket/product]" parameter:

Code: Select all

aimeos/ai-client-jsonapi              2019.10.4             Aimeos JSON API extension
aimeos/ai-client-jsonapi              dev-master 6dd20da Aimeos JSON API extension
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply