-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions and environment
- Magento Open Source 2.4.X
- Clean Installation of Magento 2.4.X, I used 2.4.6-p2 but all 2.4.X are affected.
- Magento with multiple websites.
- Product has assigned multiple websites.
- Magento Sample Data installed and Tier prices are added to the products with identical information except the website that is affected.
Steps to reproduce
- Go to the admin edit page and edit a product information.
- Set product tier prices with identical information but different affected websites.
- Delete ALL product tier prices with TierPriceStorageInterface, to do this get all tier prices with the TierPriceStorageInterface and use the retrieved prices to delete them.
Tier Prices should look like this:
Expected result
All Tier prices are deleted.
Actual result
Only the first tier price that match the conditions is deleted, because it doesn't take into account the website of the tier price.
Additional information
The problem is found in \Magento\Catalog\Model\Product\Price\TierPriceStorage.php where the function delete doesn't retrieve correctly the affected IDs to delete. The function retrievePriceId (Line 267) is the culprit of the bug with the current code:
` /**
* Look through provided price in list of existing prices and retrieve it's Id.
*
* @param array $price
* @param array $existingPrices
* @return int|null
*/
private function retrievePriceId(array $price, array $existingPrices): ?int
{
$linkField = $this->tierPricePersistence->getEntityLinkField();
foreach ($existingPrices as $existingPrice) {
if ($existingPrice['all_groups'] == $price['all_groups']
&& $existingPrice['customer_group_id'] == $price['customer_group_id']
&& $existingPrice['qty'] == $price['qty']
&& $this->isCorrectPriceValue($existingPrice, $price)
&& $existingPrice[$linkField] == $price[$linkField]
) {
return (int) $existingPrice['value_id'];
}
}
return null;
}`
But the correct way of retrieving the price Id should be:
` /**
* Look through provided price in list of existing prices and retrieve it's Id.
*
* @param array $price
* @param array $existingPrices
* @return int|null
*/
private function retrievePriceId(array $price, array $existingPrices): ?int
{
$linkField = $this->tierPricePersistence->getEntityLinkField();
foreach ($existingPrices as $existingPrice) {
if ($existingPrice['all_groups'] == $price['all_groups']
&& $existingPrice['customer_group_id'] == $price['customer_group_id']
&& $existingPrice['qty'] == $price['qty']
&& $this->isCorrectPriceValue($existingPrice, $price)
&& $existingPrice[$linkField] == $price[$linkField]
&& $existingPrice['website_id'] == $price['website_id']
) {
return (int) $existingPrice['value_id'];
}
}
return null;
}`
With this fix the retrieve price ID takes into account the website the tier price is created and makes a unique identifier of the tier price with all the previous information.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.