Skip to content

Commit

Permalink
Commit changes from Sebwite#31
Browse files Browse the repository at this point in the history
  • Loading branch information
groomershop-mt committed Apr 13, 2020
1 parent d15544b commit 9b8cb1b
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 43 deletions.
65 changes: 41 additions & 24 deletions Block/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,27 @@
class Sidebar extends Template
{

/**
* @var \Magento\Catalog\Helper\Category
*/
/** * @var \Magento\Catalog\Helper\Category */
protected $_categoryHelper;

/**
* @var \Magento\Framework\Registry
*/
/** * @var \Magento\Framework\Registry */
protected $_coreRegistry;

/**
* @var \Magento\Catalog\Model\Indexer\Category\Flat\State
*/
/** * @var \Magento\Catalog\Model\Indexer\Category\Flat\State */
protected $categoryFlatConfig;

/**
* @var \Magento\Catalog\Model\CategoryFactory
*/
/** * @var \Magento\Catalog\Model\CategoryFactory */
protected $_categoryFactory;

/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection */
protected $_productCollectionFactory;

/** @var \Magento\Catalog\Helper\Output */
private $helper;


/** @var \Sebwite\Sidebar\Helper\Data */
private $_dataHelper;

/**
* @param Template\Context $context
* @param \Magento\Catalog\Helper\Category $categoryHelper
Expand All @@ -57,7 +52,6 @@ public function __construct(
\Magento\Framework\Registry $registry,
\Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Catalog\Model\ResourceModel\Product\Collection $productCollectionFactory,
\Magento\Catalog\Helper\Output $helper,
\Sebwite\Sidebar\Helper\Data $dataHelper,
Expand All @@ -75,11 +69,6 @@ public function __construct(
parent::__construct($context, $data);
}

/*
* Get owner name
* @return string
*/

/**
* Get all categories
*
Expand Down Expand Up @@ -165,7 +154,7 @@ public function getChildCategoryView($category, $html = '', $level = 1)

$childCategories = $this->getSubcategories($category);

if ( count($childCategories) > 0 )
if (is_object($childCategories) && count($childCategories) > 0 )
{

$html .= '<ul class="o-list o-list--unstyled">';
Expand Down Expand Up @@ -205,21 +194,19 @@ public function getChildCategoryView($category, $html = '', $level = 1)

/**
* Retrieve subcategories
* DEPRECATED
*
* @param $category
*
* @return array
*/

public function getSubcategories($category)
{
if ( $this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource() )
{
return (array)$category->getChildrenNodes();
}

return $category->getChildrenCategories();
return $category->getChildren();
}


Expand Down Expand Up @@ -277,4 +264,34 @@ public function getCategoryUrl($category)
{
return $this->_categoryHelper->getCategoryUrl($category);
}
}

/**
* Return Is Enabled config option
*
* @return string
*/
public function isEnabled()
{
return $this->_dataHelper->isEnabled();
}

/**
* Return Title Text for menu
*
* @return string
*/
public function getTitleText()
{
return $this->_dataHelper->getTitleText();
}

/**
* Return Menu Open config option
*
* @return string
*/
public function isOpenOnLoad()
{
return $this->_dataHelper->isOpenOnLoad();
}
}
30 changes: 29 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_PATH_ENABLED = 'general/enabled';
const XML_PATH_CATEGORY = 'general/category';
const XML_PATH_CATEGORY_DEPTH_LEVEL = 'general/categorydepth';
const XML_PATH_TITLE_TEXT = 'general/title';
const XML_PATH_OPEN_ON_LOAD = 'general/open';


