Skip to content

Commit b2e7753

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop latest changes
Accepted Community Pull Requests: - #30057: #1833: Add ability to disable renditions functionality to stores configuration (by @joweecaquicla) - #29794: Fix issue product name in minicart render wrong with special characters (by @mrtuvn) - #30034: #1830: Stabilize AdminMediaGalleryCatalogUiVerifyUsedInLinkProductGridTest and AdminMediaGalleryCatalogUiUsedInCategoryFilterTest (by @joweecaquicla) - #29814: Fix of Asynchronous opetations status issue (by @nuzil) - #29972: Update zip_codes.xml (by @marcostrama) - #28818: Improvement PageLayout Config Builder. Added save in cache config files. (by @Knase) - #29081: Fix for wildcard section reload being broken by section-config refacor (by @complexthings) - #29080: UPS Shipment Tracking: Show "Delivered On" only when package has actually been delivered (by @danbtl) - #28164: Prevent side effect on category objects store_id and url_key on save (by @schmengler) - #27980: Fix SQL query quoting/casting when type is passed to where function (by @tmotyl) - #30095: Added configuration for Stale Issue bot (by @sdzhepa) Fixed GitHub Issues: - #29075: Minicart product name - not covered cases (reported by @Januszpl) has been fixed in #29794 by @mrtuvn in 2.4-develop branch Related commits: 1. 9df9db2 - #29718: Wrong handling some of asynchronous bulk operations and related mysql queue messages in Magento 2.4.0 (reported by @Neos2007) has been fixed in #29814 by @nuzil in 2.4-develop branch Related commits: 1. 09b63c7 2. 2450b14 3. 77d62ef 4. 4da31ea 5. a0e65ed 6. 5c87afe - #29984: [Issue] Update zip_codes.xml (reported by @m2-assistant[bot]) has been fixed in #29972 by @marcostrama in 2.4-develop branch Related commits: 1. 1472740 2. 16b8d6a 3. 65b5ee4 4. c336ccc 5. 2f94846 - #29546: [Issue] Improvement PageLayout Config Builder. Added save in cache config files. (reported by @m2-assistant[bot]) has been fixed in #28818 by @Knase in 2.4-develop branch Related commits: 1. f2468b5 2. cc2c5b9 3. 26b41af 4. eeecdf7 5. 2ac6e0c 6. 276cb1c - #28154: [Backward compatibility] Customer section load with one section causes an error (reported by @zhartaunik) has been fixed in #29081 by @complexthings in 2.4-develop branch Related commits: 1. 4f10b5d 2. 1505a36 3. ff99146 4. 8047497 5. dd862a2 6. cdfc681 7. c2e254c 8. c490073 9. 176013f 10. 2922c1c 11. f7da23e 12. 3b397e3 13. 6f9a274 14. 5de71f6 15. fd4a2c7 16. fae1c5c - #28428: Customer data not retrieved after executing a custom login controller (reported by @pitbulk) has been fixed in #29081 by @complexthings in 2.4-develop branch Related commits: 1. 4f10b5d 2. 1505a36 3. ff99146 4. 8047497 5. dd862a2 6. cdfc681 7. c2e254c 8. c490073 9. 176013f 10. 2922c1c 11. f7da23e 12. 3b397e3 13. 6f9a274 14. 5de71f6 15. fd4a2c7 16. fae1c5c - #29659: [Issue] UPS Shipment Tracking: Show "Delivered On" only when package has actually been delivered (reported by @m2-assistant[bot]) has been fixed in #29080 by @danbtl in 2.4-develop branch Related commits: 1. 5031159 2. 123a4f0 - #29585: [Issue] Prevent side effect on category objects store_id and url_key on save (reported by @m2-assistant[bot]) has been fixed in #28164 by @schmengler in 2.4-develop branch Related commits: 1. 7bd5e25 2. 8bcd2fa 3. 87c5c60 4. 31c5963 5. c051134 6. 6083a7c - #29590: [Issue] Fix SQL query quoting/casting when type is passed to where function (reported by @m2-assistant[bot]) has been fixed in #27980 by @tmotyl in 2.4-develop branch Related commits: 1. 0118d48 2. b8dd6b3 3. 6c41578 4. 4860f31 5. a103b64
2 parents 390505a + 7986939 commit b2e7753

File tree

35 files changed

+991
-110
lines changed

35 files changed

+991
-110
lines changed

.github/stale.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Configuration for probot-stale - https://github.com/probot/stale
2+
3+
# Number of days of inactivity before an Issue or Pull Request becomes stale
4+
daysUntilStale: 76
5+
6+
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
7+
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8+
daysUntilClose: 14
9+
10+
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
11+
onlyLabels: []
12+
13+
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
14+
exemptLabels:
15+
- "Priority: P0"
16+
- "Priority: P1"
17+
- "Priority: P2"
18+
- "Progress: dev in progress"
19+
- "Progress: PR in progress"
20+
- "Progress: done"
21+
- "B2B: GraphQL"
22+
- "Progress: PR Created"
23+
- "PAP"
24+
- "Project: Login as Customer"
25+
- "Project: GraphQL"
26+
27+
# Set to true to ignore issues in a project (defaults to false)
28+
exemptProjects: false
29+
30+
# Set to true to ignore issues in a milestone (defaults to false)
31+
exemptMilestones: false
32+
33+
# Set to true to ignore issues with an assignee (defaults to false)
34+
exemptAssignees: false
35+
36+
# Label to use when marking as stale
37+
staleLabel: "stale issue"
38+
39+
# Comment to post when marking as stale. Set to `false` to disable
40+
markComment: >
41+
This issue has been automatically marked as stale because it has not had
42+
recent activity. It will be closed after 14 days if no further activity occurs. Thank you
43+
for your contributions.
44+
# Comment to post when removing the stale label.
45+
# unmarkComment: >
46+
# Your comment here.
47+
48+
# Comment to post when closing a stale Issue or Pull Request.
49+
# closeComment: >
50+
# Your comment here.
51+
52+
# Limit the number of actions per hour, from 1-30. Default is 30
53+
limitPerRun: 30
54+
55+
# Limit to only `issues` or `pulls`
56+
only: issues
57+
58+
# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
59+
# pulls:
60+
# daysUntilStale: 30
61+
# markComment: >
62+
# This pull request has been automatically marked as stale because it has not had
63+
# recent activity. It will be closed if no further activity occurs. Thank you
64+
# for your contributions.
65+
66+
# issues:
67+
# exemptLabels:
68+
# - confirmed

app/code/Magento/AsynchronousOperations/etc/db_schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<table name="magento_operation" resource="default" engine="innodb" comment="Operation entity">
3535
<column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true"
3636
comment="Operation ID"/>
37-
<column xsi:type="int" name="operation_key" padding="10" unsigned="true" nullable="false"
37+
<column xsi:type="int" name="operation_key" padding="10" unsigned="true" nullable="true"
3838
comment="Operation Key"/>
3939
<column xsi:type="varbinary" name="bulk_uuid" nullable="true" length="39" comment="Related Bulk UUID"/>
4040
<column xsi:type="varchar" name="topic_name" nullable="true" length="255"

app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class CategoryUrlRewriteGenerator
5454
*/
5555
private $mergeDataProviderPrototype;
5656

57+
/**
58+
* @var CategoryRepositoryInterface
59+
*/
60+
private $categoryRepository;
61+
5762
/**
5863
* @var bool
5964
*/
@@ -124,10 +129,11 @@ protected function generateForGlobalScope(
124129
$mergeDataProvider = clone $this->mergeDataProviderPrototype;
125130
$categoryId = $category->getId();
126131
foreach ($category->getStoreIds() as $storeId) {
127-
$category->setStoreId($storeId);
128132
if (!$this->isGlobalScope($storeId)
129133
&& $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls)
130134
) {
135+
$category = clone $category; // prevent undesired side effects on original object
136+
$category->setStoreId($storeId);
131137
$this->updateCategoryUrlForStore($storeId, $category);
132138
$mergeDataProvider->merge($this->generateForSpecificStoreView($storeId, $category, $rootCategoryId));
133139
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function testGenerationForGlobalScope()
158158
],
159159
$this->categoryUrlRewriteGenerator->generate($this->category, false, $categoryId)
160160
);
161+
$this->assertEquals(0, $this->category->getStoreId(), 'Store ID should not have been modified');
161162
}
162163

