Skip to content

Commit d9728aa

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-61478' into EPAM-PR-16
2 parents f41e31d + c8941f1 commit d9728aa

File tree

14 files changed

+645
-26
lines changed

14 files changed

+645
-26
lines changed

app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Catalog\Helper\Product\ProductList;
99
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
10+
use Magento\Catalog\Model\Product\ProductList\ToolbarMemorizer;
11+
use Magento\Framework\App\ObjectManager;
1012

1113
/**
1214
* Product list toolbar
@@ -77,6 +79,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
7779

7880
/**
7981
* @var bool $_paramsMemorizeAllowed
82+
* @deprecated
8083
*/
8184
protected $_paramsMemorizeAllowed = true;
8285

@@ -96,6 +99,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
9699
* Catalog session
97100
*
98101
* @var \Magento\Catalog\Model\Session
102+
* @deprecated
99103
*/
100104
protected $_catalogSession;
101105

@@ -104,6 +108,11 @@ class Toolbar extends \Magento\Framework\View\Element\Template
104108
*/
105109
protected $_toolbarModel;
106110

111+
/**
112+
* @var ToolbarMemorizer
113+
*/
114+
private $toolbarMemorizer;
115+
107116
/**
108117
* @var ProductList
109118
*/
@@ -119,6 +128,16 @@ class Toolbar extends \Magento\Framework\View\Element\Template
119128
*/
120129
protected $_postDataHelper;
121130

131+
/**
132+
* @var \Magento\Framework\App\Http\Context
133+
*/
134+
private $httpContext;
135+
136+
/**
137+
* @var \Magento\Framework\Data\Form\FormKey
138+
*/
139+
private $formKey;
140+
122141
/**
123142
* @param \Magento\Framework\View\Element\Template\Context $context
124143
* @param \Magento\Catalog\Model\Session $catalogSession
@@ -128,6 +147,11 @@ class Toolbar extends \Magento\Framework\View\Element\Template
128147
* @param ProductList $productListHelper
129148
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
130149
* @param array $data
150+
* @param ToolbarMemorizer|null $toolbarMemorizer
151+
* @param \Magento\Framework\App\Http\Context|null $httpContext
152+
* @param \Magento\Framework\Data\Form\FormKey|null $formKey
153+
*
154+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
131155
*/
132156
public function __construct(
133157
\Magento\Framework\View\Element\Template\Context $context,
@@ -137,21 +161,34 @@ public function __construct(
137161
\Magento\Framework\Url\EncoderInterface $urlEncoder,
138162
ProductList $productListHelper,
139163
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
140-
array $data = []
164+
array $data = [],
165+
ToolbarMemorizer $toolbarMemorizer = null,
166+
\Magento\Framework\App\Http\Context $httpContext = null,
167+
\Magento\Framework\Data\Form\FormKey $formKey = null
141168
) {
142169
$this->_catalogSession = $catalogSession;
143170
$this->_catalogConfig = $catalogConfig;
144171
$this->_toolbarModel = $toolbarModel;
145172
$this->urlEncoder = $urlEncoder;
146173
$this->_productListHelper = $productListHelper;
147174
$this->_postDataHelper = $postDataHelper;
175+
$this->toolbarMemorizer = $toolbarMemorizer ?: ObjectManager::getInstance()->get(
176+
ToolbarMemorizer::class
177+
);
178+
$this->httpContext = $httpContext ?: ObjectManager::getInstance()->get(
179+
\Magento\Framework\App\Http\Context::class
180+
);
181+
$this->formKey = $formKey ?: ObjectManager::getInstance()->get(
182+
\Magento\Framework\Data\Form\FormKey::class
183+
);
148184
parent::__construct($context, $data);
149185
}
150186

151187
/**
152188
* Disable list state params memorizing
153189
*
154190
* @return $this
191+
* @deprecated
155192
*/
156193
public function disableParamsMemorizing()
157194
{
@@ -165,6 +202,7 @@ public function disableParamsMemorizing()
165202
* @param string $param parameter name
166203
* @param mixed $value parameter value
167204
* @return $this
205+
* @deprecated
168206
*/
169207
protected function _memorizeParam($param, $value)
170208
{
@@ -244,13 +282,13 @@ public function getCurrentOrder()
244282
$defaultOrder = $keys[0];
245283
}
246284

247-
$order = $this->_toolbarModel->getOrder();
285+
$order = $this->toolbarMemorizer->getOrder();
248286
if (!$order || !isset($orders[$order])) {
249287
$order = $defaultOrder;
250288
}
251289

252-
if ($order != $defaultOrder) {
253-
$this->_memorizeParam('sort_order', $order);
290+
if ($this->toolbarMemorizer->isMemorizingAllowed()) {
291+
$this->httpContext->setValue(ToolbarModel::ORDER_PARAM_NAME, $order, $defaultOrder);
254292
}
255293

256294
$this->setData('_current_grid_order', $order);
@@ -270,13 +308,13 @@ public function getCurrentDirection()
270308
}
271309

272310
$directions = ['asc', 'desc'];
273-
$dir = strtolower($this->_toolbarModel->getDirection());
311+
$dir = strtolower($this->toolbarMemorizer->getDirection());
274312
if (!$dir || !in_array($dir, $directions)) {
275313
$dir = $this->_direction;
276314
}
277315

278-
if ($dir != $this->_direction) {
279-
$this->_memorizeParam('sort_direction', $dir);
316+
if ($this->toolbarMemorizer->isMemorizingAllowed()) {
317+
$this->httpContext->setValue(ToolbarModel::DIRECTION_PARAM_NAME, $dir, $this->_direction);
280318
}
281319

282320
$this->setData('_current_grid_direction', $dir);
@@ -392,6 +430,8 @@ public function getPagerUrl($params = [])
392430
}
393431

394432
/**
433+
* Get pager encoded url.
434+
*
395435
* @param array $params
396436
* @return string
397437
*/
@@ -412,11 +452,15 @@ public function getCurrentMode()
412452
return $mode;
413453
}
414454
$defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes());
415-
$mode = $this->_toolbarModel->getMode();
455+
$mode = $this->toolbarMemorizer->getMode();
416456
if (!$mode || !isset($this->_availableMode[$mode])) {
417457
$mode = $defaultMode;
418458
}
419459

