Skip to content

Commit 20d3f40

Browse files
committed
Fix minicart promotion region not rendering
The minicart promotion region was not rendering due to a wrongly written check for the number of items in the 'promotion' region. The code checked for the length property of the observable returned from the getRegion method instead of the array it contained. A fast way would have been to add the missing parentheses to the check (and I made antoher PR doing just that), but I felt that the getRegion(region)().length pattern is a bit hard to read and easy to make a mistake with. Therefore, this commit adds a new method to the lib/core/collection.js component of the Magento_Ui module that can be used to check if a region has any elements associated with it. This commit also replaces all occurences of getRegion(region)().length with a call to the new method.
1 parent 65763df commit 20d3f40

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

app/code/Magento/Catalog/view/base/web/template/product/list/listing.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
<render args="$col.getBody()"/>
2626
</fastForEach>
2727

28-
<div if="getRegion('action-primary-area')().length || getRegion('action-secondary-area')().length"
28+
<div if="regionHasElements('action-primary-area') || regionHasElements('action-secondary-area')"
2929
class="product-item-actions">
30-
<div class="actions-primary" if="getRegion('action-primary-area')().length">
30+
<div class="actions-primary" if="regionHasElements('action-primary-area')">
3131
<fastForEach args="data: getRegion('action-primary-area'), as: '$col'" >
3232
<render args="$col.getBody()"/>
3333
</fastForEach>
3434
</div>
3535

36-
<div if="getRegion('action-secondary-area')().length"
36+
<div if="regionHasElements('action-secondary-area')"
3737
class="actions-secondary"
3838
data-role="add-to-links">
3939
<fastForEach args="data: getRegion('action-secondary-area'), as: '$col'" >
@@ -42,7 +42,7 @@
4242
</div>
4343
</div>
4444

45-
<div if="getRegion('description-area')().length"
45+
<div if=regionHasElements('description-area')"
4646
class="product-item-description">
4747
<fastForEach args="data: getRegion('description-area'), as: '$col'" >
4848
<render args="$col.getBody()"/>

app/code/Magento/Checkout/view/frontend/web/js/view/payment/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ define([
203203
*/
204204
isPaymentMethodsAvailable: function () {
205205
return _.some(this.paymentGroupsList(), function (group) {
206-
return this.getRegion(group.displayArea)().length;
206+
return this.regionHasElements(group.displayArea);
207207
}, this);
208208
},
209209

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
</div>
9898
</div>
9999

100-
<div id="minicart-widgets" class="minicart-widgets" if="getRegion('promotion').length">
100+
<div id="minicart-widgets" class="minicart-widgets" if="regionHasElements('promotion')">
101101
<each args="getRegion('promotion')" render=""/>
102102
</div>
103103
</div>

app/code/Magento/Checkout/view/frontend/web/template/payment-methods/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class="items payment-methods">
99
<div repeat="foreach: paymentGroupsList, item: '$group'"
1010
class="payment-group">
11-
<div if="getRegion($group().displayArea)().length"
11+
<div if="regionHasElements($group().displayArea)"
1212
translate="getGroupTitle($group)"
1313
class="step-title"
1414
data-role="title">

app/code/Magento/Ui/view/base/web/js/lib/core/collection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ define([
214214
return regions[name];
215215
},
216216

217+
/**
218+
* Checks if the specified region has any elements
219+
* associated with it.
220+
*
221+
* @param {String} name
222+
* @returns {Boolean}
223+
*/
224+
regionHasElements: function (name) {
225+
var region = this.getRegion(name);
226+
return region().length > 0;
227+
},
228+
217229
/**
218230
* Replaces specified regions' data with a provided one.
219231
* Creates region if it was not created yet.

0 commit comments

Comments
 (0)