Skip to content

Undefined index in TierPriceValidator.php #36431

@clockworkgeek

Description

@clockworkgeek

Preconditions and environment

  • Magento version 2.4.5
  • MariaDB 10.3.36 although that's probably irrelevant since this is normal database behaviour.

Steps to reproduce

  1. Create a customer group with a trailing space in it's name.
  2. Create admin integration token using POST: /rest/default/V1/integration/admin/token
  3. Using the API endpoint /rest/V1/products/tier-prices, attempt to POST a tier price for the new customer group but without the trailing space.
    Payload:
    {
    "prices": [
    {
    "price": 40,
    "price_type": "fixed",
    "website_id": 0,
    "sku": "24-MB01",
    "customer_group": "rvevgbbrrbr",
    "quantity": 1,
    "extension_attributes": {}
    }
    ]
    }

Expected result

A tier price should not be created because the customer group's name does not match. The API should return an error message like "No such entity with Customer Group".

Actual result

The API returns an error message like Message: Notice: Undefined index: XXXXX in ~/public_html/vendor/magento/module-catalog/Model/Product/Price/Validation/TierPriceValidator.php on line 474"

Additional information

The problem occurs because the database equates the two customer group names although we know there is a single character difference. The method TierPriceValidator::retrieveGroupValue first assigns one name with:

$this->customerGroupsByCode[strtolower($item->getCode())] = $item->getId();

then accesses the same array with another name and triggers an undefined index error:

return $this->customerGroupsByCode[$code];

There are two ways to mitigate this that I can see.

  1. Sanitise your inputs by trimming whitespace, removing control characters, etc. (And it's good advice in general too)
  2. Query the database with LIKE instead of = because that respects trailing spaces.

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

Labels

Area: PricingComponent: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: doneReported on 2.4.5Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions