JSON API - create new product and add existing Attributes with Product.lists.type

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 03 Dec 2020, 09:07

Hi there,

I am currently using Aimeos laravel ver 2020.10*

- I am using JSON API to create a variant article with existing attributes to include to Selection product
below Image is the data in the request.

- The problem is after submitting, the product.list.type = variant is automatically change to 'default'
Attachments
Screen Shot 2020-12-03 at 4.05.17 PM.png
Screen Shot 2020-12-03 at 4.05.17 PM.png (61.46 KiB) Viewed 9161 times

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

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by aimeos » 04 Dec 2020, 08:29

Can you please post your full request and response including the code for building the request?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 04 Dec 2020, 09:15

this is the data in the POST request

{
"type": "product",
"attributes": {
"product.status": 1,
"product.type": "default",
"product.label": "label size S yellow",
"product.code": "testselectioncreate-size-S-yellow"
},
"relationships": {
"attribute": {
"data": [
{
"id": "25",
"type": "attribute",
"attributes": {
"product.lists.refid": "25",
"product.lists.domain": "attribute",
"product.lists.status": 1,
"product.lists.type": "variant"
}
},
{
"id": "28",
"type": "attribute",
"attributes": {
"product.lists.refid": "28",
"product.lists.domain": "attribute",
"product.lists.status": 1,
"product.lists.type": "variant"
}
}
]
}
}
}

the response will be the Product with the created Data
{
"meta": {
"total": 9
, "csrf": {
"name": "_token",
"value": ""
}

}

, "data": [
{
"id": "277",
"type": "product",
"attributes": {
"product.id": "277",
"product.siteid": "3.",
"product.ctime": "2020-12-04 15:43:38",
"product.mtime": "2020-12-04 15:43:38",
"product.editor": "shop2",
"product.url": "label-size-S-yellow",
"product.type": "default",
"product.code": "testselectioncreate-size-S-yellow",
"product.label": "label size S yellow",
"product.status": 1,
"product.dataset": "",
"product.datestart": null,
"product.dateend": null,
"product.config": [],
"product.scale": 1,
"product.target": "",
"product.rating": "0.00",
"product.ratings": 0
},
"links": {
},
"relationships": []
},

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 04 Dec 2020, 09:47

when I check the source code in JSON ADM

As the line 432 the source code
$listItem = $listManager->createItem()->setType( 'default' );
I change to 'default' to 'variant' the variant is set for the product.lists.type

How could I extend the source here to get the product.lists.type from the request

Code: Select all

{
"type": "product",
"attributes": {
"product.status": 1,
"product.type": "default",
"product.label": "label size S yellow",
"product.code": "testselectioncreate-size-S-yellow"
},
"relationships": {
"attribute": {
"data": [
{
"id": "25",
"type": "attribute",
"attributes": {
"product.lists.refid": "25",
"product.lists.domain": "attribute",
"product.lists.status": 1,
"product.lists.type": "variant"
}
},
{
"id": "28",
"type": "attribute",
"attributes": {
"product.lists.refid": "28",
"product.lists.domain": "attribute",
"product.lists.status": 1,
"product.lists.type": "variant"
}
}
]
}
}
}
Attachments
Screen Shot 2020-12-04 at 4.44.17 PM.png
Screen Shot 2020-12-04 at 4.44.17 PM.png (141.95 KiB) Viewed 9136 times

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

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by aimeos » 06 Dec 2020, 17:44

In line 437 (fromArray()), your product.lists.type should be set to "variant" if you pass that via the JsonAdm API. Can you please check what does happen there in your case?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 07 Dec 2020, 02:59

Thank you for your response,

However the product.lists.type is still "default"

could you please call an sample API fo checking it?
- create a new product with existing attributes and the product.lists.type: "variant"

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 07 Dec 2020, 03:13

as I am checking the In line 437 (fromArray()),

Code: Select all

$item = $item->fromArray( $attr, true );
the $item is the product id rather than the product.list

I changed to this one and the product.lists is saved as expected:

Code: Select all

$listItem = $listItem->fromArray( $attr, true );
would you like to check the source is it alright or any problems with my change?

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

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by aimeos » 07 Dec 2020, 14:18

Yes, it should be $listItem instead of $item. Can you create a PR for your fix?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Kevin1596
Posts: 28
Joined: 13 Aug 2020, 10:11

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by Kevin1596 » 14 Dec 2020, 08:10

yes I already created a pull request

please help me check it
https://github.com/aimeos/ai-admin-json ... 11/commits

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

Re: JSON API - create new product and add existing Attributes with Product.lists.type

Post by aimeos » 14 Dec 2020, 08:18

Thanks, your PR has been merged and will be part of the next release
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply