-
Couldn't load subscription status.
- Fork 9.4k
Description
Preconditions
- Magento 2.2.6
Steps to reproduce
- Set Price Scope to Website (Stores -> Configuration -> Catalog -> Catalog -> Prices)
- Create a Product that has at least one tier price with global scope (all websites)
- Save Product
- Try to update Product (reproduced via Rest API - without even sending new tier prices - and Backend Save)
Expected result
- Product Values are updated
Actual result
- Exception: Unique constraint violation
The Problem seems to be here:
https://github.com/magento/magento2/blob/2.2.6/app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php#L86
While the Interface defines int as return type (not strict, only per type hint), the actual model behind the interface also allows string and returns a string.
As a result $isGlobal is false (although it should be true) because of strict comparison.
This leads to the $old array being empty and finally to Magento trying to insert the values although they already exist in the db (which then causes the Unique Constraint Violation error).
An elegant workaround with a plugin on getWebsiteId (cast value to int) seems very risky if in some other place the system expects it to be a string.