Page 1 of 1

GetRefItems from Json API

Posted: 13 Aug 2019, 10:08
by QuốcTrungNguyễnHoàng
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 ?

Re: GetRefItems from Json API

Posted: 13 Aug 2019, 11:54
by aimeos
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.

Re: GetRefItems from Json API

Posted: 14 Aug 2019, 04:41
by QuốcTrungNguyễnHoàng
Thank for your help,
Another problems,
I use Product JSON API Resource with f_catid filter, it not return promotion products in response

Re: GetRefItems from Json API

Posted: 14 Aug 2019, 07:26
by aimeos
Use promotion for f_listtype to get the promotional products of a category

Re: GetRefItems from Json API

Posted: 17 Sep 2019, 08:44
by QuốcTrungNguyễnHoàng
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.

Re: GetRefItems from Json API

Posted: 17 Sep 2019, 08:47
by aimeos
Keep you index tables up to date and rebuild the product index using the "index/rebuild" job controller.