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

Commit

Permalink
Add link renderer and item renderer for link
Browse files Browse the repository at this point in the history
  • Loading branch information
Hnto committed Jul 30, 2021
1 parent 22962ce commit 7233c4d
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 18 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,63 @@
<?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()
{
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();
}
}
}
2 changes: 2 additions & 0 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
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">
<?php foreach ($block->getItems() as $item): ?>
<?=$block->renderLinkItem($item)?>
<?php endforeach; ?>
</ol>
40 changes: 40 additions & 0 deletions view/frontend/templates/product/layered/link/item.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 ($item->getChildren() as $child): ?>
<?=$block->renderTreeItem($child)?>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</li>

0 comments on commit 7233c4d

Please sign in to comment.