Skip to content

Commit 6dc0956

Browse files
author
Sergey Semenov
committed
MAGETWO-21349: Advanced Mini Cart
1 parent 42e0710 commit 6dc0956

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function execute()
8484
protected function jsonResponse($error = '')
8585
{
8686
$response = $this->sidebar->getResponseData($error);
87-
if (isset($response['cleanup']) && (bool)$response['cleanup']) {
88-
$resultPage = $this->resultPageFactory->create();
89-
$block = $resultPage->getLayout()->getBlock('minicart.content')->toHtml();
90-
$response['content'] = $block;
91-
}
87+
88+
$resultPage = $this->resultPageFactory->create();
89+
$block = $resultPage->getLayout()->getBlock('minicart.content')->toHtml();
90+
$response['content'] = $block;
91+
9292
return $this->getResponse()->representJson(
9393
$this->jsonHelper->jsonEncode($response)
9494
);

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

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,40 @@ define([
1818
scrollHeight: 0,
1919

2020
_create: function() {
21+
this._initContent();
22+
},
23+
24+
_initContent: function() {
2125
var self = this;
2226

2327
this.element.decorate('list', this.options.isRecursive);
2428

29+
$(this.options.button.close).click(function(event) {
30+
event.stopPropagation();
31+
$(self.options.targetElement).dropdownDialog("close");
32+
});
33+
2534
$(this.options.button.checkout).on('click', $.proxy(function() {
2635
location.href = this.options.url.checkout;
2736
}, this));
2837

29-
$(this.options.item.qty).keyup(function(event) {
30-
self._showButton($(this));
31-
});
32-
$(this.options.item.button).click(function(event) {
33-
event.stopPropagation();
34-
self._updateQty($(this))
35-
});
36-
3738
$(this.options.button.remove).click(function(event) {
3839
event.stopPropagation();
3940
if (confirm(self.options.confirmMessage)) {
4041
self._removeItem($(this));
4142
}
4243
});
4344

44-
this._initCloseButton();
45-
this._calcHeight();
46-
this._isOverflowed();
47-
},
48-
49-
/**
50-
* Add event on "Close" button click
51-
*
52-
* @private
53-
*/
54-
_initCloseButton: function() {
55-
var self = this;
56-
$(this.options.button.close).click(function(event) {
45+
$(this.options.item.qty).keyup(function() {
46+
self._showItemButton($(this));
47+
});
48+
$(this.options.item.button).click(function(event) {
5749
event.stopPropagation();
58-
$(self.options.targetElement).dropdownDialog("close");
50+
self._updateItemQty($(this))
5951
});
52+
53+
this._calcHeight();
54+
this._isOverflowed();
6055
},
6156

6257
/**
@@ -73,16 +68,16 @@ define([
7368
}
7469
},
7570

76-
_showButton: function(elem) {
71+
_showItemButton: function(elem) {
7772
var itemId = elem.data('cart-item');
7873
var itemQty = elem.data('item-qty');
7974
if (this._isValidQty(itemQty, elem.val())) {
8075
$('#update-cart-item-' + itemId).show('fade', 300);
8176
} else if (elem.val() == 0) {
8277
elem.val(itemQty);
83-
this._hideButton(elem);
78+
this._hideItemButton(elem);
8479
} else {
85-
this._hideButton(elem);
80+
this._hideItemButton(elem);
8681
}
8782
},
8883

@@ -99,17 +94,17 @@ define([
9994
&& (changed - 0 > 0);
10095
},
10196

102-
_hideButton: function(elem) {
97+
_hideItemButton: function(elem) {
10398
var itemId = elem.data('cart-item');
10499
$('#update-cart-item-' + itemId).hide('fade', 300);
105100
},
106101

107-
_updateQty: function(elem) {
102+
_updateItemQty: function(elem) {
108103
var itemId = elem.data('cart-item');
109104
this._ajax(this.options.url.update, {
110105
item_id: itemId,
111106
item_qty: $('#cart-item-' + itemId + '-qty').val()
112-
}, elem, this._updateQtyAfter);
107+
}, elem, this._updateItemQtyAfter);
113108
},
114109

115110
/**
@@ -119,14 +114,14 @@ define([
119114
* @param response
120115
* @private
121116
*/
122-
_updateQtyAfter: function(elem, response) {
117+
_updateItemQtyAfter: function(elem, response) {
123118
if ($.type(response.data) === 'object') {
124119
this._refreshQty(response.data.summary_qty, response.data.summary_text);
125120
this._refreshSubtotal(response.data.subtotal);
126121
this._refreshShowcart(response.data.summary_qty, response.data.summary_text);
127122
this._refreshItemQty(elem, response.data.summary_qty);
128123
}
129-
this._hideButton(elem);
124+
this._hideItemButton(elem);
130125
},
131126

132127
_removeItem: function(elem) {
@@ -145,19 +140,13 @@ define([
145140
*/
146141
_removeItemAfter: function(elem, response) {
147142
if ($.type(response.data) === 'object') {
148-
this._refreshQty(response.data.summary_qty, response.data.summary_text);
149-
this._refreshSubtotal(response.data.subtotal);
150143
this._refreshShowcart(response.data.summary_qty, response.data.summary_text);
151144
}
145+
$(this.options.minicart.content).html($.trim(response.content));
152146
if (response.cleanup === true) {
153-
$(this.options.minicart.content).replaceWith($.trim(response.content));
154147
$(this.options.showcart.parent).addClass('empty');
155-
this._initCloseButton();
156-
} else {
157-
elem.closest('li').remove();
158-
this._calcHeight();
159-
this._isOverflowed();
160148
}
149+
this._initContent();
161150
},
162151

163152
/**

0 commit comments

Comments
 (0)