460+
if ($this->toolbarMemorizer->isMemorizingAllowed()) {
461+
$this->httpContext->setValue(ToolbarModel::MODE_PARAM_NAME, $mode, $defaultMode);
462+
}
463+
420464
$this->setData('_current_grid_mode', $mode);
421465
return $mode;
422466
}
@@ -568,20 +612,22 @@ public function getLimit()
568612
$defaultLimit = $keys[0];
569613
}
570614

571-
$limit = $this->_toolbarModel->getLimit();
615+
$limit = $this->toolbarMemorizer->getLimit();
572616
if (!$limit || !isset($limits[$limit])) {
573617
$limit = $defaultLimit;
574618
}
575619

576-
if ($limit != $defaultLimit) {
577-
$this->_memorizeParam('limit_page', $limit);
620+
if ($this->toolbarMemorizer->isMemorizingAllowed()) {
621+
$this->httpContext->setValue(ToolbarModel::LIMIT_PARAM_NAME, $limit, $defaultLimit);
578622
}
579623

580624
$this->setData('_current_limit', $limit);
581625
return $limit;
582626
}
583627

584628
/**
629+
* Check if limit is current used in toolbar.
630+
*
585631
* @param int $limit
586632
* @return bool
587633
*/
@@ -591,6 +637,8 @@ public function isLimitCurrent($limit)
591637
}
592638

593639
/**
640+
* Pager number of items from which products started on current page.
641+
*
594642
* @return int
595643
*/
596644
public function getFirstNum()
@@ -600,6 +648,8 @@ public function getFirstNum()
600648
}
601649

602650
/**
651+
* Pager number of items products finished on current page.
652+
*
603653
* @return int
604654
*/
605655
public function getLastNum()
@@ -609,6 +659,8 @@ public function getLastNum()
609659
}
610660

