Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined index in TierPriceValidator.php #36431

Closed
1 of 5 tasks
clockworkgeek opened this issue Nov 7, 2022 · 9 comments
Closed
1 of 5 tasks

Undefined index in TierPriceValidator.php #36431

clockworkgeek opened this issue Nov 7, 2022 · 9 comments
Assignees
Labels
Area: Pricing Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@clockworkgeek
Copy link

clockworkgeek commented Nov 7, 2022

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”.
@m2-assistant
Copy link

m2-assistant bot commented Nov 7, 2022

Hi @clockworkgeek. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented Nov 9, 2022

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-November. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-November
Copy link
Contributor

Verified the issue on Magento 2.4-develop instance and the issue is reproducible. Hence updating the description and confirming this issue.
Issue occurred for existing customer group names having trailing space and for any other non existing customer group names given in the api request, this issue is not reproducible.
image
image

@engcom-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Pricing Reported on 2.4.5 Indicates original Magento version for the Issue report. labels Nov 10, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Nov 10, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-7002 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Nov 10, 2022

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@engcom-November engcom-November added the Priority: P3 May be fixed according to the position in the backlog. label Nov 10, 2022
@m2-community-project m2-community-project bot added this to Ready for Development in Low Priority Backlog Nov 10, 2022
@quterorta
Copy link
Contributor

@magento I am working on this

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in Low Priority Backlog Dec 9, 2022
quterorta added a commit to quterorta/magento2 that referenced this issue Dec 9, 2022
- fixed issue with undefined index customer group for changing tier price
quterorta added a commit to quterorta/magento2 that referenced this issue Dec 15, 2022
- fixed issue with undefined index customer group for changing tier price
quterorta added a commit to quterorta/magento2 that referenced this issue Jan 23, 2023
- fixed issue with undefined index customer group for changing tier price
quterorta added a commit to quterorta/magento2 that referenced this issue Jan 24, 2023
- fixed issue with undefined index customer group for changing tier price
quterorta added a commit to quterorta/magento2 that referenced this issue Feb 24, 2023
- fixed issue with undefined index customer group for changing tier price
quterorta added a commit to quterorta/magento2 that referenced this issue Feb 24, 2023
- fixed issue with undefined index customer group for changing tier price
@m2-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in Low Priority Backlog May 22, 2023
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in Low Priority Backlog Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Pricing Component: Api Use with concrete module component label E.g. "Component: Api" + "Catalog" Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Development

No branches or pull requests

4 participants