Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peter-hank/4d33c4cad7efd8441c99 to your computer and use it in GitHub Desktop.

Select an option

Save peter-hank/4d33c4cad7efd8441c99 to your computer and use it in GitHub Desktop.

Revisions

  1. peter-hank created this gist Jan 5, 2016.
    46 changes: 46 additions & 0 deletions magento-1.9-patch-sorted-attribue-options
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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);