GetRefItems from Json API

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)
User avatar
QuốcTrungNguyễnHoàng
Posts: 4
Joined: 06 Aug 2019, 03:22

GetRefItems from Json API

Post by QuốcTrungNguyễnHoàng » 13 Aug 2019, 10:08

Hi, I'm try to get preview URL for product from JSON API product resource. My Json Reponse here:

Image
How can i map references object Id from Relationship array with object id from Included Array not use loop for every product ?

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

Re: GetRefItems from Json API

Post by aimeos » 13 Aug 2019, 11:54

The jsonapi.org standard doesn't allow to structure the "included" array in advance, so the best way is to loop over the "included" array once at the beginning and create an object tree of

Code: Select all

{
	"<domain>": {
		"<id>": <entry>,
		// ...
	}
}
e.g.

Code: Select all

let map = {};
for( let entry of included ) {
	map[entry['type']][entry['id']] = entry;
}
Afterwards, you can do a quick lookup when iterating over the products.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
QuốcTrungNguyễnHoàng
Posts: 4
Joined: 06 Aug 2019, 03:22

Re: GetRefItems from Json API

Post by QuốcTrungNguyễnHoàng » 14 Aug 2019, 04:41

Thank for your help,
Another problems,
I use Product JSON API Resource with f_catid filter, it not return promotion products in response

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

Re: GetRefItems from Json API

Post by aimeos » 14 Aug 2019, 07:26

Use promotion for f_listtype to get the promotional products of a category
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply