Napotkałem ten sam problem z sortowaniem opcji atrybutów w interfejsie, ponieważ sprawdziłem ten problem i stwierdziłem, że podczas pobierania opcji atrybutów w zapytaniu w Magento 2.1.2 nie ma dodanego filtru sortowania, więc aby rozwiązać ten problem, potrzebujesz aby dodać poniższy kod w celu dodania ZAMÓWIENIA W funkcji getAttributeOptions w wierszu nr 282 w pliku: vendor / magento / module-configurable-product / Model / ResourceModel / Product / Type / Configurable.php Teraz działa dla mnie dobrze.
->joinInner(
['attribute_opt' => $this->getTable('eav_attribute_option')],
'attribute_opt.option_id = entity_value.value',
[]
)->order(
'attribute_opt.sort_order ASC'
);
Jeśli nie możesz edytować kodu, zastąp tę funkcję getAttributeOptions kodem jak poniżej:
public function getAttributeOptions($superAttribute, $productId)
{
$scope = $this->getScopeResolver()->getScope();
$select = $this->getConnection()->select()->from(
['super_attribute' => $this->getTable('catalog_product_super_attribute')],
[
'sku' => 'entity.sku',
'product_id' => 'product_entity.entity_id',
'attribute_code' => 'attribute.attribute_code',
'value_index' => 'entity_value.value',
'option_title' => $this->getConnection()->getIfNullSql(
'option_value.value',
'default_option_value.value'
),
'default_title' => 'default_option_value.value',
]
)->joinInner(
['product_entity' => $this->getTable('catalog_product_entity')],
"product_entity.{$this->getProductEntityLinkField()} = super_attribute.product_id",
[]
)->joinInner(
['product_link' => $this->getTable('catalog_product_super_link')],
'product_link.parent_id = super_attribute.product_id',
[]
)->joinInner(
['attribute' => $this->getTable('eav_attribute')],
'attribute.attribute_id = super_attribute.attribute_id',
[]
)->joinInner(
['entity' => $this->getTable('catalog_product_entity')],
'entity.entity_id = product_link.product_id',
[]
)->joinInner(
['entity_value' => $superAttribute->getBackendTable()],
implode(
' AND ',
[
'entity_value.attribute_id = super_attribute.attribute_id',
'entity_value.store_id = 0',
"entity_value.{$this->getProductEntityLinkField()} = "
. "entity.{$this->getProductEntityLinkField()}",
]
),
[]
)->joinLeft(
['option_value' => $this->getTable('eav_attribute_option_value')],
implode(
' AND ',
[
'option_value.option_id = entity_value.value',
'option_value.store_id = ' . $scope->getId(),
]
),
[]
)->joinLeft(
['default_option_value' => $this->getTable('eav_attribute_option_value')],
implode(
' AND ',
[
'default_option_value.option_id = entity_value.value',
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
),
[]
)->where(
'super_attribute.product_id = ?',
$productId
)->where(
'attribute.attribute_id = ?',
$superAttribute->getAttributeId()
)->joinInner(
['attribute_opt' => $this->getTable('eav_attribute_option')],
'attribute_opt.option_id = entity_value.value',
[]
)->order(
'attribute_opt.sort_order ASC'
);
return $this->getConnection()->fetchAll($select);
}