Skip to content

Commit 9e64a1c

Browse files
committed
first commit
0 parents  commit 9e64a1c

12 files changed

+287
-0
lines changed

Block/CategorisCollection.php

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Ibnab\CategoriesSide\Block;
3+
4+
class CategorisCollection extends \Magento\Framework\View\Element\Template
5+
{
6+
7+
protected $_categoryHelper;
8+
protected $categoryFlatConfig;
9+
protected $topMenu;
10+
/**
11+
* @param \Magento\Framework\View\Element\Template\Context $context
12+
* @param \Magento\Catalog\Helper\Category $categoryHelper
13+
* @param array $data
14+
*/
15+
public function __construct(
16+
\Magento\Framework\View\Element\Template\Context $context,
17+
\Magento\Catalog\Helper\Category $categoryHelper,
18+
\Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
19+
\Magento\Theme\Block\Html\Topmenu $topMenu
20+
) {
21+
22+
$this->_categoryHelper = $categoryHelper;
23+
$this->categoryFlatConfig = $categoryFlatState;
24+
$this->topMenu = $topMenu;
25+
parent::__construct($context);
26+
}
27+
/**
28+
* Return categories helper
29+
*/
30+
public function getCategoryHelper()
31+
{
32+
return $this->_categoryHelper;
33+
}
34+
35+
/**
36+
* Return categories helper
37+
* getHtml($outermostClass = '', $childrenWrapClass = '', $limit = 0)
38+
* example getHtml('level-top', 'submenu', 0)
39+
*/
40+
public function getHtml()
41+
{
42+
return $this->topMenu->getHtml();
43+
}
44+
/**
45+
* Retrieve current store categories
46+
*
47+
* @param bool|string $sorted
48+
* @param bool $asCollection
49+
* @param bool $toLoad
50+
* @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Category\Collection|array
51+
*/
52+
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
53+
{
54+
return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
55+
}
56+
/**
57+
* Retrieve child store categories
58+
*
59+
*/
60+
public function getChildCategories($category)
61+
{
62+
if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
63+
$subcategories = (array)$category->getChildrenNodes();
64+
} else {
65+
$subcategories = $category->getChildren();
66+
}
67+
return $subcategories;
68+
}
69+
70+
}

Block/CategorisCollection.php~

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Ibnab\CategoriesSide\Block;
3+
4+
class CategorisCollection extends \Magento\Framework\View\Element\Template
5+
{
6+
7+
protected $_categoryHelper;
8+
protected $categoryFlatConfig;
9+
protected $topMenu;
10+
/**
11+
* @param \Magento\Framework\View\Element\Template\Context $context
12+
* @param \Magento\Catalog\Helper\Category $categoryHelper
13+
* @param array $data
14+
*/
15+
public function __construct(
16+
\Magento\Framework\View\Element\Template\Context $context,
17+
\Magento\Catalog\Helper\Category $categoryHelper,
18+
\Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
19+
\Magento\Theme\Block\Html\Topmenu $topMenu
20+
) {
21+
22+
$this->_categoryHelper = $categoryHelper;
23+
$this->categoryFlatConfig = $categoryFlatState;
24+
$this->topMenu = $topMenu;
25+
parent::__construct($context);
26+
}
27+
/**
28+
* Return categories helper
29+
*/
30+
public function getCategoryHelper()
31+
{
32+
return $this->_categoryHelper;
33+
}
34+
35+
/**
36+
* Return categories helper
37+
* getHtml($outermostClass = '', $childrenWrapClass = '', $limit = 0)
38+
* example getHtml('level-top', 'submenu', $columnsLimit)
39+
*/
40+
public function getHtml()
41+
{
42+
return $this->topMenu->getHtml();
43+
}
44+
/**
45+
* Retrieve current store categories
46+
*
47+
* @param bool|string $sorted
48+
* @param bool $asCollection
49+
* @param bool $toLoad
50+
* @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Category\Collection|array
51+
*/
52+
public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
53+
{
54+
return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
55+
}
56+
/**
57+
* Retrieve child store categories
58+
*
59+
*/
60+
public function getChildCategories($category)
61+
{
62+
if ($this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource()) {
63+
$subcategories = (array)$category->getChildrenNodes();
64+
} else {
65+
$subcategories = $category->getChildren();
66+
}
67+
return $subcategories;
68+
}
69+
70+
}

