Skip to content

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

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

Open
wants to merge 7 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion app/code/Magento/Catalog/Controller/Category/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Controller\Result\ForwardFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -39,6 +38,8 @@
*/
class View extends Action implements HttpGetActionInterface, HttpPostActionInterface
{
protected const PARAM_NAME_REDIRECT_URL = 'redirect_url';

/**
* @var Registry
*/
Expand Down Expand Up @@ -211,6 +212,11 @@ public function execute()
}
$category = $this->_initCategory();
if ($category) {
$redirectUrl = $this->applyMemorizingRedirect();
if ($redirectUrl) {
return $this->resultRedirectFactory->create()->setUrl($redirectUrl);
}

$this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY);
$settings = $this->_catalogDesign->getDesignSettings($category);

Expand Down Expand Up @@ -294,4 +300,20 @@ private function applyLayoutUpdates(
$page->addPageLayoutHandles($settings->getPageLayoutHandles());
}
}

/**
* Apply redirect for Memorizing
*
* @return false|mixed
*/
private function applyMemorizingRedirect()
{
if ($this->toolbarMemorizer->isMemorizingAllowed()) {
$url = $this->_request->getParam(self::PARAM_NAME_REDIRECT_URL);
if ($url) {
return $url;
}
}
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.

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ define([
formKey.value = this.options.formKey;
form.appendChild(formKey);

input = document.createElement('input');
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.

paramData = $.param(paramData);
baseUrl += paramData.length ? '?' + paramData : '';

Expand Down