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)
Spam and unrelated posts will be removed immediately!
User avatar
QuốcTrungNguyễnHoàng
Posts: 14
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: 7866
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: 14
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: 7866
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

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

Re: GetRefItems from Json API

Post by QuốcTrungNguyễnHoàng » 17 Sep 2019, 08:44

I have some change from product category. But products retrieve from JSON api still not change, but products retrieve from MShop Product Class changed. It look like Json API get old categoryID of product. How can i fixed it? Tks very much.
Sorry for my bad English.

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

Re: GetRefItems from Json API

Post by aimeos » 17 Sep 2019, 08:47

Keep you index tables up to date and rebuild the product index using the "index/rebuild" job controller.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply