From dbfa3f54a01f6da07e1d88c8de47734aafd27cbd Mon Sep 17 00:00:00 2001 From: Edwin Jacobs Date: Wed, 10 Apr 2019 20:21:14 +0200 Subject: [PATCH 1/2] Added alternate sorting --- .../Block/Catalog/Layer/Facet/Attribute.php | 13 ++++++++++++ .../Tweakwise/Model/Bus/Type/Abstract.php | 21 +++++++++++++++++++ .../Tweakwise/Model/Bus/Type/Attribute.php | 4 ++++ .../catalog/layer/facet/attribute.phtml | 20 ++++++++++++++---- .../emico_tweakwise/js/filter_collapse.js | 17 +++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/code/community/Emico/Tweakwise/Block/Catalog/Layer/Facet/Attribute.php b/app/code/community/Emico/Tweakwise/Block/Catalog/Layer/Facet/Attribute.php index 39e7299..a302551 100644 --- a/app/code/community/Emico/Tweakwise/Block/Catalog/Layer/Facet/Attribute.php +++ b/app/code/community/Emico/Tweakwise/Block/Catalog/Layer/Facet/Attribute.php @@ -95,6 +95,19 @@ public function isMoreItem(Emico_Tweakwise_Model_Bus_Type_Attribute $item) return $key >= $this->getFacetSettings()->getNumberOfShownAttributes(); } + /** + * @return bool + */ + public function hasAlternateSort() + { + $filter = function (Emico_Tweakwise_Model_Bus_Type_Attribute $item) { + return is_numeric($item->getAlternateSortOrder()); + }; + + $itemsWithAlternateOrder = array_filter($this->getAttributes(), $filter); + return \count($this->getAttributes()) === \count($itemsWithAlternateOrder); + } + /** * Get magento url based on current url * diff --git a/app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php b/app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php index 84d7a5e..6fd660a 100644 --- a/app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php +++ b/app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php @@ -99,4 +99,25 @@ protected function elementToType(SimpleXMLElement $xmlElement, $type) return $helper->getTypeModel($type, $xmlElement); } } + + /** + * @param SimpleXMLElement $element + * @param string $attribute + * @param string DataType + * @param string $dataKey + */ + protected function setDataFromAttribute(SimpleXMLElement $element, $attribute, $dataType, $dataKey = null) + { + foreach ($element->attributes() as $attributeName => $value) { + if ($attributeName !== $attribute) { + continue; + } + + $value = $this->elementToType($value, $dataType); + if (!$dataKey) { + $dataKey = $attribute; + } + $this->setData($dataKey, $value); + } + } } \ No newline at end of file diff --git a/app/code/community/Emico/Tweakwise/Model/Bus/Type/Attribute.php b/app/code/community/Emico/Tweakwise/Model/Bus/Type/Attribute.php index b022203..778b8b2 100644 --- a/app/code/community/Emico/Tweakwise/Model/Bus/Type/Attribute.php +++ b/app/code/community/Emico/Tweakwise/Model/Bus/Type/Attribute.php @@ -9,6 +9,7 @@ * @method int getNumberOfResults(); * @method int getAttributeId(); * @method string getUrl(); + * @method int getAlternateSortOrder(); * @method Emico_Tweakwise_Model_Bus_Type_Attribute[] getChildren(); */ class Emico_Tweakwise_Model_Bus_Type_Attribute extends Emico_Tweakwise_Model_Bus_Type_Abstract @@ -24,6 +25,9 @@ public function setDataFromXMLElement(SimpleXMLElement $xmlElement) $this->setDataFromField($xmlElement, 'attributeid', self::DATA_TYPE_INT, self::ELEMENT_COUNT_ONE, 'attribute_id'); $this->setDataFromField($xmlElement, 'url', self::DATA_TYPE_STRING); $this->setDataFromField($xmlElement, 'children', 'attribute', self::ELEMENT_COUNT_NONE_OR_MORE); + + $this->setDataFromAttribute($xmlElement, 'alternatesortorder', self::DATA_TYPE_INT, 'alternate_sort_order'); + if ($parent = $xmlElement->xpath("parent::*")) { if ($parentLevel = $parent[0]->xpath("parent::*")) { if ($parentLevel[0]->isselected) { diff --git a/app/design/frontend/base/default/template/emico_tweakwise/catalog/layer/facet/attribute.phtml b/app/design/frontend/base/default/template/emico_tweakwise/catalog/layer/facet/attribute.phtml index cb9dc4a..3b5a40e 100644 --- a/app/design/frontend/base/default/template/emico_tweakwise/catalog/layer/facet/attribute.phtml +++ b/app/design/frontend/base/default/template/emico_tweakwise/catalog/layer/facet/attribute.phtml @@ -15,10 +15,17 @@ getAttributes(); ?> -
    - +
      hasAlternateSort()):?> data-has-alternate-sort="1"> + $_item): ?> getIsSelected() || $this->isCheckbox(); ?> -
    1. +
    2. getAlternateSortOrder())):?> + data-original-sort="" + data-alternate-sort="getAlternateSortOrder()?>" + + > href="escapeUrl($this->getFacetUrl($_item)) ?>" title="escapeHtml($this->getItemTitle($_item))?>"getHrefAttributes()?>> escapeHtml($this->getItemTitle($_item)); ?> getIsNumberOfResultVisible()): ?> @@ -29,7 +36,12 @@ showMoreText()): ?> -
    3. diff --git a/skin/frontend/base/default/emico_tweakwise/js/filter_collapse.js b/skin/frontend/base/default/emico_tweakwise/js/filter_collapse.js index 31bb68e..835e442 100644 --- a/skin/frontend/base/default/emico_tweakwise/js/filter_collapse.js +++ b/skin/frontend/base/default/emico_tweakwise/js/filter_collapse.js @@ -2,6 +2,9 @@ function initTweakwiseCollapseLinks(){ $$('#narrow-by-list .more-link').each(function(showLink) { var hideLink = showLink.up().select('.less-link')[0]; var hiddenElements = showLink.up('li').up().select('li.hidden'); + var list = showLink.up('ol'); + var elements = showLink.up('ol').select('li'); + var hasAlternateSort = showLink.up('ol').readAttribute('data-has-alternate-sort'); showLink.observe('click', function(event){ event.stop(); @@ -9,6 +12,9 @@ function initTweakwiseCollapseLinks(){ showLink.addClassName('hidden'); hideLink.removeClassName('hidden'); hiddenElements.each(function(element){ element.removeClassName('hidden'); }); + if (hasAlternateSort) { + sortFilterItems('data-alternate-sort', elements, list); + } }); hideLink.observe('click', function(event){ @@ -17,6 +23,9 @@ function initTweakwiseCollapseLinks(){ hideLink.addClassName('hidden'); showLink.removeClassName('hidden'); hiddenElements.each(function(element){ element.addClassName('hidden'); }); + if (hasAlternateSort) { + sortFilterItems('data-original-sort', elements, list); + } }); }); @@ -37,5 +46,13 @@ function initTweakwiseCollapseLinks(){ }); } +function sortFilterItems(type, elements, list) { + elements.sort(function (a, b) { + return a.readAttribute(type) - b.readAttribute(type); + }); + jQuery(list).append(elements); + //list.appendChild(elements); +} + document.observe('dom:loaded', initTweakwiseCollapseLinks); document.observe('list:loaded', initTweakwiseCollapseLinks); \ No newline at end of file From dafb33a95a32aeebe61dca59566a1db00cceaaf7 Mon Sep 17 00:00:00 2001 From: Edwin Jacobs Date: Wed, 24 Apr 2019 13:02:23 +0200 Subject: [PATCH 2/2] Added extra styling for hidden facets --- .../base/default/emico_tweakwise/css/navigation.css | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/skin/frontend/base/default/emico_tweakwise/css/navigation.css b/skin/frontend/base/default/emico_tweakwise/css/navigation.css index 972d84d..4a29a93 100755 --- a/skin/frontend/base/default/emico_tweakwise/css/navigation.css +++ b/skin/frontend/base/default/emico_tweakwise/css/navigation.css @@ -178,6 +178,16 @@ div .slider .right { color: inherit; } +.block-layered-nav .checkbox { + display: block; +} + +.block-layered-nav li.hidden, +.block-layered-nav .more-link.hidden, +.block-layered-nav .less-link.hidden { + display: none; +} + @media only screen and (max-width: 770px) { .block-layered-nav .arrow { display: none;