/**
Expand All @@ -41,7 +43,7 @@ public function __construct(\Magento\Framework\App\Helper\Context $context, Modu
*/
public function getConfigPath(
$xmlPath,
$section = 'sebwitete_sidebar'
$section = 'sebwite_sidebar'
) {
return $section . '/' . $xmlPath;
}
Expand Down Expand Up @@ -84,5 +86,31 @@ public function getCategoryDepthLevel()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Get title text
*
* @return string|null
*/
public function getTitleText()
{
return $this->scopeConfig->getValue(
$this->getConfigPath(self::XML_PATH_TITLE_TEXT),
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Get is open on load?
*
* @return string|null
*/
public function isOpenOnLoad()
{
return $this->scopeConfig->getValue(
$this->getConfigPath(self::XML_PATH_OPEN_ON_LOAD),
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

}
14 changes: 13 additions & 1 deletion Model/Config/Source/Depth.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ public function toOptionArray()
[
'value' => 5,
'label' => __('5'),
],
],
[
'value' => 6,
'label' => __('6'),
],
[
'value' => 7,
'label' => __('7'),
],
[
'value' => 8,
'label' => __('8'),
],
];
}
}
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified composer.json
100755 → 100644
Empty file.
18 changes: 15 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</tab>
<section id="sebwite_sidebar" showInDefault="1">
<tab>sebwite</tab>
<label>Sidebar</label>
<label>Sidebar CMS Menu</label>
<resource>Magento_Config::config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0"
showInStore="0">
Expand All @@ -16,7 +16,11 @@
showInStore="0">
<label>Is Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</field>
<field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Title text above menu</label>
</field>
<field id="category" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Select Sidebar Category</label>
Expand All @@ -26,7 +30,15 @@
showInStore="0">
<label>Select Category Depth</label>
<source_model>Sebwite\Sidebar\Model\Config\Source\Depth</source_model>
</field>
</field>
<field id="open" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Open to reveal active link on page load?</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="fixed">1</field>
</depends>
</field>
</group>
</section>
</system>
Expand Down
Empty file removed test
Empty file.
3 changes: 1 addition & 2 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!--<script type="text/javascript" src="Sebwite_Sidebar::js/module.js"/>-->
<css src="Sebwite_Sidebar::css/module.css" />
<css src="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" src_type="url" />
<css src="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" src_type="url" /> <!-- Comment out if already called by theme -->
</head>
</page>
32 changes: 23 additions & 9 deletions view/frontend/templates/sidebar.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
*
* @var $block Sebwite\Sidebar\Block\Sidebar
*/
$categories = $block->getCategories();
$brands = $block->getBrands();
$isEnabled = $block->isEnabled();
$titleText = $block->getTitleText();
$isOpenOnLoad = $block->isOpenOnLoad();
$categories = $block->getCategories();

if ($isEnabled) {
?>

<h3><?php echo __('Categories'); ?></h3>
<ul class="o-list">
<h3><?= $titleText; ?></h3>
<ul class="o-list">

<?php
// Loop through categories
Expand All @@ -26,8 +30,18 @@ $brands = $block->getBrands();
<?php echo $block->getChildCategoryView($category); ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">
/* Simply invoke iffe of sidebarmodule */
require(['jquery','sidebarmodule'], function ($) {});
</script>
</ul>
<?php if ($isOpenOnLoad) { ?>
<script>
require(['jquery', 'sidebarmodule'], function($) {
$('.is-active').parents('ul').css('display','block');
$('.is-active').parents('li').addClass('active');
$('.is-active').parents('li').find('> span i').removeClass('fa-plus').addClass('fa-minus');
});
</script>
<?php } else { ?>
<script>
require(['jquery', 'sidebarmodule'], function($) {});
</script>
<?php }
} ?>
8 changes: 5 additions & 3 deletions view/frontend/web/css/module.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
float: right;
}
.o-list {
display: none;
display: block;
margin-top: 20px;
margin-bottom: 0px;
padding-left: 0px;
li {
Expand All @@ -29,8 +30,9 @@
display: inline-block;
}
> ul {
padding-top: 7px;
padding-top: 15px;
margin-top: 0px;
display: none;
}
}
.level0 {
Expand All @@ -52,4 +54,4 @@
padding-right: 45px;
margin-bottom: 30px;
}
}
}

0 comments on commit 9b8cb1b

Please sign in to comment.