Skip to content

Fix php warning on update item qty request from sidebar #34953

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

Conversation

Melnychuk-Alexandr
Copy link
Contributor

Description (*)

Added "int" type when get param from request.
Path to file (app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php)

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Warning: A non-numeric value encountered in vendor/magento/module-checkout/Controller/Sidebar/UpdateItemQty.php on line 69 #34380

Manual testing scenarios (*)

  1. Open https://your-magento-domain.com/checkout/sidebar/updateItemQty/?item_qty=error
  2. See result

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jan 10, 2022

Hi @Melnychuk-Alexandr. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests 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 Pull Requests 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.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

@m2-community-project m2-community-project bot added the Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. label Jan 10, 2022
@m2-community-project m2-community-project bot added Progress: pending review Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Jan 10, 2022
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add test coverage for this case

@ihor-sviziev ihor-sviziev changed the title Github issue 34380: Added "int" type when get param from request. Fix php warning on update item qty request from sidebar Jan 20, 2022
@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests and removed Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. labels Jan 20, 2022
@ihor-sviziev
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Melnychuk-Alexandr,
Could you please cover your change with any type of automated test?
Thank you!

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also restrict this controller to handle only POST requests?
I see it's only used in

<form action="<?= $block->escapeUrl($block->getUrl('checkout/cart/updatePost')) ?>"
method="post"
id="form-validate"
data-mage-init='{"Magento_Checkout/js/action/update-shopping-cart":
{"validationURL" : "<?= $block->escapeUrl($block->getUrl('checkout/cart/updateItemQty')) ?>",
"updateCartActionContainer": "#update_cart_action_container"}
}'
class="form form-cart">

@engcom-Alfa
Copy link
Contributor

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Alfa
Copy link
Contributor

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Alfa
Copy link
Contributor

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. Have Magento latest installed
  2. Make sure to have one customer login to login at the frontend

Manual testing scenario:

  1. Login to the front end

  2. Add a product to the cart and checkout.

  3. Open developer tool and be in the Network tab;

  4. Replace the URL to this - https://your-magento-domain.com/checkout/sidebar/updateItemQty/?item_qty=error and enter

Before: ✖️ We were getting an 500 error in the response

image

After: ✔️ We are getting an Magento error with 404

image

There is no additional testing required since it is specific to URL tampering, hence no regression case has been added for this.

@engcom-Alfa
Copy link
Contributor

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento-engcom-team
Copy link
Contributor

Hi @Den4ik, thank you for the review.
ENGCOM-9398 has been created to process this Pull Request

@engcom-Charlie
Copy link
Contributor

As PR has been approved and tested, also the build is green now, hence moving this PR to Merge in Progress.

Thank you!

@davidandersson1
Copy link

Hello,

Anybody know how to apply the patch for this issue?

I have downloaded https://github.com/magento/magento2/commit/b692ea60a10f695cfb3114c5faf6b8dd60548b32.diff
and created folder at "app/code/Magento/Checkout/Controller/Sidebar" and put file UpdateItemQty.php as per this
https://github.com/Melnychuk-Alexandr/magento2/blob/b692ea60a10f695cfb3114c5faf6b8dd60548b32/app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

and tried with composer i.e
"magento/module-checkout": {
"non-numeric value encountered": "patches/composer/b692ea60a10f695cfb3114c5faf6b8dd60548b32.diff",
},
but somehow it's not work and throwing error as per attached screenshot.

So please help if anybody know exactly how to apply this patch.
Screenshot from 2022-08-02 11-51-23

@hostep
Copy link
Contributor

hostep commented Aug 4, 2022

@davidandersson1:

  1. Overriding a file by just putting it in app/code is most likely not going to work, this isn't Magento 1 anymore.
  2. The patch you need is not the last commit of this PR, but all the commits of the PR, in this case: https://github.com/magento/magento2/pull/34953.diff
  3. If the patch doesn't apply, it could mean that it's not compatible with your magento version (but you are on 2.4.3-p1 or 2.4.3-p2, and the patch should apply on those versions), or it could mean that you haven't updated the correct paths in your patch (remove app/code/Magento/Checkout/ from the patch, 8 times in this case). Also try to understand how your patches module works by reading its documentation. Also adding -vvv to composer install might show you more details about why it fails.

(Additional hint: you really should be switching from composer v1 to composer v2, it will run many many times faster.)

@davidandersson1
Copy link

@hostep thanks for your response, I took all commits of the PR and apply patch accordingdly and now patch works fine. thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: Checkout Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning: A non-numeric value encountered in vendor/magento/module-checkout/Controller/Sidebar/UpdateItemQty.php on line 69
9 participants