-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Updating a product via the REST API using PUT /rest/all/V1/products/example_sku assigns it to all websites automatically.
Possibly a duplicate of #10495
Preconditions
- Magento 2.2.0 CE (upgraded from 2.1.9)
- PHP 7.0.20
- MYSQL 5.7.17
- NGINX
Steps to reproduce
- Remove a product from all websites in admin
GET V1/products/example_skuvia REST API to confirm product isn't assigned to any stores- update product data at global scope via
PUT rest/all/V1/products/example_sku GET V1/products/example_skuvia REST API again
Expected result
- Products should be assigned to same stores as it was previously (none) as I didn't pass website_ids in extension attributes and I didn't call V1/products/example_sku/websites
Actual result
- Product is assigned to all websites even though I didn't explicitly send any website associations
Example API calls made to replicate this issue.
GET http://mysite.com/index.php/rest/all/V1/products/example_sku
response (truncated)
{
"id": 971,
"sku": "example_sku",
"name": "Example Product",
"attribute_set_id": 9,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2017-10-07 03:56:47",
"updated_at": "2017-10-10 03:37:00",
"weight": 0
"extension_attributes": {
"website_ids": []
},
...
}
note that the website_ids array is empty as I have unassociated the product from any websites
PUT http://mysite.com/rest/all/V1/products/example_sku
{
"product": {
"name": "Example Product Updated"
}
}
note that I am not passing any website_ids to associate the product with any stores.
GET http://mysite.com/index.php/rest/all/V1/products/example_sku
response (truncated)
{
"id": 971,
"sku": "example_sku",
"name": "Example Product Updated",
"attribute_set_id": 9,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2017-10-07 03:56:47",
"updated_at": "2017-10-10 03:54:48",
"weight": 0,
"extension_attributes": {
"website_ids": [
1,
2,
3
]
}
...
}
note that the website_ids array is now populated with all website ids.
I understand that I am using "all" which is setting values for all store views however I think it should still be possible to update attribute values globally without automatically assigning products to websites. e.g We have 9 websites in a single Magento install, some products are used on multiple websites but not all websites. We want to update the product data at global scope so the data can be reused across stores but currently doing this means that the product then becomes available on all websites which could be very bad if this happened in a live environment.
This may just be my misunderstanding of how the API works but if this is the case then I see merit in changing it. We already have an API to assign products to stores via V1/products/{sku}/websites, automatically doing it in a product update is confusing if I am not explicitly passing website ids to the product.