Skip to content

Commit cb4e13f

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3282' into Tier4-Kings-PR-11-22-2024
2 parents f96340f + c53fcf8 commit cb4e13f

File tree

4 files changed

+86
-35
lines changed

4 files changed

+86
-35
lines changed

app/code/Magento/Wishlist/CustomerData/Wishlist.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Wishlist\CustomerData;
77

@@ -85,7 +85,8 @@ public function getSectionData()
8585
return [
8686
'counter' => $counter,
8787
'items' => $counter ? $this->getItems() : [],
88-
'websiteId' => $this->storeManager->getWebsite()->getId()
88+
'websiteId' => $this->storeManager->getWebsite()->getId(),
89+
'storeId' => $this->storeManager->getStore()->getId()
8990
];
9091
}
9192

app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,6 +15,7 @@
1515
use Magento\Catalog\Model\Product\Type\AbstractType;
1616
use Magento\Framework\App\ViewInterface;
1717
use Magento\Framework\Pricing\Render;
18+
use Magento\Store\Api\Data\StoreInterface;
1819
use Magento\Store\Model\StoreManagerInterface;
1920
use Magento\Wishlist\Block\Customer\Sidebar;
2021
use Magento\Wishlist\CustomerData\Wishlist;
@@ -55,6 +56,9 @@ class WishlistTest extends TestCase
5556
/** @var WebsiteInterface|MockObject */
5657
private $websiteMock;
5758

59+
/** @var StoreInterface|MockObject */
60+
private $storeMock;
61+
5862
/** @var ImageFactory|MockObject */
5963
private $imageHelperFactory;
6064

@@ -93,6 +97,11 @@ protected function setUp(): void
9397
->disableOriginalConstructor()
9498
->getMockForAbstractClass();
9599

100+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
101+
->onlyMethods(['getId',])
102+
->disableOriginalConstructor()
103+
->getMockForAbstractClass();
104+
96105
$this->model = new Wishlist(
97106
$this->wishlistHelperMock,
98107
$this->sidebarMock,
@@ -127,10 +136,18 @@ public function testGetSectionData()
127136
->method('getWebsite')
128137
->willReturn($this->websiteMock);
129138

139+
$this->storeManagerMock->expects($this->once())
140+
->method('getStore')
141+
->willReturn($this->storeMock);
142+
130143
$this->websiteMock->expects($this->once())
131144
->method('getId')
132145
->willReturn(1);
133146

147+
$this->storeMock->expects($this->once())
148+
->method('getId')
149+
->willReturn(1);
150+
134151
$result = [
135152
'counter' => __('1 item'),
136153
'items' => [
@@ -153,7 +170,8 @@ public function testGetSectionData()
153170
'delete_item_params' => $itemRemoveParams,
154171
],
155172
],
156-
'websiteId' => 1
173+
'websiteId' => 1,
174+
'storeId' => 1
157175
];
158176

159177
/** @var Item|MockObject $itemMock */
@@ -322,10 +340,18 @@ public function testGetSectionDataWithTwoItems()
322340
->method('getWebsite')
323341
->willReturn($this->websiteMock);
324342

343+
$this->storeManagerMock->expects($this->once())
344+
->method('getStore')
345+
->willReturn($this->storeMock);
346+
325347
$this->websiteMock->expects($this->once())
326348
->method('getId')
327349
->willReturn(1);
328350

351+
$this->storeMock->expects($this->once())
352+
->method('getId')
353+
->willReturn(1);
354+
329355
$result = [
330356
'counter' => __('%1 items', count($items)),
331357
'items' => [
@@ -366,7 +392,8 @@ public function testGetSectionDataWithTwoItems()
366392
'delete_item_params' => $itemRemoveParams,
367393
],
368394
],
369-
'websiteId' => 1
395+
'websiteId' => 1,
396+
'storeId' => 1
370397
];
371398

372399
$this->wishlistHelperMock->expects($this->once())
@@ -508,14 +535,23 @@ public function testGetSectionDataWithoutItems()
508535
->method('getWebsite')
509536
->willReturn($this->websiteMock);
510537

538+
$this->storeManagerMock->expects($this->once())
539+
->method('getStore')
540+
->willReturn($this->storeMock);
541+
511542
$this->websiteMock->expects($this->once())
512543
->method('getId')
513544
->willReturn(null);
514545

546+
$this->storeMock->expects($this->once())
547+
->method('getId')
548+
->willReturn(null);
549+
515550
$result = [
516551
'counter' => null,
517552
'items' => [],
518-
'websiteId' =>null
553+
'websiteId' =>null,
554+
'storeId' => null
519555
];
520556

521557
$this->wishlistHelperMock->expects($this->once())

app/code/Magento/Wishlist/view/frontend/web/js/view/wishlist.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2015 Adobe
3+
* All Rights Reserved.
44
*/
55

