Skip to content

Commit 9d62762

Browse files
author
Stanislav Idolov
committed
MAGETWO-57062: [Backport] - Issues with minicart in multiwebsite - for 2.1
1 parent 12f3b8f commit 9d62762

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public function getConfig()
6969
'removeItemUrl' => $this->getRemoveItemUrl(),
7070
'imageTemplate' => $this->getImageHtmlTemplate(),
7171
'baseUrl' => $this->getBaseUrl(),
72-
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount()
72+
'minicartMaxItemsVisible' => $this->getMiniCartMaxItemsCount(),
73+
'websiteId' => $this->_storeManager->getStore()->getWebsiteId()
7374
];
7475
}
7576

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function testGetTotalsHtml()
124124
public function testGetConfig()
125125
{
126126
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
127+
$websiteId = 100;
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' => $websiteId
143145
];
144146

145147
$valueMap = [
@@ -156,8 +158,9 @@ 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);
163+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
161164
$this->imageHelper->expects($this->once())->method('getFrame')->willReturn(false);
162165

163166
$this->scopeConfigMock->expects($this->once())

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function testGetSectionData()
9090
$subtotalValue = 200;
9191
$productId = 10;
9292
$storeId = 20;
93+
$websiteId = 100;
9394
$productRewrite = [$productId => ['rewrite' => 'product']];
9495
$itemData = ['item' => 'data'];
9596
$shortcutButtonsHtml = '<span>Buttons</span>';
@@ -100,7 +101,7 @@ public function testGetSectionData()
100101

101102
$quoteMock = $this->getMock(
102103
'\Magento\Quote\Model\Quote',
103-
['getTotals', 'getHasError', 'getAllVisibleItems'],
104+
['getTotals', 'getHasError', 'getAllVisibleItems', 'getStore'],
104105
[],
105106
'',
106107
false
@@ -109,6 +110,10 @@ public function testGetSectionData()
109110
$quoteMock->expects($this->once())->method('getTotals')->willReturn($totals);
110111
$quoteMock->expects($this->once())->method('getHasError')->willReturn(false);
111112

113+
$storeMock = $this->getMock(\Magento\Store\Model\System\Store::class, ['getWebsiteId'], [], '', false);
114+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
115+
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);
116+
112117
$this->checkoutCartMock->expects($this->once())->method('getSummaryQty')->willReturn($summaryQty);
113118
$this->checkoutHelperMock->expects($this->once())
114119
->method('formatPrice')
@@ -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
}
@@ -180,6 +186,7 @@ public function testGetSectionDataWithCompositeProduct()
180186
$subtotalValue = 200;
181187
$productId = 10;
182188
$storeId = 20;
189+
$websiteId = 100;
183190

184191
$productRewrite = [$productId => ['rewrite' => 'product']];
185192
$itemData = ['item' => 'data'];
@@ -190,7 +197,7 @@ public function testGetSectionDataWithCompositeProduct()
190197

191198
$quoteMock = $this->getMock(
192199
'\Magento\Quote\Model\Quote',
193-
['getTotals', 'getHasError', 'getAllVisibleItems'],
200+
['getTotals', 'getHasError', 'getAllVisibleItems', 'getStore'],
194201
[],
195202
'',
196203
false
@@ -216,6 +223,10 @@ public function testGetSectionDataWithCompositeProduct()
216223

217224
$quoteMock->expects($this->once())->method('getAllVisibleItems')->willReturn([$quoteItemMock]);
218225

226+
$storeMock = $this->getMock(\Magento\Store\Model\System\Store::class, ['getWebsiteId'], [], '', false);
227+
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
228+
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);
229+
219230
$productMock = $this->getMock(
220231
'\Magento\Catalog\Model\Product',
221232
['isVisibleInSiteVisibility', 'getId', 'setUrlDataObject'],
@@ -271,7 +282,8 @@ public function testGetSectionDataWithCompositeProduct()
271282
['item' => 'data']
272283
],
273284
'extra_actions' => '<span>Buttons</span>',
274-
'isGuestCheckoutAllowed' => 1
285+
'isGuestCheckoutAllowed' => 1,
286+
'website_id' => $websiteId
275287
];
276288
$this->assertEquals($expectedResult, $this->model->getSectionData());
277289
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ define([
9797
addToCartCalls++;
9898
self.isLoading(true);
9999
});
100+
if (cartData().website_id !== window.checkout.websiteId) {
101+
customerData.reload(['cart'], false);
102+
}
100103

101104
return this._super();
102105
},

0 commit comments

Comments
 (0)