Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #173 from EmicoEcommerce/feat/category-filter-type…
Browse files Browse the repository at this point in the history
…-tweakwise

Feat/category filter type tweakwise
  • Loading branch information
stijnbernards authored Aug 4, 2021
2 parents 22962ce + 4ab1b42 commit 0d552f1
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 23 deletions.
25 changes: 24 additions & 1 deletion Block/LayeredNavigation/RenderLayered/LinkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,30 @@

namespace Emico\Tweakwise\Block\LayeredNavigation\RenderLayered;

use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer\ItemRenderer;
use Emico\Tweakwise\Model\Catalog\Layer\Filter\Item;

/**
* Class LinkRenderer
* @package Emico\Tweakwise\Block\LayeredNavigation\RenderLayered
*/
class LinkRenderer extends DefaultRenderer
{
/**
* {@inheritDoc}
*/
protected $_template = 'Emico_Tweakwise::product/layered/link.phtml';

}
/**
* @param Item $item
* @return string
*/
public function renderLinkItem(Item $item)
{
/** @var ItemRenderer $block */
$block = $this->getLayout()->createBlock(ItemRenderer::class);
$block->setFilter($this->filter);
$block->setItem($item);
return $block->toHtml();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Tweakwise & Emico (https://www.tweakwise.com/ & https://www.emico.nl/) - All Rights Reserved
*
* @copyright Copyright (c) 2017-2017 Tweakwise.com B.V. (https://www.tweakwise.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer;

use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer;
use Emico\Tweakwise\Model\Catalog\Layer\Filter\Item;

/**
* Class ItemRenderer
* @package Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer
*/
class ItemRenderer extends LinkRenderer
{
/**
* {@inheritDoc}
*/
protected $_template = 'Emico_Tweakwise::product/layered/link/item.phtml';

/**
* @var Item
*/
protected $item;

/**
* @return Item
*/
public function getItem()
{
return $this->item;
}

/**
* @param Item $item
* @return $this
*/
public function setItem(Item $item)
{
$this->item = $item;
return $this;
}

/**
* @return bool
*/
public function hasChildren()
{
return $this->item->hasChildren();
}

/**
* @return Item[]
*/
public function getChildren()
{
// When rendering link items we need to remove everything after the first nesting
// because "link view (linkweergave)" has a max of 1 nesting
foreach ($this->item->getChildren() as $child) {
$child->setChildren([]);
}
return $this->item->getChildren();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\TreeRenderer;
use Emico\Tweakwise\Model\Catalog\Layer\Filter\Item;

/**
* Class ItemRenderer
* @package Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\TreeRenderer
*/
class ItemRenderer extends TreeRenderer
{
/**
Expand Down Expand Up @@ -56,4 +60,4 @@ public function getChildren()
{
return $this->item->getChildren();
}
}
}
7 changes: 3 additions & 4 deletions Block/Navigation/FilterRenderer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Closure;
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\DefaultRenderer;
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer;
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\SwatchRenderer;
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\SliderRenderer;
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\TreeRenderer;
Expand Down Expand Up @@ -46,6 +47,7 @@ class Plugin
*/
protected $blockTypes = [
SettingsType::SELECTION_TYPE_TREE => TreeRenderer::class,
SettingsType::SELECTION_TYPE_LINK => LinkRenderer::class,
SettingsType::SELECTION_TYPE_SLIDER => SliderRenderer::class,
SettingsType::SELECTION_TYPE_COLOR => SwatchRenderer::class,
];
Expand Down Expand Up @@ -97,6 +99,7 @@ public function aroundRender(FilterRenderer $subject, Closure $proceed, FilterIn
$facet = $filter->getFacet();
$settings = $facet->getFacetSettings();
$renderType = $settings->getSelectionType();

if ($this->config->getUseDefaultLinkRenderer() && in_array($renderType, $this->defaultAllowedRenderTypes)) {
return $proceed($filter);
}
Expand All @@ -119,10 +122,6 @@ public function aroundRender(FilterRenderer $subject, Closure $proceed, FilterIn
*/
protected function getBlockType(SettingsType $settings)
{
if ($settings->getSource() === SettingsType::SOURCE_CATEGORY) {
return TreeRenderer::class;
}

$renderType = $settings->getSelectionType();
return $this->blockTypes[$renderType] ?? DefaultRenderer::class;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getHideSingleOptions(Store $store = null)
*/
public function getUseDefaultLinkRenderer(Store $store = null)
{
return (bool)$this->getStoreConfig('tweakwise/layered/default_link_renderer', $store);
return (bool) $this->getStoreConfig('tweakwise/layered/default_link_renderer', $store);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ Below is a rundown of all configuration options

#### Layered Navigation (All settings depend on Enabled having value yes):
1) Enabled: Use tweakwise results in navigation, if disabled the standard magento navigation is used.
2) Category filters as link
3) Hide facets with only one option: Given a result set from tweakwise in which a filter has only one option show that filter or not?
4) Use default magento filter renderer: Use Magento standard filter templates or use templates bundled by the module.
2) Hide facets with only one option: Given a result set from tweakwise in which a filter has only one option show that filter or not?
3) Use default magento filter renderer: Use Magento standard filter templates or use templates bundled by the module.
If you want to make full use of the features provided by this module then this should be set to No (i.e. make use of tweakwise template files).
5) Filter form: This depends on 'Use default magento filter renderer' having value No. Render all filters in a form with filter buttons so that the user can select a set of filters and then navigate to the result instead of immediately navigating to the results when a filter is clicked.
6) Filter url query parameters: Tweakwise filter urls will have all query parameters of the page in it so also the "cid" and utm_source parameters if present.
4) Filter form: This depends on 'Use default magento filter renderer' having value No. Render all filters in a form with filter buttons so that the user can select a set of filters and then navigate to the result instead of immediately navigating to the results when a filter is clicked.
5) Filter url query parameters: Tweakwise filter urls will have all query parameters of the page in it so also the "cid" and utm_source parameters if present.
You can determine in which way you want to filter these out (if any).
7) Filter url query arguments: This depends on 'Filter url query parameters' having any value not equal to 'Dont Filter'. This field specifies which parameters should be removed from the tweakwise filter urls.
8) Url strategy: Has two options Query parameters and Seo path slug. If query parameters is selected then the tweakwise filter urls (and thus your navigation urls) will be constructed as
6) Filter url query arguments: This depends on 'Filter url query parameters' having any value not equal to 'Dont Filter'. This field specifies which parameters should be removed from the tweakwise filter urls.
7) Url strategy: Has two options Query parameters and Seo path slug. If query parameters is selected then the tweakwise filter urls (and thus your navigation urls) will be constructed as
`www.example.com/example-category?color=red`.

If Seo path slugs is selected the url is constructed as `www.example.com/example-category/color/red`.
Expand Down
8 changes: 0 additions & 8 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="category_links" translate="label,comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Category filters as link</label>
<comment>When category filter is not of type tree in Tweakwise use links to child categories instead of filter values.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="hide_single_option" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Hide facets with only one option</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
1 change: 0 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</general>
<layered>
<enabled>0</enabled>
<category_links>1</category_links>
<hide_single_option>1</hide_single_option>
<default_link_renderer>1</default_link_renderer>
<query_filter_type>none</query_filter_type>
Expand Down
16 changes: 16 additions & 0 deletions view/frontend/templates/product/layered/link.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Tweakwise & Emico (https://www.tweakwise.com/ & https://www.emico.nl/) - All Rights Reserved
*
* @copyright Copyright (c) 2017-2017 Tweakwise.com B.V. (https://www.tweakwise.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\TreeRenderer;

/** @var $block \Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer */
?>
<ol class="items link-attribute">
<?php foreach ($block->getItems() as $item): ?>
<?=$block->renderLinkItem($item)?>
<?php endforeach; ?>
</ol>
41 changes: 41 additions & 0 deletions view/frontend/templates/product/layered/link/item.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Tweakwise & Emico (https://www.tweakwise.com/ & https://www.emico.nl/) - All Rights Reserved
*
* @copyright Copyright (c) 2017-2017 Tweakwise.com B.V. (https://www.tweakwise.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
use Emico\Tweakwise\Block\LayeredNavigation\RenderLayered\LinkRenderer\ItemRenderer;

/** @var $block ItemRenderer */
$item = $block->getItem();
?>

<li class="item">
<a href="<?=$block->escapeUrl($item->getUrl())?>">
<?=$block->getItemPrefix()?>
<?=$block->escapeHtml($item->getLabel())?>
<?=$block->getItemPostfix()?>

<?php if ($block->shouldDisplayProductCountOnLayer()): ?>
<span class="count">
<?=htmlentities($item->getCount())?>
<span class="filter-count-label">
<?php if ($item->getCount() == 1):?>
<?=__('item')?>
<?php else:?>
<?=__('items')?>
<?php endif;?>
</span>
</span>
<?php endif; ?>
</a>

<?php if ($block->hasChildren()): ?>
<ol class="items child-items">
<?php foreach ($block->getChildren() as $child): ?>
<?=$block->renderLinkItem($child)?>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</li>
3 changes: 3 additions & 0 deletions view/frontend/web/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
margin-left: 15px;
}

.link-attribute .child-items {
margin-left: 15px;
}

.search-autocomplete {
ul {
Expand Down

0 comments on commit 0d552f1

Please sign in to comment.