611661
/**
662+
* Total number of products in current category.
663+
*
612664
* @return int
613665
*/
614666
public function getTotalNum()
@@ -617,6 +669,8 @@ public function getTotalNum()
617669
}
618670

619671
/**
672+
* Check if current page is the first.
673+
*
620674
* @return bool
621675
*/
622676
public function isFirstPage()
@@ -625,6 +679,8 @@ public function isFirstPage()
625679
}
626680

627681
/**
682+
* Return last page number.
683+
*
628684
* @return int
629685
*/
630686
public function getLastPageNum()
@@ -692,6 +748,8 @@ public function getWidgetOptionsJson(array $customOptions = [])
692748
'orderDefault' => $this->getOrderField(),
693749
'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
694750
'url' => $this->getPagerUrl(),
751+
'formKey' => $this->formKey->getFormKey(),
752+
'post' => $this->toolbarMemorizer->isMemorizingAllowed() ? true : false
695753
];
696754
$options = array_replace_recursive($options, $customOptions);
697755
return json_encode(['productListToolbarForm' => $options]);

app/code/Magento/Catalog/Controller/Category/View.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\Action\HttpGetActionInterface;
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Catalog\Model\Layer\Resolver;
13+
use Magento\Catalog\Model\Product\ProductList\ToolbarMemorizer;
1314
use Magento\Framework\Exception\NoSuchEntityException;
1415
use Magento\Framework\View\Result\PageFactory;
1516
use Magento\Framework\App\Action\Action;
@@ -74,6 +75,11 @@ class View extends Action implements HttpGetActionInterface, HttpPostActionInter
7475
*/
7576
protected $categoryRepository;
7677

78+
/**
79+
* @var ToolbarMemorizer
80+
*/
81+
private $toolbarMemorizer;
82+
7783
/**
7884
* Constructor
7985
*
@@ -87,6 +93,7 @@ class View extends Action implements HttpGetActionInterface, HttpPostActionInter
8793
* @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
8894
* @param Resolver $layerResolver
8995
* @param CategoryRepositoryInterface $categoryRepository
96+
* @param ToolbarMemorizer|null $toolbarMemorizer
9097
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9198
*/
9299
public function __construct(
@@ -99,7 +106,8 @@ public function __construct(
99106
PageFactory $resultPageFactory,
100107
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
101108
Resolver $layerResolver,
102-
CategoryRepositoryInterface $categoryRepository
109+
CategoryRepositoryInterface $categoryRepository,
110+
ToolbarMemorizer $toolbarMemorizer = null
103111
) {
104112
parent::__construct($context);
105113
$this->_storeManager = $storeManager;
@@ -111,6 +119,7 @@ public function __construct(
111119
$this->resultForwardFactory = $resultForwardFactory;
112120
$this->layerResolver = $layerResolver;
113121
$this->categoryRepository = $categoryRepository;
122+
$this->toolbarMemorizer = $toolbarMemorizer ?: $context->getObjectManager()->get(ToolbarMemorizer::class);
114123
}
115124

116125
/**
@@ -135,6 +144,7 @@ protected function _initCategory()
135144
}
136145
$this->_catalogSession->setLastVisitedCategoryId($category->getId());
137146
$this->_coreRegistry->register('current_category', $category);
147+
$this->toolbarMemorizer->memorizeParams();
138148
try {
139149
$this->_eventManager->dispatch(
140150
'catalog_controller_category_init_after',
@@ -198,7 +208,7 @@ public function execute()
198208
if ($layoutUpdates && is_array($layoutUpdates)) {
199209
foreach ($layoutUpdates as $layoutUpdate) {
200210
$page->addUpdate($layoutUpdate);
201-
$page->addPageLayoutHandles(['layout_update' => md5($layoutUpdate)], null, false);
211+
$page->addPageLayoutHandles(['layout_update' => sha1($layoutUpdate)], null, false);
202212
}
203213
}
204214

0 commit comments

Comments
 (0)