Skip to content

Commit 808f0f8

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-61066' into 2.0-develop-pr6
2 parents ef030c0 + 07a31bc commit 808f0f8

File tree

8 files changed

+96
-34
lines changed

8 files changed

+96
-34
lines changed

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public function getConfig()
6464
'removeItemUrl' => $this->getRemoveItemUrl(),
6565
'imageTemplate' => $this->getImageHtmlTemplate(),
6666
'baseUrl' => $this->getBaseUrl(),
67-
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
67+
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount(),
68+
'websiteId' => $this->_storeManager->getStore()->getWebsiteId()
6869
];
6970
}
7071

app/code/Magento/Checkout/CustomerData/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function getSectionData()
9696
'items' => $this->getRecentItems(),
9797
'extra_actions' => $this->layout->createBlock('Magento\Catalog\Block\ShortcutButtons')->toHtml(),
9898
'isGuestCheckoutAllowed' => $this->isGuestCheckoutAllowed(),
99+
'website_id' => $this->getQuote()->getStore()->getWebsiteId()
99100
];
100101
}
101102

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public function testGetTotalsHtml()
123123

124124
public function testGetConfig()
125125
{
126-
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
126+
$websiteId = 100;
127+
$storeMock = $this->getMock(\Magento\Store\Model\Store::class, [], [], '', false);
127128

128129
$shoppingCartUrl = 'http://url.com/cart';
129130
$checkoutUrl = 'http://url.com/checkout';
@@ -139,7 +140,8 @@ public function testGetConfig()
139140
'removeItemUrl' => $removeItemUrl,
140141
'imageTemplate' => $imageTemplate,
141142
'baseUrl' => $baseUrl,
142-
'minicartMaxItemsVisible' => 3
143+
'minicartMaxItemsVisible' => 3,
144+
'websiteId' => 100
143145
];
144146

145147
$valueMap = [
@@ -156,7 +158,7 @@ public function testGetConfig()
156158
$this->urlBuilderMock->expects($this->exactly(4))
157159
->method('getUrl')
158160
->willReturnMap($valueMap);
159-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
161+
$this->storeManagerMock->expects($this->exactly(2))->method('getStore')->willReturn($storeMock);
160162
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
161163
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);
162164

@@ -167,6 +169,8 @@ public function testGetConfig()
167169
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
168170
)->willReturn(3);
169171

172+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
173+
170174
$this->assertEquals($expectedResult, $this->model->getConfig());
171175
}
172176

app/code/Magento/Checkout/Test/Unit/CustomerData/CartTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ public function testGetSectionData()
9393
$productRewrite = [$productId => ['rewrite' => 'product']];
9494
$itemData = ['item' => 'data'];
9595
$shortcutButtonsHtml = '<span>Buttons</span>';
96+
$websiteId = 100;
9697

97-
$subtotalMock = $this->getMock('\Magento\Framework\DataObject', ['getValue'], [], '', false);
98+
$subtotalMock = $this->getMock(\Magento\Framework\DataObject::class, ['getValue'], [], '', false);
9899
$subtotalMock->expects($this->once())->method('getValue')->willReturn($subtotalValue);
99100
$totals = ['subtotal' => $subtotalMock];
100101

101102
$quoteMock = $this->getMock(
102-
'\Magento\Quote\Model\Quote',
103-
['getTotals', 'getHasError', 'getAllVisibleItems'],
103+
\Magento\Quote\Model\Quote::class,
104+
['getTotals', 'getHasError', 'getAllVisibleItems', 'getStore'],
104105
[],
105106
'',
106107
false
@@ -116,11 +117,15 @@ public function testGetSectionData()
116117
->willReturn($subtotalValue);
117118
$this->checkoutHelperMock->expects($this->once())->method('canOnepageCheckout')->willReturn(true);
118119

119-
$quoteItemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', ['getProduct', 'getStoreId'], [], '', false);
120+
$quoteItemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['getProduct', 'getStoreId'], [], '', false);
120121
$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([$quoteItemMock]);
121122