etc/di.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
9+
<type name="Ibnab\CategoriesSide\Block\CategorisCollection">
10+
<arguments>
11+
<argument name="deleteorderAction" xsi:type="array">
12+
<item name="context" xsi:type="string">\Magento\Framework\View\Element\Template\Context</item>
13+
<item name="helper" xsi:type="string">\Magento\Catalog\Helper\Category</item>
14+
<item name="flatstate" xsi:type="string">\Magento\Catalog\Model\Indexer\Category\Flat\State</item>
15+
<item name="menu" xsi:type="string">\Magento\Theme\Block\Html\Topmenu</item>
16+
</argument>
17+
</arguments>
18+
</type>
19+
20+
</config>

etc/di.xml~

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
9+
<type name="Ibnab\CategoriesSide\Block\CategorisCollection">
10+
<arguments>
11+
<argument name="deleteorderAction" xsi:type="array">
12+
<item name="context" xsi:type="string">\Magento\Framework\View\Element\Template\Context</item>
13+
<item name="helper" xsi:type="string">\Magento\Catalog\Helper\Category</item>
14+
<item name="flatstate" xsi:type="string">\Magento\Catalog\Model\Indexer\Category\Flat\State</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
19+
</config>

etc/module.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
3+
<module name="Ibnab_CategoriesSide" setup_version="1.0.0" schema_version="1.0.0">
4+
<sequence>
5+
<module name="Magento_Catalog"/>
6+
</sequence>
7+
</module>
8+
</config>

etc/module.xml~

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="sidebar.main">
11+
<block class="Ibnab\CategoriesSide\Block\CategorisCollection" name="categoriecollection" template="Ibnab_CategoriesSide::storecategories.phtml"/>
12+
</referenceContainer>
13+
</body>
14+
</page>

view/frontend/layout/cms_index_index.xml.dist~

Whitespace-only changes.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="sidebar.additional">
11+
<block class="Ibnab\CategoriesSide\Block\CategorisCollection" name="categoriecollection" template="Ibnab_CategoriesSide::storecategories.phtml"/>
12+
</referenceContainer>
13+
</body>
14+
</page>

view/frontend/storecategories.phtml~

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$categories = $this->getStoreCategories(true,false,true);
3+
$categoryHelper = $this->getCategoryHelper();
4+
?>
5+
<ul>
6+
<?php
7+
foreach($categories as $category):
8+
if (!$category->getIsActive()) {
9+
continue;
10+
}
11+
12+
?>
13+
<li><a href="<?php echo $categoryHelper->getCategoryUrl($category) ?>"><?php echo $category->getName() ?></a></li>
14+
<?php
15+
if($childrenCategories = $this->getChildCategories($category)):
16+
?>
17+
<ul>
18+
<?php
19+
foreach($childrenCategories as $childrenCategory):
20+
if (!$childrenCategory->getIsActive()) {
21+
continue;
22+
}
23+
?>
24+
<li><a href="<?php echo $categoryHelper->getCategoryUrl($childrenCategory) ?>"><?php echo $childrenCategory->getName() ?></a></li>
25+
<?php
26+
endforeach;
27+
?>
28+
</ul>
29+
<?php
30+
endif;
31+
endforeach;
32+
?>
33+
</ul>
34+
<h1>OR</h1>
35+
<?php echo $this->getHtml() ?>
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$categories = $this->getStoreCategories(true,false,true);
3+
$categoryHelper = $this->getCategoryHelper();
4+
?>
5+
<ul>
6+
<?php
7+
foreach($categories as $category):
8+
if (!$category->getIsActive()) {
9+
continue;
10+
}
11+
12+
?>
13+
<li><a href="<?php echo $categoryHelper->getCategoryUrl($category) ?>"><?php echo $category->getName() ?></a></li>
14+
<?php
15+
if($childrenCategories = $this->getChildCategories($category)):
16+
?>
17+
<ul>
18+
<?php
19+
foreach($childrenCategories as $childrenCategory):
20+
if (!$childrenCategory->getIsActive()) {
21+
continue;
22+
}
23+
?>
24+
<li><a href="<?php echo $categoryHelper->getCategoryUrl($childrenCategory) ?>"><?php echo $childrenCategory->getName() ?></a></li>
25+
<?php
26+
endforeach;
27+
?>
28+
</ul>
29+
<?php
30+
endif;
31+
endforeach;
32+
?>
33+
</ul>
34+
35+
<?php echo $this->getHtml() ?>
36+

0 commit comments

Comments
 (0)