163164
/**

app/code/Magento/Checkout/view/frontend/layout/checkout_cart_sidebar_item_renderers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</item>
2222
<item name="children" xsi:type="array">
2323
<item name="item.renderer" xsi:type="array">
24-
<item name="component" xsi:type="string">uiComponent</item>
24+
<item name="component" xsi:type="string">Magento_Checkout/js/view/cart-item-renderer</item>
2525
<item name="config" xsi:type="array">
2626
<item name="displayArea" xsi:type="string">defaultRenderer</item>
2727
<item name="template" xsi:type="string">Magento_Checkout/minicart/item/default</item>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'uiComponent'
8+
], function (Component) {
9+
'use strict';
10+
11+
return Component.extend({
12+
/**
13+
* Prepare the product name value to be rendered as HTML
14+
*
15+
* @param {String} productName
16+
* @return {String}
17+
*/
18+
getProductNameUnsanitizedHtml: function (productName) {
19+
// product name has already escaped on backend
20+
return productName;
21+
},
22+
23+
/**
24+
* Prepare the given option value to be rendered as HTML
25+
*
26+
* @param {String} optionValue
27+
* @return {String}
28+
*/
29+
getOptionValueUnsanitizedHtml: function (optionValue) {
30+
// option value has already escaped on backend
31+
return optionValue;
32+
}
33+
});
34+
});

app/code/Magento/Checkout/view/frontend/web/template/minicart/item/default.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
<div class="product-item-details">
2525
<strong class="product-item-name">
2626
<!-- ko if: product_has_url -->
27-
<a data-bind="attr: {href: product_url}, html: product_name"></a>
27+
<a data-bind="attr: {href: product_url}, html: $parent.getProductNameUnsanitizedHtml(product_name)"></a>
2828
<!-- /ko -->
2929
<!-- ko ifnot: product_has_url -->
30-
<!-- ko text: product_name --><!-- /ko -->
30+
<span data-bind="html: $parent.getProductNameUnsanitizedHtml(product_name)"></span>
3131
<!-- /ko -->
3232
</strong>
3333

