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 */
66namespace Magento \Catalog \Helper ;
77
88use Magento \Catalog \Api \CategoryRepositoryInterface ;
99use Magento \Catalog \Model \Category as ModelCategory ;
10+ use Magento \Catalog \Model \CategoryFactory ;
1011use 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 ;
1115use Magento \Framework \Exception \NoSuchEntityException ;
1216use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
17+ use Magento \Store \Model \ScopeInterface ;
1318use 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