77
88use Magento \Framework \Data \Tree \Node ;
99use Magento \Store \Model \Store ;
10+ use Magento \Framework \Registry ;
11+ use Magento \Catalog \Model \ResourceModel \Category \Tree ;
12+ use Magento \Catalog \Model \CategoryFactory ;
13+ use Magento \Backend \Block \Template \Context ;
14+ use Magento \Catalog \Model \Category ;
1015
1116/**
1217 * Class AbstractCategory
@@ -16,17 +21,17 @@ class AbstractCategory extends \Magento\Backend\Block\Template
1621 /**
1722 * Core registry
1823 *
19- * @var \Magento\Framework\ Registry
24+ * @var Registry
2025 */
2126 protected $ _coreRegistry = null ;
2227
2328 /**
24- * @var \Magento\Catalog\Model\ResourceModel\Category\ Tree
29+ * @var Tree
2530 */
2631 protected $ _categoryTree ;
2732
2833 /**
29- * @var \Magento\Catalog\Model\ CategoryFactory
34+ * @var CategoryFactory
3035 */
3136 protected $ _categoryFactory ;
3237
@@ -36,17 +41,17 @@ class AbstractCategory extends \Magento\Backend\Block\Template
3641 protected $ _withProductCount ;
3742
3843 /**
39- * @param \Magento\Backend\Block\Template\ Context $context
40- * @param \Magento\Catalog\Model\ResourceModel\Category\ Tree $categoryTree
41- * @param \Magento\Framework\ Registry $registry
42- * @param \Magento\Catalog\Model\ CategoryFactory $categoryFactory
44+ * @param Context $context
45+ * @param Tree $categoryTree
46+ * @param Registry $registry
47+ * @param CategoryFactory $categoryFactory
4348 * @param array $data
4449 */
4550 public function __construct (
46- \ Magento \ Backend \ Block \ Template \ Context $ context ,
47- \ Magento \ Catalog \ Model \ ResourceModel \ Category \ Tree $ categoryTree ,
48- \ Magento \ Framework \ Registry $ registry ,
49- \ Magento \ Catalog \ Model \ CategoryFactory $ categoryFactory ,
51+ Context $ context ,
52+ Tree $ categoryTree ,
53+ Registry $ registry ,
54+ CategoryFactory $ categoryFactory ,
5055 array $ data = []
5156 ) {
5257 $ this ->_categoryTree = $ categoryTree ;
@@ -67,36 +72,47 @@ public function getCategory()
6772 }
6873
6974 /**
75+ * Get category id
76+ *
7077 * @return int|string|null
7178 */
7279 public function getCategoryId ()
7380 {
7481 if ($ this ->getCategory ()) {
75- return $ this ->getCategory ()->getId ();
82+ return $ this ->getCategory ()
83+ ->getId ();
7684 }
77- return \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ;
85+ return Category::TREE_ROOT_ID ;
7886 }
7987
8088 /**
89+ * Get category name
90+ *
8191 * @return string
8292 */
8393 public function getCategoryName ()
8494 {
85- return $ this ->getCategory ()->getName ();
95+ return $ this ->getCategory ()
96+ ->getName ();
8697 }
8798
8899 /**
100+ * Get category path
101+ *
89102 * @return mixed
90103 */
91104 public function getCategoryPath ()
92105 {
93106 if ($ this ->getCategory ()) {
94- return $ this ->getCategory ()->getPath ();
107+ return $ this ->getCategory ()
108+ ->getPath ();
95109 }
96- return \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ;
110+ return Category::TREE_ROOT_ID ;
97111 }
98112
99113 /**
114+ * Check store root category
115+ *
100116 * @return bool
101117 */
102118 public function hasStoreRootCategory ()
@@ -109,15 +125,20 @@ public function hasStoreRootCategory()
109125 }
110126
111127 /**
128+ * Get store from request
129+ *
112130 * @return Store
113131 */
114132 public function getStore ()
115133 {
116- $ storeId = (int )$ this ->getRequest ()->getParam ('store ' );
134+ $ storeId = (int )$ this ->getRequest ()
135+ ->getParam ('store ' );
117136 return $ this ->_storeManager ->getStore ($ storeId );
118137 }
119138
120139 /**
140+ * Get root category for tree
141+ *
121142 * @param mixed|null $parentNodeCategory
122143 * @param int $recursionLevel
123144 * @return Node|array|null
@@ -130,13 +151,14 @@ public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
130151 }
131152 $ root = $ this ->_coreRegistry ->registry ('root ' );
132153 if ($ root === null ) {
133- $ storeId = (int )$ this ->getRequest ()->getParam ('store ' );
154+ $ storeId = (int )$ this ->getRequest ()
155+ ->getParam ('store ' );
134156
135157 if ($ storeId ) {
136158 $ store = $ this ->_storeManager ->getStore ($ storeId );
137159 $ rootId = $ store ->getRootCategoryId ();
138160 } else {
139- $ rootId = \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ;
161+ $ rootId = Category::TREE_ROOT_ID ;
140162 }
141163
142164 $ tree = $ this ->_categoryTree ->load (null , $ recursionLevel );
@@ -149,10 +171,11 @@ public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
149171
150172 $ root = $ tree ->getNodeById ($ rootId );
151173
152- if ($ root && $ rootId != \ Magento \ Catalog \ Model \Category:: TREE_ROOT_ID ) {
174+ if ($ root ) {
153175 $ root ->setIsVisible (true );
154- } elseif ($ root && $ root ->getId () == \Magento \Catalog \Model \Category::TREE_ROOT_ID ) {
155- $ root ->setName (__ ('Root ' ));
176+ if ($ root ->getId () == Category::TREE_ROOT_ID ) {
177+ $ root ->setName (__ ('Root ' ));
178+ }
156179 }
157180
158181 $ this ->_coreRegistry ->register ('root ' , $ root );
@@ -162,22 +185,28 @@ public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
162185 }
163186
164187 /**
188+ * Get Default Store Id
189+ *
165190 * @return int
166191 */
167192 protected function _getDefaultStoreId ()
168193 {
169- return \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ;
194+ return Store::DEFAULT_STORE_ID ;
170195 }
171196
172197 /**
198+ * Get category collection
199+ *
173200 * @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
174201 */
175202 public function getCategoryCollection ()
176203 {
177- $ storeId = $ this ->getRequest ()->getParam ('store ' , $ this ->_getDefaultStoreId ());
204+ $ storeId = $ this ->getRequest ()
205+ ->getParam ('store ' , $ this ->_getDefaultStoreId ());
178206 $ collection = $ this ->getData ('category_collection ' );
179207 if ($ collection === null ) {
180- $ collection = $ this ->_categoryFactory ->create ()->getCollection ();
208+ $ collection = $ this ->_categoryFactory ->create ()
209+ ->getCollection ();
181210
182211 $ collection ->addAttributeToSelect (
183212 'name '
@@ -212,11 +241,11 @@ public function getRootByIds($ids)
212241 if (null === $ root ) {
213242 $ ids = $ this ->_categoryTree ->getExistingCategoryIdsBySpecifiedIds ($ ids );
214243 $ tree = $ this ->_categoryTree ->loadByIds ($ ids );
215- $ rootId = \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ;
244+ $ rootId = Category::TREE_ROOT_ID ;
216245 $ root = $ tree ->getNodeById ($ rootId );
217- if ($ root && $ rootId != \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ) {
246+ if ($ root && $ rootId != Category::TREE_ROOT_ID ) {
218247 $ root ->setIsVisible (true );
219- } elseif ($ root && $ root ->getId () == \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ) {
248+ } elseif ($ root && $ root ->getId () == Category::TREE_ROOT_ID ) {
220249 $ root ->setName (__ ('Root ' ));
221250 }
222251
@@ -227,6 +256,8 @@ public function getRootByIds($ids)
227256 }
228257
229258 /**
259+ * Get category node for tree
260+ *
230261 * @param mixed $parentNodeCategory
231262 * @param int $recursionLevel
232263 * @return Node
@@ -237,9 +268,9 @@ public function getNode($parentNodeCategory, $recursionLevel = 2)
237268 $ node = $ this ->_categoryTree ->loadNode ($ nodeId );
238269 $ node ->loadChildren ($ recursionLevel );
239270
240- if ($ node && $ nodeId != \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ) {
271+ if ($ node && $ nodeId != Category::TREE_ROOT_ID ) {
241272 $ node ->setIsVisible (true );
242- } elseif ($ node && $ node ->getId () == \ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ) {
273+ } elseif ($ node && $ node ->getId () == Category::TREE_ROOT_ID ) {
243274 $ node ->setName (__ ('Root ' ));
244275 }
245276
@@ -249,17 +280,26 @@ public function getNode($parentNodeCategory, $recursionLevel = 2)
249280 }
250281
251282 /**
283+ * Get category save url
284+ *
252285 * @param array $args
253286 * @return string
254287 */
255288 public function getSaveUrl (array $ args = [])
256289 {
257- $ params = ['_current ' => false , '_query ' => false , 'store ' => $ this ->getStore ()->getId ()];
290+ $ params = [
291+ '_current ' => false ,
292+ '_query ' => false ,
293+ 'store ' => $ this ->getStore ()
294+ ->getId ()
295+ ];
258296 $ params = array_merge ($ params , $ args );
259297 return $ this ->getUrl ('catalog/*/save ' , $ params );
260298 }
261299
262300 /**
301+ * Get category edit url
302+ *
263303 * @return string
264304 */
265305 public function getEditUrl ()
@@ -279,7 +319,7 @@ public function getRootIds()
279319 {
280320 $ ids = $ this ->getData ('root_ids ' );
281321 if ($ ids === null ) {
282- $ ids = [\ Magento \ Catalog \ Model \ Category::TREE_ROOT_ID ];
322+ $ ids = [Category::TREE_ROOT_ID ];
283323 foreach ($ this ->_storeManager ->getGroups () as $ store ) {
284324 $ ids [] = $ store ->getRootCategoryId ();
285325 }
0 commit comments