Created
January 5, 2016 19:20
-
-
Save peter-hank/4d33c4cad7efd8441c99 to your computer and use it in GitHub Desktop.
Sort product attribute options by the position property in Magento patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7423c3fd53926f4e8dac9ab9a4b4f65b94eaa7f7 Mon Sep 17 00:00:00 2001 | |
From: peter-hank <peter.hankiewicz@gmail.com> | |
Date: Tue, 5 Jan 2016 20:11:19 +0100 | |
Subject: [PATCH] Update Collection.php | |
--- | |
.../Product/Type/Configurable/Attribute/Collection.php | 10 +++++++++- | |
1 file changed, 9 insertions(+), 1 deletion(-) | |
diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php | |
index 12ec7e2..93a3110 100755 | |
--- a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php | |
+++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php | |
@@ -250,8 +250,11 @@ protected function _loadPrices() | |
$options = $productAttribute->getFrontend()->getSelectOptions(); | |
$optionsByValue = array(); | |
+ $sortOrders = array(); | |
+ $sortOrder = 1; | |
foreach ($options as $option) { | |
$optionsByValue[$option['value']] = $option['label']; | |
+ $sortOrders[$option['value']] = $sortOrder++; | |
} | |
foreach ($this->getProduct()->getTypeInstance(true) | |
@@ -272,7 +275,8 @@ protected function _loadPrices() | |
'store_label' => $optionsByValue[$optionValue], | |
'is_percent' => 0, | |
'pricing_value' => null, | |
- 'use_default_value' => true | |
+ 'use_default_value' => true, | |
+ 'sort_order' => $sortOrders[$optionValue] | |
); | |
} | |
} | |
@@ -301,6 +305,10 @@ protected function _loadPrices() | |
} | |
} | |
} | |
+ | |
+ usort($values, function ($a, $b) { | |
+ return $a['sort_order'] > $b['sort_order']; | |
+ }); | |
foreach ($values as $data) { | |
$this->getItemById($data['product_super_attribute_id'])->addPrice($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment