Skip to content

Tier Price Storage Interface Delete Bug doesn't delete all Tier Prices #37949

@MarcProvi

Description

@MarcProvi

Preconditions and environment

  • Magento Open Source 2.4.X
  1. Clean Installation of Magento 2.4.X, I used 2.4.6-p2 but all 2.4.X are affected.
  2. Magento with multiple websites.
  3. Product has assigned multiple websites.
  4. Magento Sample Data installed and Tier prices are added to the products with identical information except the website that is affected.

Steps to reproduce

  1. Go to the admin edit page and edit a product information.
  2. Set product tier prices with identical information but different affected websites.
  3. 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:

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions