Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minicart promotion region not rendering #25373 #25375

Merged
merged 5 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
<render args="$col.getBody()"/>
</fastForEach>

<div if="getRegion('action-primary-area')().length || getRegion('action-secondary-area')().length"
<div if="regionHasElements('action-primary-area') || regionHasElements('action-secondary-area')"
class="product-item-actions">
<div class="actions-primary" if="getRegion('action-primary-area')().length">
<div class="actions-primary" if="regionHasElements('action-primary-area')">
<fastForEach args="data: getRegion('action-primary-area'), as: '$col'" >
<render args="$col.getBody()"/>
</fastForEach>
</div>

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

<div if="getRegion('description-area')().length"
<div if="regionHasElements('description-area')"
class="product-item-description">
<fastForEach args="data: getRegion('description-area'), as: '$col'" >
<render args="$col.getBody()"/>
Expand All @@ -54,4 +54,4 @@
</ol>
</div>
</div>
</div>
</div>
16 changes: 13 additions & 3 deletions app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ define([

/**
* Get cart param by name.
*
* @param {String} name
* @returns {*}
*/
getCartParam: function (name) {
getCartParamUnsanitizedHtml: function (name) {
if (!_.isUndefined(name)) {
if (!this.cart.hasOwnProperty(name)) {
this.cart[name] = ko.observable();
Expand All @@ -175,12 +176,21 @@ define([
return this.cart[name]();
},

/**
* @deprecated please use getCartParamUnsanitizedHtml.
* @param {String} name
* @returns {*}
*/
getCartParam: function (name) {
return this.getCartParamUnsanitizedHtml(name);
},

/**
* Returns array of cart items, limited by 'maxItemsToDisplay' setting
* @returns []
*/
getCartItems: function () {
var items = this.getCartParam('items') || [];
var items = this.getCartParamUnsanitizedHtml('items') || [];

items = items.slice(parseInt(-this.maxItemsToDisplay, 10));

Expand All @@ -192,7 +202,7 @@ define([
* @returns {Number}
*/
getCartLineItemsCount: function () {
var items = this.getCartParam('items') || [];
var items = this.getCartParamUnsanitizedHtml('items') || [];

return parseInt(items.length, 10);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ define([
*/
isPaymentMethodsAvailable: function () {
return _.some(this.paymentGroupsList(), function (group) {
return this.getRegion(group.displayArea)().length;
return this.regionHasElements(group.displayArea);
}, this);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"
translate="'Proceed to Checkout'"
/>
<div data-bind="html: getCartParam('extra_actions')"></div>
<div data-bind="html: getCartParamUnsanitizedHtml('extra_actions')"></div>
</div>
</div>
</if>
Expand Down Expand Up @@ -97,7 +97,7 @@
</div>
</div>

<div id="minicart-widgets" class="minicart-widgets" if="getRegion('promotion').length">
<div id="minicart-widgets" class="minicart-widgets" if="regionHasElements('promotion')">
<each args="getRegion('promotion')" render=""/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class="items payment-methods">
<div repeat="foreach: paymentGroupsList, item: '$group'"
class="payment-group">
<div if="getRegion($group().displayArea)().length"
<div if="regionHasElements($group().displayArea)"
translate="getGroupTitle($group)"
class="step-title"
data-role="title">
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/lib/core/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ define([
return regions[name];
},

/**
* Checks if the specified region has any elements
* associated with it.
*
* @param {String} name
* @returns {Boolean}
*/
regionHasElements: function (name) {
var region = this.getRegion(name);

return region().length > 0;
},

/**
* Replaces specified regions' data with a provided one.
* Creates region if it was not created yet.
Expand Down