Skip to content

Updating a product via the REST API assigns it to all websites automatically. #11324

@andrewkett

Description

@andrewkett

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

  1. Magento 2.2.0 CE (upgraded from 2.1.9)
  2. PHP 7.0.20
  3. MYSQL 5.7.17
  4. NGINX

Steps to reproduce

  1. Remove a product from all websites in admin
  2. GET V1/products/example_sku via REST API to confirm product isn't assigned to any stores
  3. update product data at global scope via PUT rest/all/V1/products/example_sku
  4. GET V1/products/example_sku via REST API again

Expected result

  1. 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

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions