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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Jacobs committed May 1, 2019
2 parents dfa7cb9 + 7ef9436 commit b63e4b7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
21 changes: 21 additions & 0 deletions app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@

<?php $_attributes = $this->getAttributes(); ?>
<?php $_numberOfShownAttributes = 0; ?>
<ol>
<?php foreach ($_attributes as $_item): ?>
<ol <?php if ($this->hasAlternateSort()):?> data-has-alternate-sort="1"<?php endif;?>>
<?php foreach ($_attributes as $_index => $_item): ?>
<?php $_showLink = !$_item->getIsSelected() || $this->isCheckbox(); ?>
<li class="<?php echo $_item->getIsSelected() ? 'active' : 'inactive'; echo ($_numberOfShownAttributes >= $_settings->getNumberOfShownAttributes()) ? ' hidden' : ''; echo $this->isCheckbox() ? ' checkbox' : ''; ?>">
<li class="<?php echo $_item->getIsSelected() ? 'active' : 'inactive';
echo ($_numberOfShownAttributes >= $_settings->getNumberOfShownAttributes()) ? ' hidden' : '';
echo $this->isCheckbox() ? ' checkbox' : ''; ?>"
<?php if (is_numeric($_item->getAlternateSortOrder())):?>
data-original-sort="<?=$_index?>"
data-alternate-sort="<?=$_item->getAlternateSortOrder()?>"
<?php endif;?>
>
<a<?php if($_showLink): ?> href="<?php echo $this->escapeUrl($this->getFacetUrl($_item)) ?>"<?php endif; ?> title="<?=$this->escapeHtml($this->getItemTitle($_item))?>"<?=$this->getHrefAttributes()?>>
<?php echo $this->escapeHtml($this->getItemTitle($_item)); ?>
<?php if ($_settings->getIsNumberOfResultVisible()): ?>
Expand All @@ -29,7 +36,12 @@
<?php $_numberOfShownAttributes += 1 ?>
<?php endforeach ?>
<?php if($this->showMoreText()): ?>
<li class="more-less-links">
<li class="more-less-links"
<?php if ($this->hasAlternateSort()):?>
data-alternate-sort="99999"
data-original-sort="99999"
<?php endif;?>
>
<a href="#" class="more-link"><?php echo $this->__($_settings->getExpandText()); ?></a>
<a href="#" class="less-link hidden"><?php echo $this->__($_settings->getCollapseText()); ?></a>
</li>
Expand Down
10 changes: 10 additions & 0 deletions skin/frontend/base/default/emico_tweakwise/css/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions skin/frontend/base/default/emico_tweakwise/js/filter_collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ 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();

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){
Expand All @@ -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);
}
});
});

Expand All @@ -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);

0 comments on commit b63e4b7

Please sign in to comment.