Skip to content

Commit 4b08d4f

Browse files
Adiglo70550glo60612
authored andcommitted
ACP2E-3282: When we unassign products from the shared catalog, the wishlist products are not being cleared
1 parent 708738f commit 4b08d4f

File tree

5 files changed

+88
-26
lines changed

5 files changed

+88
-26
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/Model/ResourceModel/Item/Collection/Grid.php

Lines changed: 4 additions & 2 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 2013 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Wishlist\Model\ResourceModel\Item\Collection;
@@ -124,6 +124,8 @@ protected function _assignProducts()
124124
$item->setProductName($product->getName());
125125
$item->setName($product->getName());
126126
$item->setPrice($product->getPrice());
127+
} else {
128+
$this->removeItemByKey($item->getId());
127129
}
128130
}
129131

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: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ define([
2020
describe('Magento_Wishlist/js/view/wishlist', function () {
2121
var wishlistComponent,
2222
mockWishlist,
23+
mockCompany,
2324
mockCustomerData,
2425
injector;
2526

@@ -28,14 +29,23 @@ define([
2829

2930
mockWishlist = {
3031
counter: 1,
31-
items: [],
32-
websiteId: 1
32+
items: [{ id: 1, name: 'Test Product' }],
33+
storeId: 1
3334
};
35+
36+
mockCompany = {
37+
is_enabled: true
38+
};
39+
3440
injector.clean();
3541

3642
mockCustomerData = {
37-
get: jasmine.createSpy('customerDataGet').and.returnValue(function () {
38-
return mockWishlist;
43+
get: jasmine.createSpy('customerDataGet').and.callFake(function (key) {
44+
if (key === 'wishlist') {
45+
return function () { return mockWishlist; };
46+
} else if (key === 'company') {
47+
return function () { return mockCompany; };
48+
}
3949
}),
4050
reload: jasmine.createSpy('customerDataReload'),
4151
invalidate: jasmine.createSpy(),
@@ -75,20 +85,32 @@ define([
7585
expect(mockCustomerData.get).toHaveBeenCalledWith('wishlist');
7686
});
7787

78-
it('should invalidate wishlist if websiteIds do not match', async function () {
79-
window.checkout = { websiteId: 2 };
88+
it('should call customerData.get with "company"', async function () {
89+
expect(mockCustomerData.get).toHaveBeenCalledWith('company');
90+
});
91+
92+
it('should invalidate wishlist if storeIds do not match', async function () {
93+
window.checkout = { storeId: 2 };
8094
await wishlistComponent.initialize();
8195
expect(mockCustomerData.invalidate).toHaveBeenCalledWith(['wishlist']);
8296
});
8397

84-
it('should not reload wishlist if websiteIds match', async function () {
85-
window.checkout = { websiteId: 1 };
98+
it('should not reload wishlist if storeIds match and company is disabled', async function () {
99+
window.checkout = { storeId: 1 };
100+
mockCompany.is_enabled = false;
86101
await wishlistComponent.initialize();
87-
expect(mockCustomerData.reload).not.toHaveBeenCalled();
102+
expect(mockCustomerData.reload).not.toHaveBeenCalledWith(['wishlist'], false);
103+
});
104+
105+
it('should reload wishlist if storeIds do not match', async function () {
106+
window.checkout = { storeId: 2 };
107+
await wishlistComponent.initialize();
108+
expect(mockCustomerData.reload).toHaveBeenCalledWith(['wishlist'], false);
88109
});
89110

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

0 commit comments

Comments
 (0)