Get sku parameters on product

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
FrontEnd07
Posts: 4
Joined: 24 May 2023, 11:19

Get sku parameters on product

Post by FrontEnd07 » 24 May 2023, 11:35

How can I get sku parameters Image via api send a request to the address:

Code: Select all

http://localhost/jsonapi/product?include=attribute,media,price,product,product/property,text,catalog,supplier,stock&id=4
The issuance goes all in a heap, is this normal? Image

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

Re: Get sku parameters on product

Post by aimeos » 25 May 2023, 06:22

The JSON:API response (https://jsonapi.org) contains the found products including the related items in "included" referenced via "relationships" in the products. Thus, variant articles are also referenced via relationships (product.lists.type: "default") from the "included" section and the SKU of products is in the "product.code" property.

You can use a JS library like this one to simplify access to the JSON:API data:
https://github.com/tobyzerner/json-api-models
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
FrontEnd07
Posts: 4
Joined: 24 May 2023, 11:19

Re: Get sku parameters on product

Post by FrontEnd07 » 25 May 2023, 08:57

aimeos wrote: 25 May 2023, 06:22 The JSON:API response (https://jsonapi.org) contains the found products including the related items in "included" referenced via "relationships" in the products. Thus, variant articles are also referenced via relationships (product.lists.type: "default") from the "included" section and the SKU of products is in the "product.code" property.

You can use a JS library like this one to simplify access to the JSON:API data:
https://github.com/tobyzerner/json-api-models
Thank you for the response and support of open source aimeos, for me, as a beginner in `JSON:The API` seems complicated to work with, can you give an example of how the 'json-api-models` package will help me sort the sku parameters?
Last edited by FrontEnd07 on 25 May 2023, 08:59, edited 1 time in total.

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

Re: Get sku parameters on product

Post by aimeos » 27 May 2023, 08:45

The SKUs are in data -> attributes -> product.code in the pure JSON response and you can access them using:

Code: Select all

fetch(url, options).then(response => {
	return response.json()
}).then(response => {
	response.data.forEach(item => {
		console.log(item.attributes['product.code'])
	})
})
When using the mentioned JS library, it's:

Code: Select all

fetch(url, options).then(response => {
	return response.json()
}).then(result => {
        return (new Store()).sync(result)
}).then(models => {
	models.forEach(model => {
		console.log(model['product.code'])
	})
})
The power of the JS library is in accessing related items that are returnd in the "included" section of the response and they are directly available in the "model".
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
FrontEnd07
Posts: 4
Joined: 24 May 2023, 11:19

Re: Get sku parameters on product

Post by FrontEnd07 » 28 May 2023, 19:17

So, with one request, there is no way to get everything related to products? That is, you need to collect data through various kinds of queries? Don't you think that this complicates and leads to a big server costs?

User avatar
FrontEnd07
Posts: 4
Joined: 24 May 2023, 11:19

Re: Get sku parameters on product

Post by FrontEnd07 » 28 May 2023, 19:26

I checked the site droppe.com based on aimeos api this site is so slow and slow, it is delayed from replies

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

Re: Get sku parameters on product

Post by aimeos » 28 May 2023, 23:13

FrontEnd07 wrote: 28 May 2023, 19:17 So, with one request, there is no way to get everything related to products? That is, you need to collect data through various kinds of queries? Don't you think that this complicates and leads to a big server costs?
You can get e.g. all product related data in one query using the "include" parameter:
https://aimeos.org/docs/latest/frontend ... -resources
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Get sku parameters on product

Post by aimeos » 28 May 2023, 23:18

FrontEnd07 wrote: 28 May 2023, 19:26 I checked the site droppe.com based on aimeos api this site is so slow and slow, it is delayed from replies
The page has a sub-optimal setup and two main problems:
1.) The JSON:API and the PWA are on different domains leading to lots of CORS requests
2.) There are too many requests used for data that should be fetched in one request
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
FrontEnd07
Posts: 4
Joined: 24 May 2023, 11:19

Re: Get sku parameters on product

Post by FrontEnd07 » 29 May 2023, 09:22

I checked two sites based on `api aimeos` `azexport.az` and `droppe.com` they have the same concept of building requests to api, that is, requests come in batches, this naturally slows down, if it is possible to get answers with one request, then how?

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

Re: Get sku parameters on product

Post by aimeos » 30 May 2023, 08:05

Like said, please read: https://aimeos.org/docs/latest/frontend ... -resources

Use request like:

Code: Select all

http://localhost:8000/jsonapi/product?include=product.text,media,price,catalog,supplier,attribute,product
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply