1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \Catalog \Helper ;
7
7
8
8
use Magento \Catalog \Api \CategoryRepositoryInterface ;
9
9
use Magento \Catalog \Model \Category as ModelCategory ;
10
+ use Magento \Catalog \Model \CategoryFactory ;
10
11
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 ;
11
15
use Magento \Framework \Exception \NoSuchEntityException ;
12
16
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
17
+ use Magento \Store \Model \ScopeInterface ;
13
18
use Magento \Store \Model \Store ;
19
+ use Magento \Store \Model \StoreManagerInterface ;
20
+ use Magento \Catalog \Model \ResourceModel \Category \Collection as CategoryCollection ;
14
21
15
22
/**
16
23
* Catalog category helper
@@ -33,21 +40,21 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface
33
40
/**
34
41
* Store manager instance
35
42
*
36
- * @var \Magento\Store\Model\ StoreManagerInterface
43
+ * @var StoreManagerInterface
37
44
*/
38
45
protected $ _storeManager ;
39
46
40
47
/**
41
48
* Category factory instance
42
49
*
43
- * @var \Magento\Catalog\Model\ CategoryFactory
50
+ * @var CategoryFactory
44
51
*/
45
52
protected $ _categoryFactory ;
46
53
47
54
/**
48
55
* Lib data collection factory
49
56
*
50
- * @var \Magento\Framework\Data\ CollectionFactory
57
+ * @var CollectionFactory
51
58
*/
52
59
protected $ _dataCollectionFactory ;
53
60
@@ -57,17 +64,17 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface
57
64
protected $ categoryRepository ;
58
65
59
66
/**
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
64
71
* @param CategoryRepositoryInterface $categoryRepository
65
72
*/
66
73
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 ,
71
78
CategoryRepositoryInterface $ categoryRepository
72
79
) {
73
80
$ this ->_categoryFactory = $ categoryFactory ;
@@ -83,8 +90,8 @@ public function __construct(
83
90
* @param bool|string $sorted
84
91
* @param bool $asCollection
85
92
* @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
88
95
*/
89
96
public function getStoreCategories ($ sorted = false , $ asCollection = false , $ toLoad = true )
90
97
{
@@ -98,7 +105,6 @@ public function getStoreCategories($sorted = false, $asCollection = false, $toLo
98
105
* Check if parent node of the store still exists
99
106
*/
100
107
$ category = $ this ->_categoryFactory ->create ();
101
- /* @var $category ModelCategory */
102
108
if (!$ category ->checkId ($ parent )) {
103
109
if ($ asCollection ) {
104
110
return $ this ->_dataCollectionFactory ->create ();
@@ -110,7 +116,7 @@ public function getStoreCategories($sorted = false, $asCollection = false, $toLo
110
116
0 ,
111
117
(int )$ this ->scopeConfig ->getValue (
112
118
'catalog/navigation/max_depth ' ,
113
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
119
+ ScopeInterface::SCOPE_STORE
114
120
)
115
121
);
116
122
$ storeCategories = $ category ->getCategories ($ parent , $ recursionLevel , $ sorted , $ asCollection , $ toLoad );
@@ -173,7 +179,7 @@ public function canUseCanonicalTag($store = null)
173
179
{
174
180
return $ this ->scopeConfig ->getValue (
175
181
self ::XML_PATH_USE_CATEGORY_CANONICAL_TAG ,
176
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
182
+ ScopeInterface::SCOPE_STORE ,
177
183
$ store
178
184
);
179
185
}
@@ -185,4 +191,19 @@ public function _resetState(): void
185
191
{
186
192
$ this ->_storeCategories = [];
187
193
}
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
+ }
188
209
}
0 commit comments