From 7233c4d4a02edab9e5bb99f775bab43535e0c51f Mon Sep 17 00:00:00 2001 From: Herant Date: Fri, 30 Jul 2021 15:07:45 +0200 Subject: [PATCH] Add link renderer and item renderer for link --- .../RenderLayered/LinkRenderer.php | 25 +++++++- .../LinkRenderer/ItemRenderer.php | 63 +++++++++++++++++++ .../TreeRenderer/ItemRenderer.php | 6 +- Block/Navigation/FilterRenderer/Plugin.php | 2 + README.md | 13 ++-- etc/adminhtml/system.xml | 8 --- etc/config.xml | 1 - .../templates/product/layered/link.phtml | 16 +++++ .../templates/product/layered/link/item.phtml | 40 ++++++++++++ 9 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 Block/LayeredNavigation/RenderLayered/LinkRenderer/ItemRenderer.php create mode 100644 view/frontend/templates/product/layered/link.phtml create mode 100644 view/frontend/templates/product/layered/link/item.phtml diff --git a/Block/LayeredNavigation/RenderLayered/LinkRenderer.php b/Block/LayeredNavigation/RenderLayered/LinkRenderer.php index 53045c12..403355be 100644 --- a/Block/LayeredNavigation/RenderLayered/LinkRenderer.php +++ b/Block/LayeredNavigation/RenderLayered/LinkRenderer.php @@ -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'; -} \ No newline at end of file + /** + * @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(); + } +} diff --git a/Block/LayeredNavigation/RenderLayered/LinkRenderer/ItemRenderer.php b/Block/LayeredNavigation/RenderLayered/LinkRenderer/ItemRenderer.php new file mode 100644 index 00000000..76d3f657 --- /dev/null +++ b/Block/LayeredNavigation/RenderLayered/LinkRenderer/ItemRenderer.php @@ -0,0 +1,63 @@ +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(); + } +} diff --git a/Block/LayeredNavigation/RenderLayered/TreeRenderer/ItemRenderer.php b/Block/LayeredNavigation/RenderLayered/TreeRenderer/ItemRenderer.php index c0919117..9101832a 100644 --- a/Block/LayeredNavigation/RenderLayered/TreeRenderer/ItemRenderer.php +++ b/Block/LayeredNavigation/RenderLayered/TreeRenderer/ItemRenderer.php @@ -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 { /** @@ -56,4 +60,4 @@ public function getChildren() { return $this->item->getChildren(); } -} \ No newline at end of file +} diff --git a/Block/Navigation/FilterRenderer/Plugin.php b/Block/Navigation/FilterRenderer/Plugin.php index 681820d7..a35052f7 100644 --- a/Block/Navigation/FilterRenderer/Plugin.php +++ b/Block/Navigation/FilterRenderer/Plugin.php @@ -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; @@ -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, ]; diff --git a/README.md b/README.md index d089cd5d..2167bd58 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c5b5bcf1..b021509b 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -24,14 +24,6 @@ Magento\Config\Model\Config\Source\Yesno - - - When category filter is not of type tree in Tweakwise use links to child categories instead of filter values. - Magento\Config\Model\Config\Source\Yesno - - 1 - - Magento\Config\Model\Config\Source\Yesno diff --git a/etc/config.xml b/etc/config.xml index d13c1b64..c72cd86b 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -19,7 +19,6 @@ 0 - 1 1 1 none diff --git a/view/frontend/templates/product/layered/link.phtml b/view/frontend/templates/product/layered/link.phtml new file mode 100644 index 00000000..f239a0a7 --- /dev/null +++ b/view/frontend/templates/product/layered/link.phtml @@ -0,0 +1,16 @@ + +
    + getItems() as $item): ?> + renderLinkItem($item)?> + +
diff --git a/view/frontend/templates/product/layered/link/item.phtml b/view/frontend/templates/product/layered/link/item.phtml new file mode 100644 index 00000000..3e3edfbf --- /dev/null +++ b/view/frontend/templates/product/layered/link/item.phtml @@ -0,0 +1,40 @@ +getItem(); +?> +
  • + + getItemPrefix()?> + escapeHtml($item->getLabel())?> + getItemPostfix()?> + + shouldDisplayProductCountOnLayer()): ?> + + getCount())?> + + getCount() == 1):?> + + + + + + + + + + hasChildren()): ?> +
      + getChildren() as $child): ?> + renderTreeItem($child)?> + +
    + +