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 all 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
4 changes: 3 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 Down Expand Up @@ -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.

return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
}
if ($category) {
$this->layerResolver->create(Resolver::CATALOG_LAYER_CATEGORY);
$settings = $this->_catalogDesign->getDesignSettings($category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model\Product\ProductList;
Expand All @@ -15,13 +14,14 @@
* Class ToolbarMemorizer
*
* Responds for saving toolbar settings to catalog session
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class ToolbarMemorizer
{
/**
* XML PATH to enable/disable saving toolbar parameters to session
*/
const XML_PATH_CATALOG_REMEMBER_PAGINATION = 'catalog/frontend/remember_pagination';
public const XML_PATH_CATALOG_REMEMBER_PAGINATION = 'catalog/frontend/remember_pagination';

/**
* @var CatalogSession
Expand Down Expand Up @@ -63,6 +63,11 @@ class ToolbarMemorizer
*/
private $isMemorizingAllowed;

/**
* @var bool
*/
private $hasMemorizeParam = false;

/**
* @param Toolbar $toolbarModel
* @param CatalogSession $catalogSession
Expand Down Expand Up @@ -173,7 +178,18 @@ private function memorizeParam($param, $value)
{
if ($value && $this->catalogSession->getData($param) != $value) {
$this->catalogSession->setData($param, $value);
$this->hasMemorizeParam = true;
}
return $this;
}

/**
* Check has Memorize parameter value apply
*
* @return bool
*/
public function hasMemorizingParam()
{
return $this->hasMemorizeParam;
}
}