Skip to content

Commit 724db18

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento-commerce/magento2ce into ACP2E-3541
2 parents cad38ad + 982b1c4 commit 724db18

File tree

28 files changed

+1953
-701
lines changed

28 files changed

+1953
-701
lines changed

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,81 @@
55
*/
66
namespace Magento\Catalog\Block\Category;
77

8+
use Magento\Catalog\Block\Breadcrumbs;
9+
use Magento\Catalog\Helper\Data;
10+
use Magento\Catalog\Helper\Category as CategoryHelper;
11+
use Magento\Catalog\Model\Category;
12+
use Magento\Catalog\Model\Layer;
13+
use Magento\Catalog\Model\Layer\Resolver;
14+
use Magento\Framework\App\ObjectManager;
15+
use Magento\Cms\Block\Block;
16+
use Magento\Framework\DataObject\IdentityInterface;
17+
use Magento\Framework\Exception\LocalizedException;
18+
use Magento\Framework\Registry;
19+
use Magento\Framework\View\Element\Template;
20+
use Magento\Framework\View\Element\Template\Context;
21+
822
/**
923
* Category View Block class
1024
* @api
1125
* @since 100.0.2
1226
*/
13-
class View extends \Magento\Framework\View\Element\Template implements \Magento\Framework\DataObject\IdentityInterface
27+
class View extends Template implements IdentityInterface
1428
{
1529
/**
16-
* @var \Magento\Framework\Registry
30+
* @var Registry
1731
*/
1832
protected $_coreRegistry = null;
1933

2034
/**
21-
* @var \Magento\Catalog\Model\Layer
35+
* @var Layer
2236
*/
2337
protected $_catalogLayer;
2438

2539
/**
26-
* @var \Magento\Catalog\Helper\Category
40+
* @var CategoryHelper
2741
*/
2842
protected $_categoryHelper;
2943

3044
/**
31-
* @var \Magento\Catalog\Helper\Data|null
45+
* @var Data|null
3246
*/
3347
private $catalogData;
3448

3549
/**
36-
* @param \Magento\Framework\View\Element\Template\Context $context
37-
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
38-
* @param \Magento\Framework\Registry $registry
39-
* @param \Magento\Catalog\Helper\Category $categoryHelper
50+
* @param Context $context
51+
* @param Resolver $layerResolver
52+
* @param Registry $registry
53+
* @param CategoryHelper $categoryHelper
4054
* @param array $data
41-
* @param \Magento\Catalog\Helper\Data|null $catalogData
55+
* @param Data|null $catalogData
4256
*/
4357
public function __construct(
44-
\Magento\Framework\View\Element\Template\Context $context,
45-
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
46-
\Magento\Framework\Registry $registry,
47-
\Magento\Catalog\Helper\Category $categoryHelper,
48-
array $data = [],
49-
?\Magento\Catalog\Helper\Data $catalogData = null
58+
Context $context,
59+
Resolver $layerResolver,
60+
Registry $registry,
61+
CategoryHelper $categoryHelper,
62+
array $data = [],
63+
?Data $catalogData = null
5064
) {
5165
$this->_categoryHelper = $categoryHelper;
5266
$this->_catalogLayer = $layerResolver->get();
5367
$this->_coreRegistry = $registry;
54-
$this->catalogData = $catalogData ?? \Magento\Framework\App\ObjectManager::getInstance()
55-
->get(\Magento\Catalog\Helper\Data::class);
68+
$this->catalogData = $catalogData ?? ObjectManager::getInstance()
69+
->get(Data::class);
5670
parent::__construct($context, $data);
5771
}
5872

5973
/**
6074
* @inheritdoc
6175
* @return $this
76+
* @throws LocalizedException
6277
*/
6378
protected function _prepareLayout()
6479
{
6580
parent::_prepareLayout();
6681

67-
$block = $this->getLayout()->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
82+
$block = $this->getLayout()->createBlock(Breadcrumbs::class);
6883

6984
$category = $this->getCurrentCategory();
7085
if ($category) {
@@ -88,7 +103,7 @@ protected function _prepareLayout()
88103
}
89104
if ($this->_categoryHelper->canUseCanonicalTag()) {
90105
$this->pageConfig->addRemotePageAsset(
91-
$category->getUrl(),
106+
$this->_categoryHelper->getCanonicalUrl($category->getUrl()),
92107
'canonical',
93108
['attributes' => ['rel' => 'canonical']]
94109
);
@@ -116,7 +131,7 @@ public function getProductListHtml()
116131
/**
117132
* Retrieve current category model object
118133
*
119-
* @return \Magento\Catalog\Model\Category
134+
* @return Category
120135
*/
121136
public function getCurrentCategory()
122137
{
@@ -135,7 +150,7 @@ public function getCmsBlockHtml()
135150
{
136151
if (!$this->getData('cms_block_html')) {
137152
$html = $this->getLayout()->createBlock(
138-
\Magento\Cms\Block\Block::class
153+
Block::class
139154
)->setBlockId(
140155
$this->getCurrentCategory()->getLandingPage()
141156
)->toHtml();
@@ -151,7 +166,7 @@ public function getCmsBlockHtml()
151166
*/
152167
public function isProductMode()
153168
{
154-
return $this->getCurrentCategory()->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PRODUCT;
169+
return $this->getCurrentCategory()->getDisplayMode() == Category::DM_PRODUCT;
155170
}
156171

157172
/**
@@ -161,7 +176,7 @@ public function isProductMode()
161176
*/
162177
public function isMixedMode()
163178
{
164-
return $this->getCurrentCategory()->getDisplayMode() == \Magento\Catalog\Model\Category::DM_MIXED;
179+
return $this->getCurrentCategory()->getDisplayMode() == Category::DM_MIXED;
165180
}
166181

167182
/**
@@ -175,7 +190,7 @@ public function isContentMode()
175190
{
176191
$category = $this->getCurrentCategory();
177192
$res = false;
178-
if ($category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) {
193+
if ($category->getDisplayMode() == Category::DM_PAGE) {
179194
$res = true;
180195
if ($category->getIsAnchor()) {
181196
$state = $this->_catalogLayer->getState();

app/code/Magento/Catalog/Helper/Category.php

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Catalog\Helper;
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Model\Category as ModelCategory;
10+
use Magento\Catalog\Model\CategoryFactory;
1011
use Magento\Framework\App\Helper\AbstractHelper;
12+
use Magento\Framework\App\Helper\Context;
13+
use Magento\Framework\Data\CollectionFactory;
14+
use Magento\Framework\Data\Tree\Node\Collection;
1115
use Magento\Framework\Exception\NoSuchEntityException;
1216
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
17+
use Magento\Store\Model\ScopeInterface;
1318
use Magento\Store\Model\Store;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1421

1522
/**
1623
* Catalog category helper
@@ -33,21 +40,21 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface
3340
/**
3441
* Store manager instance
3542
*
36-
* @var \Magento\Store\Model\StoreManagerInterface
43+
* @var StoreManagerInterface
3744
*/
3845
protected $_storeManager;
3946

4047
/**
4148
* Category factory instance
4249
*
43-
* @var \Magento\Catalog\Model\CategoryFactory
50+
* @var CategoryFactory
4451
*/
4552
protected $_categoryFactory;
4653

4754
/**
4855
* Lib data collection factory
4956
*
50-
* @var \Magento\Framework\Data\CollectionFactory
57+
* @var CollectionFactory
5158
*/
5259
protected $_dataCollectionFactory;
5360

@@ -57,17 +64,17 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface
5764
protected $categoryRepository;
5865

5966
/**
60-
* @param \Magento\Framework\App\Helper\Context $context
61-
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
62-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
63-
* @param \Magento\Framework\Data\CollectionFactory $dataCollectionFactory
67+
* @param Context $context
68+
* @param CategoryFactory $categoryFactory
69+
* @param StoreManagerInterface $storeManager
70+
* @param CollectionFactory $dataCollectionFactory
6471
* @param CategoryRepositoryInterface $categoryRepository
6572
*/
6673
public function __construct(
67-
\Magento\Framework\App\Helper\Context $context,
68-
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
69-
\Magento\Store\Model\StoreManagerInterface $storeManager,
70-
\Magento\Framework\Data\CollectionFactory $dataCollectionFactory,
74+
Context $context,
75+
CategoryFactory $categoryFactory,
76+
StoreManagerInterface $storeManager,
77+
CollectionFactory $dataCollectionFactory,
7178
CategoryRepositoryInterface $categoryRepository
7279
) {
7380
$this->_categoryFactory = $categoryFactory;
@@ -83,8 +90,8 @@ public function __construct(
8390
* @param bool|string $sorted
8491
* @param bool $asCollection
8592
* @param bool $toLoad
86-
* @return \Magento\Framework\Data\Tree\Node\Collection or
87-
* \Magento\Catalog\Model\ResourceModel\Category\Collection or array
93+
* @return Collection|CategoryCollection|array
94+
* @throws NoSuchEntityException
8895
*/
8996
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
9097
{
@@ -98,7 +105,6 @@ public function getStoreCategories($sorted = false, $asCollection = false, $toLo
98105
* Check if parent node of the store still exists
99106
*/
100107
$category = $this->_categoryFactory->create();
101-
/* @var $category ModelCategory */
102108
if (!$category->checkId($parent)) {
103109
if ($asCollection) {
104110
return $this->_dataCollectionFactory->create();
@@ -110,7 +116,7 @@ public function getStoreCategories($sorted = false, $asCollection = false, $toLo
110116
0,
111117
(int)$this->scopeConfig->getValue(
112118
'catalog/navigation/max_depth',
113-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
119+
ScopeInterface::SCOPE_STORE
114120
)
115121
);
116122
$storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
@@ -173,7 +179,7 @@ public function canUseCanonicalTag($store = null)
173179
{
174180
return $this->scopeConfig->getValue(
175181
self::XML_PATH_USE_CATEGORY_CANONICAL_TAG,
176-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
182+
ScopeInterface::SCOPE_STORE,
177183
$store
178184
);
179185
}
@@ -185,4 +191,19 @@ public function _resetState(): void
185191
{
186192
$this->_storeCategories = [];
187193
}
194+
195+
/**
196+
* Retrieve canonical url for the category page
197+
*
198+
* @param string $categoryUrl
199+
* @return string
200+
*/
201+
public function getCanonicalUrl(string $categoryUrl): string
202+
{
203+
$params = $this->_request->getParams();
204+
if ($params && isset($params['p'])) {
205+
$categoryUrl = $categoryUrl . '?p=' . $params['p'];
206+
}
207+
return $categoryUrl;
208+
}
188209
}

0 commit comments

Comments
 (0)