diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php index 958d802682d52..1a3c860cba13f 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php @@ -97,6 +97,12 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco )->where( 'attribute.attribute_id = ?', $superAttribute->getAttributeId() + )->joinInner( + ['attribute_opt' => $this->attributeResource->getTable('eav_attribute_option')], + 'attribute_opt.option_id = entity_value.value', + [] + )->order( + 'attribute_opt.sort_order ASC' ); if (!$superAttribute->getSourceModel()) { diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php index 235c16c9b556c..af777f900ebbc 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php @@ -5,13 +5,13 @@ */ namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Attribute; +use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionProvider; use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilder; use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute; -use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionProvider; use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\App\ScopeInterface; -use Magento\Framework\DB\Select; use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\DB\Select; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; /** @@ -58,7 +58,7 @@ class OptionSelectBuilderTest extends \PHPUnit\Framework\TestCase * @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject */ private $scope; - + protected function setUp() { $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) @@ -112,7 +112,7 @@ public function testGetSelect() { $this->select->expects($this->exactly(1))->method('from')->willReturnSelf(); $this->select->expects($this->exactly(1))->method('columns')->willReturnSelf(); - $this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf(); + $this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf(); $this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf(); $this->select->expects($this->exactly(2))->method('where')->willReturnSelf(); @@ -138,7 +138,7 @@ public function testGetSelectWithBackendModel() { $this->select->expects($this->exactly(1))->method('from')->willReturnSelf(); $this->select->expects($this->exactly(0))->method('columns')->willReturnSelf(); - $this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf(); + $this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf(); $this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf(); $this->select->expects($this->exactly(2))->method('where')->willReturnSelf();