123+
$storeMock = $this->getMock(\Magento\Store\Model\System\Store::class, ['getWebsiteId'], [], '', false);
124+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
125+
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);
126+
122127
$productMock = $this->getMock(
123-
'\Magento\Catalog\Model\Product',
128+
\Magento\Catalog\Model\Product::class,
124129
['isVisibleInSiteVisibility', 'getId', 'setUrlDataObject'],
125130
[],
126131
'',
@@ -166,7 +171,8 @@ public function testGetSectionData()
166171
['item' => 'data']
167172
],
168173
'extra_actions' => '<span>Buttons</span>',
169-
'isGuestCheckoutAllowed' => 1
174+
'isGuestCheckoutAllowed' => 1,
175+
'website_id' => $websiteId
170176
];
171177
$this->assertEquals($expectedResult, $this->model->getSectionData());
172178
}

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
data-bind="scope: 'minicart_content'">
1515
<span class="text"><?php /* @escapeNotVerified */ echo __('My Cart'); ?></span>
1616
<span class="counter qty empty"
17-
data-bind="css: { empty: cart().summary_count == 0 }, blockLoader: isLoading">
18-
<span class="counter-number"><!-- ko text: cart().summary_count --><!-- /ko --></span>
17+
data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
18+
<span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
1919
<span class="counter-label">
20-
<!-- ko if: cart().summary_count -->
21-
<!-- ko text: cart().summary_count --><!-- /ko -->
20+
<!-- ko if: getCartParam('summary_count') -->
21+
<!-- ko text: getCartParam('summary_count') --><!-- /ko -->
2222
<!-- ko i18n: 'items' --><!-- /ko -->
2323
<!-- /ko -->
2424
</span>

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,44 @@ define([
7474

7575
return Component.extend({
7676
shoppingCartUrl: window.checkout.shoppingCartUrl,
77+
cart: {},
78+
79+
/**
80+
* @override
81+
*/
7782
initialize: function () {
78-
var self = this;
79-
this._super();
80-
this.cart = customerData.get('cart');
81-
this.cart.subscribe(function () {
83+
var self = this,
84+
cartData = customerData.get('cart');
85+
86+
this.update(cartData());
87+
cartData.subscribe(function (updatedCart) {
8288
addToCartCalls--;
8389
this.isLoading(addToCartCalls > 0);
8490
sidebarInitialized = false;
91+
this.update(updatedCart);
8592
initSidebar();
8693
}, this);
8794
$('[data-block="minicart"]').on('contentLoading', function (event) {
8895
addToCartCalls++;
8996
self.isLoading(true);
9097
});
98+
99+
if (cartData.website_id !== window.checkout.websiteId) {
100+
customerData.reload(['cart'], false);
101+
}
102+
103+
return this._super();
91104
},
92105
isLoading: ko.observable(false),
93106
initSidebar: initSidebar,
94107

108+
/**
109+
* Close mini shopping cart.
110+
*/
111+
closeMinicart: function () {
112+
$('[data-block="minicart"]').find('[data-role="dropdownDialog"]').dropdownDialog('close');
113+
},
114+
95115
/**
96116
* @return {Boolean}
97117
*/
@@ -111,6 +131,36 @@ define([
111131
*/
112132
getItemRenderer: function (productType) {
113133
return this.itemRenderer[productType] || 'defaultRenderer';
134+
},
135+
136+
/**
137+
* Update mini shopping cart content.
138+
*
139+
* @param {Object} updatedCart
140+
* @returns void
141+
*/
142+
update: function (updatedCart) {
143+
_.each(updatedCart, function (value, key) {
144+
if (!this.cart.hasOwnProperty(key)) {
145+
this.cart[key] = ko.observable();
146+
}
147+
this.cart[key](value);
148+
}, this);
149+
},
150+
151+
/**
152+
* Get cart param by name.
153+
* @param {String} name
154+
* @returns {*}
155+
*/
156+
getCartParam: function (name) {
157+
if (!_.isUndefined(name)) {
158+
if (!this.cart.hasOwnProperty(name)) {
159+
this.cart[name] = ko.observable();
160+
}
161+
}
162+
163+
return this.cart[name]();
114164
}
115165
});
116166
});

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<span class="text"><!-- ko i18n: 'My Cart' --><!-- /ko --></span>
1010
<span
1111
class="qty empty"
12-
data-bind="css: { empty: cart().summary_count == 0 },
12+
data-bind="css: { empty: !!getCartParam('summary_count') == false },
1313
attr: { title: $t('Items in Cart') }">
14-
<!-- ko text: cart().summary_count --><!-- /ko -->
14+
<!-- ko text: getCartParam('summary_count') --><!-- /ko -->
1515
</span>
1616
</strong>
1717
</div>
@@ -25,18 +25,18 @@
2525
<span><!-- ko i18n: 'Close' --><!-- /ko --></span>
2626
</button>
2727

28-
<!-- ko if: cart().summary_count -->
28+
<!-- ko if: getCartParam('summary_count') -->
2929
<div class="items-total">
30-
<span class="count"><!-- ko text: cart().summary_count --><!-- /ko --></span>
31-
<!-- ko if: cart().summary_count == 1 -->
30+
<span class="count"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
31+
<!-- ko if: getCartParam('summary_count') == 1 -->
3232
<!-- ko i18n: 'item' --><!-- /ko -->
3333
<!-- /ko -->
34-
<!-- ko if: cart().summary_count > 1 -->
34+
<!-- ko if: getCartParam('summary_count') > 1 -->
3535
<!-- ko i18n: 'items' --><!-- /ko -->
3636
<!-- /ko -->
3737
</div>
3838

39-
<!-- ko if: cart().possible_onepage_checkout -->
39+
<!-- ko if: getCartParam('possible_onepage_checkout') -->
4040
<!-- ko foreach: getRegion('subtotalContainer') -->
4141
<!-- ko template: getTemplate() --><!-- /ko -->
4242
<!-- /ko -->
@@ -46,7 +46,7 @@
4646
<!-- ko template: getTemplate() --><!-- /ko -->
4747
<!-- /ko -->
4848

49-
<!-- ko if: cart().possible_onepage_checkout -->
49+
<!-- ko if: getCartParam('possible_onepage_checkout') -->
5050
<div class="actions">
5151
<div class="primary">
5252
<button
@@ -56,29 +56,29 @@
5656
data-bind="attr: {title: $t('Go to Checkout')}">
5757
<!-- ko i18n: 'Go to Checkout' --><!-- /ko -->
5858
</button>
59-
<div data-bind="html: cart().extra_actions"></div>
59+
<div data-bind="html: getCartParam('extra_actions')"></div>
6060
</div>
6161
</div>
6262
<!-- /ko -->
6363
<!-- /ko -->
6464

65-
<!-- ko if: cart().summary_count -->
65+
<!-- ko if: getCartParam('summary_count') -->
6666
<strong class="subtitle"><!-- ko i18n: 'Recently added item(s)' --><!-- /ko --></strong>
6767
<div data-action="scroll" class="minicart-items-wrapper">
68-
<ol id="mini-cart" class="minicart-items" data-bind="foreach: { data: cart().items, as: 'item' }">
68+
<ol id="mini-cart" class="minicart-items" data-bind="foreach: { data: getCartParam('items'), as: 'item' }">
6969
<!-- ko foreach: $parent.getRegion($parent.getItemRenderer(item.product_type)) -->
7070
<!-- ko template: {name: getTemplate(), data: item, afterRender: function() {$parents[1].initSidebar()}} --><!-- /ko -->
7171
<!-- /ko -->
7272
</ol>
7373
</div>
7474
<!-- /ko -->
7575

76-
<!-- ko ifnot: cart().summary_count -->
76+
<!-- ko ifnot: getCartParam('summary_count') -->
7777
<strong class="subtitle empty" data-bind="visible: closeSidebar()">
7878
<!-- ko i18n: 'You have no items in your shopping cart.' --><!-- /ko -->
7979
</strong>
80-
<!-- ko if: cart().cart_empty_message -->
81-
<p class="minicart empty text"><!-- ko text: cart().cart_empty_message --><!-- /ko --></p>
80+
<!-- ko if: getCartParam('cart_empty_message') -->
81+
<p class="minicart empty text"><!-- ko text: getCartParam('cart_empty_message') --><!-- /ko --></p>
8282

8383
<div class="actions">
8484
<div class="secondary">
@@ -90,7 +90,7 @@
9090
<!-- /ko -->
9191
<!-- /ko -->
9292

93-
<!-- ko if: cart().summary_count -->
93+
<!-- ko if: getCartParam('summary_count') -->
9494
<div class="actions">
9595
<div class="secondary">
9696
<a class="action viewcart" data-bind="attr: {href: shoppingCartUrl}">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66
-->
77
<div class="amount">
8-
<span data-bind="html: cart().subtotal"></span>
8+
<span data-bind="html: getCartParam('subtotal')"></span>
99
</div>

0 commit comments

Comments
 (0)