Skip to content

Commit e0092a6

Browse files
author
Maksym Aposov
committed
Merge remote-tracking branch 'origin/MAGETWO-50409' into PR-3
2 parents d4c8287 + e245408 commit e0092a6

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config/Matrix.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ protected function prepareVariations()
321321
if ($variations) {
322322
$usedProductAttributes = $this->getUsedAttributes();
323323
$productByUsedAttributes = $this->getAssociatedProducts();
324+
$configurableAttributes = $this->getAttributes();
324325
foreach ($variations as $variation) {
325326
$attributeValues = [];
326327
foreach ($usedProductAttributes as $attribute) {
@@ -337,7 +338,7 @@ protected function prepareVariations()
337338
'code' => $attribute->getAttributeCode(),
338339
'label' => $attribute->getStoreLabel(),
339340
'id' => $attribute->getAttributeId(),
340-
'position' => $attribute->getPosition(),
341+
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
341342
'chosen' => [],
342343
];
343344
foreach ($attribute->getOptions() as $option) {

app/code/Magento/ConfigurableProduct/Model/ConfigurableAttributeData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function getAttributesData(Product $product, array $options = [])
3535
'code' => $productAttribute->getAttributeCode(),
3636
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
3737
'options' => $attributeOptionsData,
38+
'position' => $attribute->getPosition(),
3839
];
3940
$defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
4041
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ConfigurableAttributeDataTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ public function testPrepareJsonAttributes()
6767
['value_index' => 'option_id_1', 'label' => 'label_1'],
6868
['value_index' => 'option_id_2', 'label' => 'label_2'],
6969
];
70+
$position = 2;
7071
$expected = [
7172
'attributes' => [
7273
$attributeId => [
7374
'id' => $attributeId,
7475
'code' => 'test_attribute',
7576
'label' => 'Test',
77+
'position' => $position,
7678
'options' => [
7779
0 => [
7880
'id' => 'option_id_1',
@@ -108,11 +110,15 @@ public function testPrepareJsonAttributes()
108110

109111
$attributeMock = $this->getMockBuilder('Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute')
110112
->disableOriginalConstructor()
111-
->setMethods(['getProductAttribute', '__wakeup', 'getLabel', 'getOptions', 'getAttributeId'])
113+
->setMethods(['getProductAttribute', '__wakeup', 'getLabel', 'getOptions', 'getAttributeId', 'getPosition'])
112114
->getMock();
113115
$attributeMock->expects($this->once())
114116
->method('getProductAttribute')
115117
->willReturn($productAttributeMock);
118+
$attributeMock->expects($this->once())
119+
->method('getPosition')
120+
->willReturn($position);
121+
116122
$this->product->expects($this->once())->method('getStoreId')->willReturn($storeId);
117123
$productAttributeMock->expects($this->once())
118124
->method('getStoreLabel')

app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ protected function prepareVariations()
231231
$usedProductAttributes = $this->getUsedAttributes();
232232
$productByUsedAttributes = $this->getAssociatedProducts();
233233
$currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
234+
$configurableAttributes = $this->getAttributes();
234235
foreach ($variations as $variation) {
235236
$attributeValues = [];
236237
foreach ($usedProductAttributes as $attribute) {
@@ -247,7 +248,7 @@ protected function prepareVariations()
247248
'code' => $attribute->getAttributeCode(),
248249
'label' => $attribute->getStoreLabel(),
249250
'id' => $attribute->getAttributeId(),
250-
'position' => $attribute->getPosition(),
251+
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
251252
'chosen' => [],
252253
];
253254
foreach ($attribute->getOptions() as $option) {

app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
?>
1111
<?php $swatchData = $block->getSwatchData(); ?>
1212
<div class="swatch-attribute swatch-layered <?php /* @escapeNotVerified */ echo $swatchData['attribute_code'] ?>"
13-
attribute-code="<?php /* @escapeNotVerified */ echo $swatchData['attribute_code'] ?>" attribute-id="174">
13+
attribute-code="<?php /* @escapeNotVerified */ echo $swatchData['attribute_code'] ?>" attribute-id="<?php /* @escapeNotVerified */ echo $swatchData['attribute_id'] ?>">
1414
<div class="swatch-attribute-options clearfix">
1515
<?php foreach ($swatchData['options'] as $option => $label): ?>
1616
<a href="<?php /* @escapeNotVerified */ echo $label['link'] ?>" class="swatch-option-link-layered">

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,22 @@ define([
205205
*/
206206
_init: function () {
207207
if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
208+
this._sortAttributes();
208209
this._RenderControls();
209210
} else {
210211
console.log('SwatchRenderer: No input data received');
211212
}
212213
},
213214

215+
/**
216+
* @private
217+
*/
218+
_sortAttributes: function () {
219+
this.options.jsonConfig.attributes = _.sortBy(this.options.jsonConfig.attributes, function (attribute) {
220+
return attribute.position;
221+
});
222+
},
223+
214224
/**
215225
* @private
216226
*/

0 commit comments

Comments
 (0)