66
define([
@@ -17,15 +17,16 @@ define([
1717
initialize: function () {
1818
this._super();
1919
this.wishlist = customerData.get('wishlist');
20+
this.company = customerData.get('company');
2021
if (!wishlistReloaded
2122
&& !_.isEmpty(this.wishlist())
2223
// Expired section names are reloaded on page load.
2324
&& _.indexOf(customerData.getExpiredSectionNames(), 'wishlist') === -1
2425
&& window.checkout
25-
&& window.checkout.websiteId
26-
&& window.checkout.websiteId !== this.wishlist().websiteId
26+
&& window.checkout.storeId
27+
&& (window.checkout.storeId !== this.wishlist().storeId || this.company().is_enabled)
2728
) {
28-
//set count to 0 to prevent "wishlist" blocks and count to show with wrong count and items
29+
//set count to 0 to prevent "Wishlist products" blocks and count to show with wrong count and items
2930
this.wishlist().counter = 0;
3031
customerData.invalidate(['wishlist']);
3132
customerData.reload(['wishlist'], false);

dev/tests/js/jasmine/tests/app/code/Magento/Wishlist/view/frontend/web/js/view/wishlist.test.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
/************************************************************************
1+
/**
22
* Copyright 2024 Adobe
33
* All Rights Reserved.
4-
*
5-
* NOTICE: All information contained herein is, and remains
6-
* the property of Adobe and its suppliers, if any. The intellectual
7-
* and technical concepts contained herein are proprietary to Adobe
8-
* and its suppliers and are protected by all applicable intellectual
9-
* property laws, including trade secret and copyright laws.
10-
* Dissemination of this information or reproduction of this material
11-
* is strictly forbidden unless prior written permission is obtained
12-
* from Adobe.
13-
* ***********************************************************************
144
*/
5+
156
define([
167
'squire'
178
], function (Squire) {
@@ -20,6 +11,7 @@ define([
2011
describe('Magento_Wishlist/js/view/wishlist', function () {
2112
var wishlistComponent,
2213
mockWishlist,
14+
mockCompany,
2315
mockCustomerData,
2416
injector;
2517

@@ -28,14 +20,23 @@ define([
2820

2921
mockWishlist = {
3022
counter: 1,
31-
items: [],
32-
websiteId: 1
23+
items: [{ id: 1, name: 'Test Product' }],
24+
storeId: 1
25+
};
26+
27+
mockCompany = {
28+
is_enabled: true
3329
};
30+
3431
injector.clean();
3532

3633
mockCustomerData = {
37-
get: jasmine.createSpy('customerDataGet').and.returnValue(function () {
38-
return mockWishlist;
34+
get: jasmine.createSpy('customerDataGet').and.callFake(function (key) {
35+
if (key === 'wishlist') {
36+
return function () { return mockWishlist; };
37+
} else if (key === 'company') {
38+
return function () { return mockCompany; };
39+
}
3940
}),
4041
reload: jasmine.createSpy('customerDataReload'),
4142
invalidate: jasmine.createSpy(),
@@ -75,20 +76,32 @@ define([
7576
expect(mockCustomerData.get).toHaveBeenCalledWith('wishlist');
7677
});
7778

78-
it('should invalidate wishlist if websiteIds do not match', async function () {
79-
window.checkout = { websiteId: 2 };
79+
it('should call customerData.get with "company"', async function () {
80+
expect(mockCustomerData.get).toHaveBeenCalledWith('company');
81+
});
82+
83+
it('should invalidate wishlist if storeIds do not match', async function () {
84+
window.checkout = { storeId: 2 };
8085
await wishlistComponent.initialize();
8186
expect(mockCustomerData.invalidate).toHaveBeenCalledWith(['wishlist']);
8287
});
8388

84-
it('should not reload wishlist if websiteIds match', async function () {
85-
window.checkout = { websiteId: 1 };
89+
it('should not reload wishlist if storeIds match and company is disabled', async function () {
90+
window.checkout = { storeId: 1 };
91+
mockCompany.is_enabled = false;
8692
await wishlistComponent.initialize();
87-
expect(mockCustomerData.reload).not.toHaveBeenCalled();
93+
expect(mockCustomerData.reload).not.toHaveBeenCalledWith(['wishlist'], false);
94+
});
95+
96+
it('should reload wishlist if storeIds do not match', async function () {
97+
window.checkout = { storeId: 2 };
98+
await wishlistComponent.initialize();
99+
expect(mockCustomerData.reload).toHaveBeenCalledWith(['wishlist'], false);
88100
});
89101

90-
it('should reload wishlist if websiteIds do not match', async function () {
91-
window.checkout = { websiteId: 2 };
102+
it('should reload wishlist if storeIds match and company is enabled', async function () {
103+
window.checkout = { storeId: 1 };
104+
mockCompany.is_enabled = true;
92105
await wishlistComponent.initialize();
93106
expect(mockCustomerData.reload).toHaveBeenCalledWith(['wishlist'], false);
94107
});

0 commit comments

Comments
 (0)