modules/acm_sku/src/Plugin/AcquiaCommerce/SKUType/Configurable.php
public static function sortConfigOptions(array &$options, $attribute_code) {
    $sorted_options = [];

    $query = \Drupal::database()->select('taxonomy_term_field_data', 'ttfd');
    $query->fields('ttfd', ['tid', 'weight']);
    $query->join('taxonomy_term__field_sku_attribute_code', 'ttfsac', 'ttfsac.entity_id = ttfd.tid');
    $query->join('taxonomy_term__field_sku_option_id', 'ttfsoi', 'ttfsoi.entity_id = ttfd.tid');
    $query->fields('ttfsoi', ['field_sku_option_id_value']);
    $query->condition('ttfd.vid', ProductOptionsManager::PRODUCT_OPTIONS_VOCABULARY);
    $query->condition('ttfsac.field_sku_attribute_code_value', $attribute_code);
    $query->condition('ttfsoi.field_sku_option_id_value', array_keys($options), 'IN');
    $query->distinct();
    $query->orderBy('weight', 'ASC');
    $tids = $query->execute()->fetchAllAssoc('tid');

    foreach ($tids as $tid => $values) {
      $sorted_options[$values->field_sku_option_id_value] = $options[$values->field_sku_option_id_value];
    }

    return $sorted_options;
  }
public static function sortConfigOptions(array &$options, $attribute_code) {
    $sorted_options = [];

    $query = \Drupal::database()->select('taxonomy_term_field_data', 'ttfd');
    $query->fields('ttfd', ['tid', 'weight']);
    $query->join('taxonomy_term__field_sku_attribute_code', 'ttfsac', 'ttfsac.entity_id = ttfd.tid');
    $query->join('taxonomy_term__field_sku_option_id', 'ttfsoi', 'ttfsoi.entity_id = ttfd.tid');
    $query->fields('ttfsoi', ['field_sku_option_id_value']);
    $query->condition('ttfd.vid', ProductOptionsManager::PRODUCT_OPTIONS_VOCABULARY);
    $query->condition('ttfsac.field_sku_attribute_code_value', $attribute_code);
    $query->condition('ttfsoi.field_sku_option_id_value', array_keys($options), 'IN');
    $query->distinct();
    $query->orderBy('weight', 'ASC');
    $tids = $query->execute()->fetchAllAssoc('tid');

    foreach ($tids as $tid => $values) {
      $sorted_options[$values->field_sku_option_id_value] = $options[$values->field_sku_option_id_value];
    }

    return $sorted_options;
  }
public static function sortConfigOptions ( array & $ options , $ attribute_code ) { $ sorted_options = [ ] ; $ query = \ Drupal :: database ( ) -> select ( 'taxonomy_term_field_data' , 'ttfd' ) ; $ query -> fields ( 'ttfd' , [ 'tid' , 'weight' ] ) ; $ query -> join ( 'taxonomy_term__field_sku_attribute_code' , 'ttfsac' , 'ttfsac.entity_id = ttfd.tid' ) ; $ query -> join ( 'taxonomy_term__field_sku_option_id' , 'ttfsoi' , 'ttfsoi.entity_id = ttfd.tid' ) ; $ query -> fields ( 'ttfsoi' , [ 'field_sku_option_id_value' ] ) ; $ query -> condition ( 'ttfd.vid' , ProductOptionsManager :: PRODUCT_OPTIONS_VOCABULARY ) ; $ query -> condition ( 'ttfsac.field_sku_attribute_code_value' , $ attribute_code ) ; $ query -> condition ( 'ttfsoi.field_sku_option_id_value' , array_keys ( $ options ) , 'IN' ) ; $ query -> distinct ( ) ; $ query -> orderBy ( 'weight' , 'ASC' ) ; $ tids = $ query -> execute ( ) -> fetchAllAssoc ( 'tid' ) ; foreach ( $ tids as $ tid => $ values ) { $ sorted_options [ $ values -> field_sku_option_id_value ] = $ options [ $ values -> field_sku_option_id_value ] ; } return $ sorted_options ; }
Helper function to sort config options based on taxonomy term weight.

@param array $options
Option values keyed by option id.
@param string $attribute_code
Attribute name.

@return array
Array of options sorted based on term weight.
Helper function to sort config options based on taxonomy term weight .