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(); ?> -