Skip to content

Commit 797f3af

Browse files
committed
MTA-3791: Fix flush cache for SetupConfigurationStep
2 parents b56df96 + 50be841 commit 797f3af

File tree

17 files changed

+336
-265
lines changed

17 files changed

+336
-265
lines changed

app/code/Magento/ConfigurableProduct/view/frontend/templates/product/view/type/options/configurable.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ $_attributes = $block->decorateArray($block->getAllowAttributes());
3535
"#product_addtocart_form": {
3636
"configurable": {
3737
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>,
38-
"onlyMainImg": <?php /* @escapeNotVerified */ echo $block->getVar('change_only_base_image', 'Magento_ConfigurableProduct') ?: 'false'; ?>
38+
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
39+
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
3940
}
4041
}
4142
}

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ define([
2929
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
3030
mediaGalleryInitial: null,
3131
slyOldPriceSelector: '.sly-old-price',
32-
onlyMainImg: false
32+
33+
/**
34+
* Defines the mechanism of how images of a gallery should be
35+
* updated when user switches between configurations of a product.
36+
*
37+
* As for now value of this option can be either 'replace' or 'prepend'.
38+
*
39+
* @type {String}
40+
*/
41+
gallerySwitchStrategy: 'replace'
3342
},
3443

3544
/**
@@ -85,10 +94,10 @@ define([
8594

8695
this.inputSimpleProduct = this.element.find(options.selectSimpleProduct);
8796

88-
gallery.on('gallery:loaded', function () {
89-
var galleryObject = gallery.data('gallery');
90-
options.mediaGalleryInitial = galleryObject.returnCurrentImages();
91-
});
97+
gallery.data('gallery') ?
98+
this._onGalleryLoaded(gallery) :
99+
gallery.on('gallery:loaded', this._onGalleryLoaded.bind(this, gallery));
100+
92101
},
93102

94103
/**
@@ -259,46 +268,33 @@ define([
259268
*/
260269
_changeProductImage: function () {
261270
var images,
262-
initialImages = $.extend(true, [], this.options.mediaGalleryInitial),
271+
initialImages = this.options.mediaGalleryInitial,
263272
galleryObject = $(this.options.mediaGallerySelector).data('gallery');
264273

265-
if (this.options.spConfig.images[this.simpleProduct]) {
266-
images = $.extend(true, [], this.options.spConfig.images[this.simpleProduct]);
274+
if (!galleryObject) {
275+
return;
267276
}
268277

269-
function updateGallery(imagesArr) {
270-
var imgToUpdate,
271-
mainImg;
278+
images = this.options.spConfig.images[this.simpleProduct];
272279

273-
mainImg = imagesArr.filter(function (img) {
274-
return img.isMain;
275-
});
280+
if (images) {
281+
if (this.options.gallerySwitchStrategy === 'prepend') {
282+
images = images.concat(initialImages);
283+
}
276284

277-
imgToUpdate = mainImg.length ? mainImg[0] : imagesArr[0];
278-
galleryObject.updateDataByIndex(0, imgToUpdate);
279-
galleryObject.seek(1);
280-
}
285+
images = $.extend(true, [], images);
281286

282-
if (galleryObject) {
283-
if (images) {
284-
images.map(function (img) {
285-
img.type = 'image';
286-
});
287+
images.forEach(function (img) {
288+
img.type = 'image';
289+
});
287290

288-
if (this.options.onlyMainImg) {
289-
updateGallery(images);
290-
} else {
291-
galleryObject.updateData(images)
292-
}
293-
} else {
294-
if (this.options.onlyMainImg) {
295-
updateGallery(initialImages);
296-
} else {
297-
galleryObject.updateData(this.options.mediaGalleryInitial);
298-
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
299-
}
300-
}
291+
galleryObject.updateData(images);
292+
} else {
293+
galleryObject.updateData(initialImages);
294+
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
301295
}
296+
297+
galleryObject.first();
302298
},
303299

304300
/**
@@ -506,8 +502,18 @@ define([
506502
} else {
507503
$(this.options.slyOldPriceSelector).hide();
508504
}
509-
}
505+
},
510506

507+
/**
508+
* Callback which fired after gallery gets initialized.
509+
*
510+
* @param {HTMLElement} element - DOM element associated with gallery.
511+
*/
512+
_onGalleryLoaded: function (element) {
513+
var galleryObject = element.data('gallery');
514+
515+
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
516+
}
511517
});
512518

513519
return $.mage.configurable;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"jsonSwatchConfig": <?php /* @escapeNotVerified */
1717
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
1818
"mediaCallback": "<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>",
19-
"onlyMainImg": <?php /* @escapeNotVerified */ echo $block->getVar('change_only_base_image',
20-
'Magento_Swatches') ?: 'false'; ?>
19+
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
20+
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
2121
}
2222
}
2323
}

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

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,15 @@ define([
243243
// Cache for BaseProduct images. Needed when option unset
244244
mediaGalleryInitial: [{}],
245245

246-
//
247-
onlyMainImg: false,
246+
/**
247+
* Defines the mechanism of how images of a gallery should be
248+
* updated when user switches between configurations of a product.
249+
*
250+
* As for now value of this option can be either 'replace' or 'prepend'.
251+
*
252+
* @type {String}
253+
*/
254+
gallerySwitchStrategy: 'replace',
248255

249256
// whether swatches are rendered in product list or on product page
250257
inProductList: false
@@ -295,11 +302,9 @@ define([
295302
this.element.parents('.product-item-info');
296303

297304
if (isProductViewExist) {
298-
gallery.on('gallery:loaded', function () {
299-
var galleryObject = gallery.data('gallery');
300-
301-
options.mediaGalleryInitial = galleryObject.returnCurrentImages();
302-
});
305+
gallery.data('gallery') ?
306+
this._onGalleryLoaded(gallery) :
307+
gallery.on('gallery:loaded', this._onGalleryLoaded.bind(this, gallery));
303308
} else {
304309
options.mediaGalleryInitial = [{
305310
'img': $main.find('.product-image-photo').attr('src')
@@ -1032,26 +1037,27 @@ define([
10321037
*/
10331038
updateBaseImage: function (images, context, isProductViewExist) {
10341039
var justAnImage = images[0],
1035-
updateImg,
1036-
imagesToUpdate,
1040+
initialImages = this.options.mediaGalleryInitial,
10371041
gallery = context.find(this.options.mediaGallerySelector).data('gallery'),
1038-
item;
1042+
imagesToUpdate,
1043+
isInitial;
10391044

10401045
if (isProductViewExist) {
10411046
imagesToUpdate = images.length ? this._setImageType($.extend(true, [], images)) : [];
1047+
isInitial = _.isEqual(imagesToUpdate, initialImages);
10421048

1043-
if (this.options.onlyMainImg) {
1044-
updateImg = imagesToUpdate.filter(function (img) {
1045-
return img.isMain;
1046-
});
1047-
item = updateImg.length ? updateImg[0] : imagesToUpdate[0];
1048-
gallery.updateDataByIndex(0, item);
1049+
if (this.options.gallerySwitchStrategy === 'prepend' && !isInitial) {
1050+
imagesToUpdate = imagesToUpdate.concat(initialImages);
1051+
}
10491052

1050-
gallery.seek(1);
1051-
} else {
1052-
gallery.updateData(imagesToUpdate);
1053+
gallery.updateData(imagesToUpdate);
1054+
1055+
if (isInitial) {
10531056
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
10541057
}
1058+
1059+
gallery.first();
1060+
10551061
} else if (justAnImage && justAnImage.img) {
10561062
context.find('.product-image-photo').attr('src', justAnImage.img);
10571063
}
@@ -1127,6 +1133,17 @@ define([
11271133
}
11281134

11291135
return selectedAttributes;
1136+
},
1137+
1138+
/**
1139+
* Callback which fired after gallery gets initialized.
1140+
*
1141+
* @param {HTMLElement} element - DOM element associated with a gallery.
1142+
*/
1143+
_onGalleryLoaded: function (element) {
1144+
var galleryObject = element.data('gallery');
1145+
1146+
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
11301147
}
11311148
});
11321149

app/design/frontend/Magento/luma/etc/view.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,7 @@
253253
</vars>
254254

255255
<vars module="Magento_ConfigurableProduct">
256-
<var name="change_only_base_image">true</var>
257-
</vars>
258-
<vars module="Magento_Swatches">
259-
<var name="change_only_base_image">true</var>
256+
<var name="gallery_switch_strategy">prepend</var>
260257
</vars>
261258

262259
<vars module="Js_Bundle">

dev/tests/functional/lib/Magento/Mtf/App/State/State1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class State1 extends AbstractState
2525
*
2626
* @var string
2727
*/
28-
protected $config ='admin_session_lifetime_1_hour, wysiwyg_disabled, admin_account_sharing_enable';
28+
protected $config ='admin_session_lifetime_1_hour, wysiwyg_disabled, admin_account_sharing_enable, log_to_file';
2929

3030
/**
3131
* @construct

dev/tests/functional/tests/app/Magento/Backend/Test/Repository/ConfigData.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@
150150
</field>
151151
</dataset>
152152

153+
<dataset name="log_to_file">
154+
<field name="dev/debug/debug_logging" xsi:type="array">
155+
<item name="scope" xsi:type="string">default</item>
156+
<item name="scope_id" xsi:type="number">0</item>
157+
<item name="label" xsi:type="string">Yes</item>
158+
<item name="value" xsi:type="number">1</item>
159+
</field>
160+
</dataset>
161+
153162
<dataset name="enable_https_frontend_admin">
154163
<field name="web/secure/use_in_frontend" xsi:type="array">
155164
<item name="scope" xsi:type="string">default</item>
@@ -164,6 +173,21 @@
164173
<item name="value" xsi:type="number">1</item>
165174
</field>
166175
</dataset>
176+
177+
<dataset name="enable_https_frontend_admin_rollback">
178+
<field name="web/secure/use_in_frontend" xsi:type="array">
179+
<item name="scope" xsi:type="string">default</item>
180+
<item name="scope_id" xsi:type="number">0</item>
181+
<item name="label" xsi:type="string">No</item>
182+
<item name="value" xsi:type="number">0</item>
183+
</field>
184+
<field name="web/secure/use_in_adminhtml" xsi:type="array">
185+
<item name="scope" xsi:type="string">default</item>
186+
<item name="scope_id" xsi:type="number">0</item>
187+
<item name="label" xsi:type="string">No</item>
188+
<item name="value" xsi:type="number">0</item>
189+
</field>
190+
</dataset>
167191
<dataset name="enable_hsts">
168192
<field name="web/secure/enable_hsts" xsi:type="array">
169193
<item name="scope" xsi:type="string">default</item>

dev/tests/functional/tests/app/Magento/Config/Test/TestStep/SetupConfigurationStep.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Mtf\Fixture\FixtureFactory;
1010
use Magento\Mtf\TestStep\TestStepInterface;
11+
use Magento\Mtf\Util\Command\Cli\Cache;
1112
use Magento\PageCache\Test\Page\Adminhtml\AdminCache;
1213

1314
/**
@@ -50,19 +51,28 @@ class SetupConfigurationStep implements TestStepInterface
5051
*/
5152
protected $flushCache;
5253

54+
/**
55+
* Cli command to do operations with cache.
56+
*
57+
* @var Cache
58+
*/
59+
private $cache;
60+
5361
/**
5462
* Preparing step properties.
5563
*
5664
* @constructor
5765
* @param FixtureFactory $fixtureFactory
5866
* @param AdminCache $adminCache
67+
* @param Cache $cache
5968
* @param string $configData
6069
* @param bool $rollback
6170
* @param bool $flushCache
6271
*/
6372
public function __construct(
6473
FixtureFactory $fixtureFactory,
6574
AdminCache $adminCache,
75+
Cache $cache,
6676
$configData = null,
6777
$rollback = false,
6878
$flushCache = false
@@ -72,6 +82,7 @@ public function __construct(
7282
$this->configData = $configData;
7383
$this->rollback = $rollback;
7484
$this->flushCache = $flushCache;
85+
$this->cache = $cache;
7586
}
7687

7788
/**
@@ -95,13 +106,11 @@ public function run()
95106
$config->persist();
96107
$result[] = $config;
97108
}
109+
if ($this->flushCache) {
110+
$this->cache->flush();
111+
}
98112
}
99-
100-
if ($this->flushCache) {
101-
$this->adminCache->open();
102-
$this->adminCache->getActionsBlock()->flushMagentoCache();
103-
$this->adminCache->getMessagesBlock()->waitSuccessMessage();
104-
}
113+
105114

106115
return ['config' => $result];
107116
}

0 commit comments

Comments
 (0)