Skip to content

Commit 6490864

Browse files
author
Ievgen Shakhsuvarov
committed
MAGETWO-40150: Empty space is displayed in Mini Shopping Cart where the Product was deleted
1 parent 180ca97 commit 6490864

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ define([
1010
'Magento_Customer/js/customer-data',
1111
'Magento_Ui/js/modal/alert',
1212
'Magento_Ui/js/modal/confirm',
13-
'Magento_Customer/js/customer-data',
1413
"jquery/ui",
1514
"mage/decorate"
16-
], function($, authenticationPopup, customerData, alert, confirm, customerData){
15+
], function($, authenticationPopup, customerData, alert, confirm){
1716

1817
$.widget('mage.sidebar', {
1918
options: {
@@ -27,14 +26,16 @@ define([
2726
* @private
2827
*/
2928
_create: function () {
30-
var self = this;
31-
3229
this._initContent();
33-
customerData.get('cart').subscribe(function () {
34-
$(self.options.targetElement).trigger('contentUpdated');
35-
self._calcHeight();
36-
self._isOverflowed();
37-
});
30+
},
31+
32+
/**
33+
* Update sidebar block.
34+
*/
35+
update: function () {
36+
$(this.options.targetElement).trigger('contentUpdated');
37+
this._calcHeight();
38+
this._isOverflowed();
3839
},
3940

4041
_initContent: function() {
@@ -219,6 +220,7 @@ define([
219220
console.log(JSON.stringify(error));
220221
});
221222
},
223+
222224
/**
223225
* Calculate height of minicart list
224226
*
@@ -228,22 +230,18 @@ define([
228230
var self = this,
229231
height = 0,
230232
counter = this.options.maxItemsVisible,
231-
target = $(this.options.minicart.list)
232-
.clone()
233-
.attr('style', 'position: absolute !important; top: -10000 !important;')
234-
.appendTo('body');
233+
target = $(this.options.minicart.list);
234+
235+
target.children().each(function () {
236+
var outerHeight = $(this).outerHeight();
235237

236-
this.scrollHeight = 0;
237-
target.children().each(function() {
238238
if (counter-- > 0) {
239-
height += $(this).height();
239+
height += outerHeight;
240240
}
241-
self.scrollHeight += $(this).height();
241+
self.scrollHeight += outerHeight;
242242
});
243243

244-
target.remove();
245-
246-
$(this.options.minicart.list).css('height', height);
244+
target.height(height);
247245
}
248246
});
249247

app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ define([
2020
});
2121

2222
function initSidebar() {
23+
if (minicart.data('mageSidebar')) {
24+
minicart.sidebar('update');
25+
}
26+
2327
if (!$('[data-role=product-item]').length) {
2428
return false;
2529
}

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
@@ -67,7 +67,7 @@
6767
<div data-action="scroll" class="minicart-items-wrapper">
6868
<ol id="mini-cart" class="minicart-items" data-bind="foreach: { data: cart().items, as: 'item' }">
6969
<!-- ko foreach: $parent.getRegion($parent.getItemRenderer(item.product_type)) -->
70-
<!-- ko template: {name: getTemplate(), data: item, afterRender: $parents[1].initSidebar()} --><!-- /ko -->
70+
<!-- ko template: {name: getTemplate(), data: item, afterRender: function() {$parents[1].initSidebar()}} --><!-- /ko -->
7171
<!-- /ko -->
7272
</ol>
7373
</div>

0 commit comments

Comments
 (0)