Skip to content

Commit b333b0f

Browse files
committed
MAGETWO-87955: Mini Cart is not getting updated while removing product from mini cart in IE11
1 parent 8c0ac6d commit b333b0f

File tree

2 files changed

+84
-3
lines changed
  • app/code/Magento/Checkout/view/frontend/web/js
  • dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js

2 files changed

+84
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ define([
99
'Magento_Customer/js/customer-data',
1010
'Magento_Ui/js/modal/alert',
1111
'Magento_Ui/js/modal/confirm',
12+
'underscore',
1213
'jquery/ui',
1314
'mage/decorate',
1415
'mage/collapsible',
1516
'mage/cookies'
16-
], function ($, authenticationPopup, customerData, alert, confirm) {
17+
], function ($, authenticationPopup, customerData, alert, confirm, _) {
1718
'use strict';
1819

1920
$.widget('mage.sidebar', {
@@ -241,11 +242,13 @@ define([
241242
* @private
242243
*/
243244
_removeItemAfter: function (elem) {
244-
var productData = customerData.get('cart')().items.find(function (item) {
245+
var productData = _.find(customerData.get('cart')().items, function (item) {
245246
return Number(elem.data('cart-item')) === Number(item['item_id']);
246247
});
247248

248-
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
249+
if (!_.isUndefined(productData)) {
250+
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
251+
}
249252
},
250253

251254
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
/* eslint-disable max-nested-callbacks */
6+
/*jscs:disable jsDoc*/
7+
8+
define([
9+
'squire',
10+
'jquery',
11+
'ko'
12+
], function (Squire, $, ko) {
13+
'use strict';
14+
15+
describe('Magento_Checkout/js/sidebar', function () {
16+
var injector = new Squire(),
17+
mocks = {
18+
'Magento_Customer/js/customer-data': {
19+
get: function () {
20+
return ko.observable();
21+
}
22+
}
23+
},
24+
sidebar;
25+
26+
beforeEach(function (done) {
27+
injector.mock(mocks);
28+
injector.require(['Magento_Checkout/js/sidebar'], function (Constr) {
29+
sidebar = new Constr;
30+
done();
31+
});
32+
});
33+
34+
describe('Check remove mini-cart item callback.', function () {
35+
var cartData = {
36+
'items': [
37+
{
38+
'item_id': 1,
39+
'product_sku': 'bundle'
40+
},
41+
{
42+
'item_id': 5,
43+
'product_sku': 'simple'
44+
},
45+
{
46+
'item_id': 7,
47+
'product_sku': 'configurable'
48+
}
49+
]
50+
},
51+
cart = ko.observable(cartData);
52+
53+
beforeEach(function () {
54+
spyOn(jQuery.fn, 'trigger');
55+
spyOn(mocks['Magento_Customer/js/customer-data'], 'get').and.returnValue(cart);
56+
});
57+
58+
it('Method "_removeItemAfter" is defined', function () {
59+
expect(sidebar._removeItemAfter).toBeDefined();
60+
});
61+
62+
it('Cart item is exists', function () {
63+
var elem = $('<input>').data('cart-item', 5);
64+
65+
sidebar._removeItemAfter(elem);
66+
expect(mocks['Magento_Customer/js/customer-data'].get).toHaveBeenCalledWith('cart');
67+
expect(jQuery('body').trigger).toHaveBeenCalledWith('ajax:removeFromCart', 'simple');
68+
});
69+
70+
it('Cart item doesn\'t exists', function () {
71+
var elem = $('<input>').data('cart-item', 100);
72+
73+
sidebar._removeItemAfter(elem);
74+
expect(jQuery('body').trigger).not.toHaveBeenCalled();
75+
});
76+
});
77+
});
78+
});

0 commit comments

Comments
 (0)