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

Issue 36563: Remember Category Pagination causes a Document Expired/form submission error #36595

Open
wants to merge 7 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

rogerdz
Copy link
Contributor

@rogerdz rogerdz commented Dec 11, 2022

Description (*)

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Remember Category Pagination causes a Document Expired/form submission error when using the browser's Back button on the product page #36563

Manual testing scenarios (*)

  1. ...
  2. ...

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 Dec 11, 2022

Hi @rogerdz. 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.

✏️ 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 Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Dec 11, 2022
@rogerdz
Copy link
Contributor Author

rogerdz commented Dec 11, 2022

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

@aplapana
Copy link
Contributor

aplapana commented Dec 21, 2022

Hello @rogerdz ! It is nice to see that you are willing to help out with this issue.

I took a look at your current implementation and it is partially working. From what i can see, it does indeed resolve the bug, but it alters the core functionality and basically disregarding the "Remember Category pagination" configuration option by adding the "product_list_limit" parameter to the URL.

I wouldn't recommend this approach, especially since it can have an impact on other areas (SEO for example) as well. Fortunately we do have an option that would address this. Lets digg a little deeper into what is actually happing:

  • changing the product list limit triggers a POST action
  • note that after the page reload, the POST is still active
  • accessing a different page (in this case a product page, but it can be other page types as well) and then going back to it will cause the browser to error out because it can't restore the previous document state

In such scenarios, a common practice is to apply a POST/REDIRECT/GET pattern. Nothing fancy about it - we just need to redirect to the same page after the POST action has been processed. We can controll this behaviour from the Magento controller that is responsible for triggering the toolbar parameter saving - namely: app/code/Magento/Catalog/Controller/Category/View.php. Notice here the $this->toolbarMemorizer->memorizeParams() method call.

Let me know if you are willing to give this another go and refactor the solution a little bit.

Thank you for your time!

@rogerdz
Copy link
Contributor Author

rogerdz commented Dec 22, 2022

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

@rogerdz
Copy link
Contributor Author

rogerdz commented Dec 22, 2022

Hi @aplapana ,
I refactor the solution.

@aplapana
Copy link
Contributor

@rogerdz i left some comments for you. Let me know if you have questions.

@rogerdz
Copy link
Contributor Author

rogerdz commented Dec 23, 2022

Hi @aplapana,
I read your comment, and changed solution in new commit. Can you review it ?

@aplapana
Copy link
Contributor

@rogerdz are you sure you pushed the changes ? I am not seeing any new commits...

@rogerdz
Copy link
Contributor Author

rogerdz commented Dec 23, 2022

@aplapana , I changed a day ago and in PR it show my new changed.
New logic is redirect same page after the POST action has been processed.

input.name = 'redirect_url';
input.value = this.options.url;
form.appendChild(input);

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't actually need to create an input to pass the current URL to your request. You can do this with PHP, directly in app/code/Magento/Catalog/Controller/Category/View.php controller. Example:
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); .

You can set the respose redirect before the return $page; statement. Note that the above should be executed under certain conditions:

  • memorizing is allowed (see app/code/Magento/Catalog/Model/Product/ProductList/ToolbarMemorizer.php)
  • toolbar specific parameters reside in the request. The parameter names are available here: app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php (notice the declared constants)

Copy link
Contributor Author

@rogerdz rogerdz Jan 9, 2023

Choose a reason for hiding this comment

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

Thank for your review. I added some change in new commit.

}
}
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't actually need this. I think a private method that would determine if you need to redirect or not (returns boolean) would be more suitable. Please also specify the method return type.

@rogerdz
Copy link
Contributor Author

rogerdz commented Jan 9, 2023

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

@@ -210,6 +209,9 @@ public function execute()
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
}
$category = $this->_initCategory();
if ($this->toolbarMemorizer->hasMemorizingParam()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also check if memorizing is allowed via $this->toolbarMemorizer->isMemorizingAllowed() method call.

Copy link
Contributor Author

@rogerdz rogerdz Jan 10, 2023

Choose a reason for hiding this comment

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

I don't think it's necessary. $this->hasMemorizeParam is always false, only true when new category parameter is saved to the session (this only happens when memorizing is allowed)

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect it is necessary. You can implement the change and have the tests run again and see how it goes. We can always revert the change. Please bare in mind that in order for this to pass, all tests need to pass.

Also, once we have a stable solution, we will need to have testing coverage for the new code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: review Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Status: Review in Progress
3 participants