@@ -42,10 +42,10 @@
4242
<dt class="label"><!-- ko text: option.label --><!-- /ko --></dt>
4343
<dd class="values">
4444
<!-- ko if: Array.isArray(option.value) -->
45-
<span data-bind="html: option.value.join('<br>')"></span>
45+
<span data-bind="html: $parents[1].getOptionValueUnsanitizedHtml(option.value.join('<br/>'))"></span>
4646
<!-- /ko -->
4747
<!-- ko if: (!Array.isArray(option.value) && ['file', 'html'].includes(option.option_type)) -->
48-
<span data-bind="html: option.value"></span>
48+
<span data-bind="html: $parents[1].getOptionValueUnsanitizedHtml(option.value)"></span>
4949
<!-- /ko -->
5050
<!-- ko if: (!Array.isArray(option.value) && !['file', 'html'].includes(option.option_type)) -->
5151
<span data-bind="text: option.value"></span>

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define([
7878
var parameters;
7979

8080
sectionNames = sectionConfig.filterClientSideSections(sectionNames);
81-
parameters = _.isArray(sectionNames) ? {
81+
parameters = _.isArray(sectionNames) && sectionNames.indexOf('*') < 0 ? {
8282
sections: sectionNames.join(',')
8383
} : [];
8484
parameters['force_new_section_timestamp'] = forceNewSectionTimestamp;

app/code/Magento/Directory/etc/zip_codes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
</zip>
6565
<zip countryCode="BR">
6666
<codes>
67-
<code id="pattern_1" active="true" example="12345">^[0-9]{5}$</code>
67+
<code id="pattern_1" active="true" example="12345678">^[0-9]{8}$</code>
6868
<code id="pattern_2" active="true" example="12345-678">^[0-9]{5}\-[0-9]{3}$</code>
6969
</codes>
7070
</zip>

app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiUsedInCategoryFilterTest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectSecondImageToDelete">
2828
<argument name="imageName" value="{{UpdatedImageDetails.title}}"/>
2929
</actionGroup>
30-
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clikDeleteSelectedButton"/>
30+
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clickDeleteSelectedButton"/>
3131
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>
3232
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
3333
<deleteData createDataKey="category" stepKey="deleteCategory"/>
@@ -37,6 +37,8 @@
3737
<argument name="category" value="$$category$$"/>
3838
</actionGroup>
3939
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
40+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilter"/>
41+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetGridToDefaultView"/>
4042
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
4143
<argument name="image" value="ImageUpload3"/>
4244
</actionGroup>
@@ -50,6 +52,8 @@
5052
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="clickAddSelectedContentImage"/>
5153
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
5254
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploaderAgain"/>
55+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilterAgain"/>
56+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetGridToDefaultViewAgain"/>
5357
<actionGroup ref="AdminEnhancedMediaGalleryExpandFilterActionGroup" stepKey="expandFilters"/>
5458
<actionGroup ref="AdminEnhancedMediaGallerySelectUsedInFilterActionGroup" stepKey="setUsedInFilter">
5559
<argument name="filterName" value="Used in Categories"/>

app/code/Magento/MediaGalleryCatalogUi/Test/Mftf/Test/AdminMediaGalleryCatalogUiVerifyUsedInLinkProductGridTest.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<after>
3030
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
3131
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
32+
<actionGroup ref="AdminOpenCatalogProductPageActionGroup" stepKey="goToProductCatalogPage"/>
33+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetProductGridToDefaultView"/>
3234
<deleteData createDataKey="category" stepKey="deleteCategory"/>
3335
</after>
3436
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchProduct">
@@ -42,6 +44,10 @@
4244
<click selector="{{CatalogWYSIWYGSection.InsertImageIcon}}" stepKey="clickInsertImageIcon" />
4345
<waitForPageLoad stepKey="waitForPageLoad" />
4446
<actionGroup ref="ClickBrowseBtnOnUploadPopupActionGroup" stepKey="clickBrowserBtn"/>
47+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilter"/>
48+
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectWysiwygFolder">
49+
<argument name="name" value="wysiwyg"/>
50+
</actionGroup>
4551
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
4652
<argument name="image" value="ImageUpload3"/>
4753
</actionGroup>
@@ -51,6 +57,8 @@
5157
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="clickAddSelectedContentImage"/>
5258
<actionGroup ref="AdminMediaGalleryClickOkButtonTinyMce4ActionGroup" stepKey="clickOkButton"/>
5359
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
60+
<actionGroup ref="AdminOpenCatalogProductPageActionGroup" stepKey="goToProductCatalogPage"/>
61+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetProductGridToDefaultView"/>
5462

5563
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openStandaloneMediaGallery"/>
5664
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="openViewImageDetails"/>
@@ -64,15 +72,14 @@
6472
<deleteData createDataKey="product" stepKey="deleteProduct"/>
6573
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openMediaGallery"/>
6674

67-
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="openViewImageDetailsToVerfifyEmptyUsedIn"/>
75+
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="openViewImageDetailsToVerifyEmptyUsedIn"/>
6876
<actionGroup ref="AssertAdminEnhancedMediaGalleryUsedInSectionNotDisplayedActionGroup" stepKey="assertThereIsNoUsedInSection"/>
6977
<actionGroup ref="AdminEnhancedMediaGalleryCloseViewDetailsActionGroup" stepKey="closeDetails"/>
7078
<actionGroup ref="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup" stepKey="enableMassActionToDeleteImages"/>
7179
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectFirstImageToDelete">
7280
<argument name="imageName" value="{{ImageMetadata.title}}"/>
7381
</actionGroup>
74-
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clikDeleteSelectedButton"/>
82+
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clickDeleteSelectedButton"/>
7583
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>
76-
7784
</test>
7885
</tests>

app/code/Magento/MediaGalleryRenditions/Model/Config.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
class Config
1919
{
2020
private const TABLE_CORE_CONFIG_DATA = 'core_config_data';
21-
private const XML_PATH_ENABLED = 'system/media_gallery/enabled';
21+
private const XML_PATH_MEDIA_GALLERY_ENABLED = 'system/media_gallery/enabled';
22+
private const XML_PATH_ENABLED = 'system/media_gallery_renditions/enabled';
2223
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH = 'system/media_gallery_renditions/width';
2324
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH = 'system/media_gallery_renditions/height';
2425

@@ -49,6 +50,16 @@ public function __construct(
4950
*
5051
* @return bool
5152
*/
53+
public function isMediaGalleryEnabled(): bool
54+
{
55+
return $this->scopeConfig->isSetFlag(self::XML_PATH_MEDIA_GALLERY_ENABLED);
56+
}
57+
58+
/**
59+
* Should the renditions be inserted in the content instead of original image
60+
*
61+
* @return bool
62+
*/
5263
public function isEnabled(): bool
5364
{
5465
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);

app/code/Magento/MediaGalleryRenditions/Plugin/SetRenditionPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function beforeExecute(
9191
$storeId
9292
];
9393

94-
if (!$this->config->isEnabled()) {
94+
if (!$this->config->isEnabled() || !$this->config->isMediaGalleryEnabled()) {
9595
return $arguments;
9696
}
9797

app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
namespace Magento\MediaGalleryRenditions\Plugin;
99

1010
use Magento\Framework\App\Config\Value;
11+
use Magento\MediaGalleryRenditions\Model\Config;
1112
use Magento\MediaGalleryRenditions\Model\Queue\ScheduleRenditionsUpdate;
1213

1314
/**
1415
* Update renditions if corresponding configuration changes
1516
*/
1617
class UpdateRenditionsOnConfigChange
1718
{
19+
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH = 'system/media_gallery_renditions/enabled';
1820
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH = 'system/media_gallery_renditions/width';
1921
private const XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH = 'system/media_gallery_renditions/height';
2022

@@ -24,10 +26,17 @@ class UpdateRenditionsOnConfigChange
2426
private $scheduleRenditionsUpdate;
2527

2628
/**
29+
* @var Config
30+
*/
31+
private $config;
32+
33+
/**
34+
* @param Config $config
2735
* @param ScheduleRenditionsUpdate $scheduleRenditionsUpdate
2836
*/
29-
public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
37+
public function __construct(Config $config, ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
3038
{
39+
$this->config = $config;
3140
$this->scheduleRenditionsUpdate = $scheduleRenditionsUpdate;
3241
}
3342

@@ -41,7 +50,13 @@ public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
4150
*/
4251
public function afterSave(Value $config, Value $result): Value
4352
{
44-
if ($this->isRenditionsValue($result) && $result->isValueChanged()) {
53+
if ($this->isRenditionsEnabled($result)) {
54+
$this->scheduleRenditionsUpdate->execute();
55+
56+
return $result;
57+
}
58+
59+
if ($this->config->isEnabled() && $this->isRenditionsValue($result) && $result->isValueChanged()) {
4560
$this->scheduleRenditionsUpdate->execute();
4661
}
4762

@@ -59,4 +74,17 @@ private function isRenditionsValue(Value $value): bool
5974
return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH
6075
|| $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH;
6176
}
77+
78+
/**
79+
* Determine if media gallery renditions is enabled based on configuration value
80+
*
81+
* @param Value $value
82+
* @return bool
83+
*/
84+
private function isRenditionsEnabled(Value $value): bool
85+
{
86+
return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH
87+
&& $value->isValueChanged()
88+
&& $value->getValue();
89+
}
6290
}

app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
<section id="system">
1111
<group id="media_gallery_renditions" translate="label" type="text" sortOrder="1010" showInDefault="1" showInWebsite="0" showInStore="0">
1212
<label>Media Gallery Image Optimization</label>
13+
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
14+
<label>Enable Image Optimization</label>
15+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
16+
</field>
1317
<comment>Resize images to improve performance and decrease the file size. When you use an image from Media Gallery on the storefront, the smaller image is generated and placed instead of the original.
1418
Changing these settings will update all generated images.</comment>
15-
<field id="width" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
19+
<field id="width" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
1620
<label>Maximum Width</label>
1721
<validate>validate-zero-or-greater validate-digits</validate>
1822
<comment>Enter the maximum width of an image in pixels.</comment>
1923
</field>
20-
<field id="height" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
24+
<field id="height" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
2125
<label>Maximum Height</label>
2226
<validate>validate-zero-or-greater validate-digits</validate>
2327
<comment>Enter the maximum height of an image in pixels.</comment>

0 commit comments

Comments
 (0)