Skip to content

Commit d947867

Browse files
committed
Merge remote-tracking branches 'local/ACP2E-1001', 'local/ACP2E-1007', 'local/ACP2E-1012', 'local/ACP2E-1018', 'local/ACP2E-1053' and 'local/ACP2E-1063' into PR_15_SEP_2022_odubovyk
7 parents 254c17b + 5271cd1 + 9dbbcd9 + 4ed7ab6 + 58444b4 + a47b41b + 21caabd commit d947867

File tree

28 files changed

+683
-86
lines changed

28 files changed

+683
-86
lines changed

app/code/Magento/Catalog/CustomerData/CompareProducts.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Store\Model\StoreManagerInterface;
1213

1314
/**
1415
* Catalog Product Compare Widget
@@ -37,22 +38,30 @@ class CompareProducts implements SectionSourceInterface
3738
*/
3839
private $scopeConfig;
3940

41+
/**
42+
* @var StoreManagerInterface
43+
*/
44+
private $storeManager;
45+
4046
/**
4147
* @param \Magento\Catalog\Helper\Product\Compare $helper
4248
* @param \Magento\Catalog\Model\Product\Url $productUrl
4349
* @param \Magento\Catalog\Helper\Output $outputHelper
4450
* @param ScopeConfigInterface|null $scopeConfig
51+
* @param StoreManagerInterface|null $storeManager
4552
*/
4653
public function __construct(
4754
\Magento\Catalog\Helper\Product\Compare $helper,
4855
\Magento\Catalog\Model\Product\Url $productUrl,
4956
\Magento\Catalog\Helper\Output $outputHelper,
50-
?ScopeConfigInterface $scopeConfig = null
57+
?ScopeConfigInterface $scopeConfig = null,
58+
?StoreManagerInterface $storeManager = null
5159
) {
5260
$this->helper = $helper;
5361
$this->productUrl = $productUrl;
5462
$this->outputHelper = $outputHelper;
5563
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
64+
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
5665
}
5766

5867
/**
@@ -66,6 +75,7 @@ public function getSectionData()
6675
'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
6776
'listUrl' => $this->helper->getListUrl(),
6877
'items' => $count ? $this->getItems() : [],
78+
'websiteId' => $this->storeManager->getWebsite()->getId()
6979
];
7080
}
7181

app/code/Magento/Catalog/Helper/Product/Compare.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,35 @@ class Compare extends \Magento\Framework\Url\Helper\Data
4141
protected $_allowUsedFlat = true;
4242

4343
/**
44-
* Customer id
44+
* Customer id for Compare Helper
4545
*
4646
* @var null|int
4747
*/
4848
protected $_customerId = null;
4949

5050
/**
51-
* Catalog session
51+
* Catalog session for Compare Helper
5252
*
5353
* @var \Magento\Catalog\Model\Session
5454
*/
5555
protected $_catalogSession;
5656

5757
/**
58-
* Customer session
58+
* Customer session for Compare Helper
5959
*
6060
* @var \Magento\Customer\Model\Session
6161
*/
6262
protected $_customerSession;
6363

6464
/**
65-
* Customer visitor
65+
* Customer visitor for Compare Helper
6666
*
6767
* @var \Magento\Customer\Model\Visitor
6868
*/
6969
protected $_customerVisitor;
7070

7171
/**
72-
* Catalog product visibility
72+
* Catalog product visibility for Compare Helper
7373
*
7474
* @var \Magento\Catalog\Model\Product\Visibility
7575
*/
@@ -297,7 +297,11 @@ public function getItemCollection()
297297
$this->_itemCollection->addAttributeToSelect('name')->addUrlRewrite()->load();
298298

299299
/* update compare items count */
300-
$this->_catalogSession->setCatalogCompareItemsCount(count($this->_itemCollection));
300+
$count = count($this->_itemCollection);
301+
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
302+
$counts[$this->_storeManager->getWebsite()->getId()] = $count;
303+
$this->_catalogSession->setCatalogCompareItemsCountPerWebsite($counts);
304+
$this->_catalogSession->setCatalogCompareItemsCount($count); //deprecated
301305
}
302306

303307
return $this->_itemCollection;
@@ -327,7 +331,10 @@ public function calculate($logout = false)
327331
->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
328332

329333
$count = $collection->getSize();
330-
$this->_catalogSession->setCatalogCompareItemsCount($count);
334+
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
335+
$counts[$this->_storeManager->getWebsite()->getId()] = $count;
336+
$this->_catalogSession->setCatalogCompareItemsCountPerWebsite($counts);
337+
$this->_catalogSession->setCatalogCompareItemsCount($count); //deprecated
331338

332339
return $this;
333340
}
@@ -339,11 +346,12 @@ public function calculate($logout = false)
339346
*/
340347
public function getItemCount()
341348
{
342-
if (!$this->_catalogSession->hasCatalogCompareItemsCount()) {
349+
$counts = $this->_catalogSession->getCatalogCompareItemsCountPerWebsite() ?: [];
350+
if (!isset($counts[$this->_storeManager->getWebsite()->getId()])) {
343351
$this->calculate();
344352
}
345353

346-
return $this->_catalogSession->getCatalogCompareItemsCount();
354+
return $counts[$this->_storeManager->getWebsite()->getId()] ?? 0;
347355
}
348356

349357
/**

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductCompareMainSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<element name="ProductAttributeByCodeAndProductName" type="text" selector="//*[@id='product-comparison']//tr[.//th[./span[contains(text(), '{{var1}}')]]]//td[count(//*[@id='product-comparison']//tr//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var2}}')]]/preceding-sibling::td)+1]/div" parameterized="true"/>
1717
<element name="ProductAddToCartButton" type="button" selector=".product-item-photo[title='{{productName}}'] ~ .product-item-actions button[type='submit']" parameterized="true" timeout="30"/>
1818
<element name="removeFirstItem" type="button" selector="table.table-comparison a.delete"/>
19+
<element name="compareProducts" type="button" selector="//ul[contains(@class, 'compare wrapper')]//a[contains(@class, 'action compare')]"/>
1920
</section>
2021
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCheckProductListPriceAttributesWithDifferentCurrencyTest" extends="AdminCheckProductListPriceAttributesTest">
12+
<annotations>
13+
<stories value="Check price attributes values on Admin Product List when different currency is used for Default Website"/>
14+
<title value="Check price attributes values on Admin Product List."/>
15+
<description value="Login as admin, create simple product, add cost, special price.
16+
Change Price to Website Scope. Change Currency to Default Website scope.
17+
Go to Admin
18+
Product List page filter grid by created product, add mentioned columns to grid, check values."/>
19+
<group value="catalog"/>
20+
<severity value="MAJOR"/>
21+
<testCaseId value="AC-6078"/>
22+
<useCaseId value="ACP2E-1018"/>
23+
</annotations>
24+
<before>
25+
<!-- Configure Stores -> Configuration -> Catalog -> Catalog -> Price Scope = Website -->
26+
<magentoCLI command="config:set catalog/price/scope 1" stepKey="setPriceScopeToWebsite" after="loginToAdminPanel" />
27+
<!-- Configure Stores -> Configuration -> General -> Currency Setup -> Currency Options -> Base Currency = Euro -->
28+
<magentoCLI command="config:set --scope website --scope-code base currency/options/base EUR" stepKey="setBaseCurrencyAsEuroToMainWebsite" after="setPriceScopeToWebsite" />
29+
</before>
30+
<after>
31+
<!-- Configure Stores -> Configuration -> General -> Currency Setup -> Currency Options -> Base Currency = USD (as default value) -->
32+
<magentoCLI command="config:set --scope website --scope-code base currency/options/base USD" stepKey="setBaseCurrencyBackAsUSDToMainWebsite" after="deleteSimpleProduct" />
33+
<!-- Configure Stores -> Configuration -> Catalog -> Catalog -> Price Scope = Global -->
34+
<magentoCLI command="config:set catalog/price/scope 0" stepKey="setPriceScopeToGlobal" after="setBaseCurrencyBackAsUSDToMainWebsite" />
35+
</after>
36+
</test>
37+
</tests>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontVerifyCompareListVisibilityForMultiWebsiteTest">
12+
<annotations>
13+
<stories value="Compare list behave incorrectly in multi-website setup."/>
14+
<title value="Customer add product to compare list and verify visibility in other store"/>
15+
<description value="Test compare products link visibility for other store view"/>
16+
<testCaseId value="AC-6406"/>
17+
<useCaseId value="ACP2E-1007"/>
18+
<severity value="MAJOR"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<!-- Create simple products -->
23+
<createData entity="SimpleProduct2" stepKey="createFirstSimpleProduct">
24+
<field key="price">560</field>
25+
</createData>
26+
<createData entity="SimpleProduct2" stepKey="createSecondSimpleProduct">
27+
<field key="price">560</field>
28+
</createData>
29+
<!-- Login as Admin -->
30+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
31+
<actionGroup ref="EnableWebUrlOptionsActionGroup" stepKey="addStoreCodeToUrls"/>
32+
<!-- Create website, store group, store view -->
33+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createAdditionalWebsite">
34+
<argument name="newWebsiteName" value="{{customWebsite.name}}"/>
35+
<argument name="websiteCode" value="{{customWebsite.code}}"/>
36+
</actionGroup>
37+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createNewStore">
38+
<argument name="website" value="{{customWebsite.name}}"/>
39+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
40+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
41+
</actionGroup>
42+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createNewStoreView">
43+
<argument name="StoreGroup" value="customStoreGroup"/>
44+
<argument name="customStore" value="customStore"/>
45+
</actionGroup>
46+
</before>
47+
<after>
48+
<!-- Reset web url option-->
49+
<actionGroup ref="ResetWebUrlOptionsActionGroup" stepKey="resetUrlOption"/>
50+
<!-- Delete website-->
51+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteWebsite">
52+
<argument name="websiteName" value="{{customWebsite.name}}"/>
53+
</actionGroup>
54+
<!-- Delete product-->
55+
<deleteData createDataKey="createFirstSimpleProduct" stepKey="deleteFirstSimpleProduct"/>
56+
<deleteData createDataKey="createSecondSimpleProduct" stepKey="deleteSecondSimpleProduct"/>
57+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
58+
</after>
59+
<!-- Add first product to compare list -->
60+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openFirstProductPage">
61+
<argument name="productUrl" value="$$createFirstSimpleProduct.custom_attributes[url_key]$$"/>
62+
</actionGroup>
63+
<scrollTo selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="scrollToCompareProductButton"/>
64+
<actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addFirstProductToCompare">
65+
<argument name="productVar" value="$$createFirstSimpleProduct$$"/>
66+
</actionGroup>
67+
<!--Add second product to compare list -->
68+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openSecondProductPage">
69+
<argument name="productUrl" value="$$createSecondSimpleProduct.custom_attributes[url_key]$$"/>
70+
</actionGroup>
71+
<scrollTo selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="scrollToCompareButton"/>
72+
<actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addSecondProductToCompare">
73+
<argument name="productVar" value="$$createSecondSimpleProduct$$"/>
74+
</actionGroup>
75+
<see userInput="Compare Products" selector="{{StorefrontProductCompareMainSection.compareProducts}}" stepKey="assertCompareProductLinkName"/>
76+
<!-- Open storefront on second store -->
77+
<amOnPage url="{{StorefrontStoreHomePage.url(customStore.code)}}" stepKey="openStorefrontPage"/>
78+
<waitForPageLoad time="30" stepKey="waitStorefrontPage"/>
79+
<dontSee userInput="Compare Products" selector="{{StorefrontProductCompareMainSection.compareProducts}}" stepKey="assertCompareProductLinkNameNotVisible"/>
80+
</test>
81+
</tests>

app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
1818
use Magento\Framework\App\Config\ScopeConfigInterface;
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
20+
use Magento\Store\Model\Website;
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
23+
use Magento\Store\Model\StoreManagerInterface;
2224

2325
class CompareProductsTest extends TestCase
2426
{
@@ -52,6 +54,16 @@ class CompareProductsTest extends TestCase
5254
*/
5355
private $scopeConfigMock;
5456

57+
/**
58+
* @var StoreManagerInterface
59+
*/
60+
private $storeManagerMock;
61+
62+
/**
63+
* @var Website|MockObject
64+
*/
65+
private $websiteMock;
66+
5567
/**
5668
* @var array
5769
*/
@@ -77,6 +89,18 @@ protected function setUp(): void
7789
->disableOriginalConstructor()
7890
->getMockForAbstractClass();
7991

92+
$this->storeManagerMock = $this->getMockBuilder(
93+
StoreManagerInterface::class
94+
)->disableOriginalConstructor()
95+
->getMockForAbstractClass();
96+
97+
$this->websiteMock = $this->getMockBuilder(
98+
Website::class
99+
)->onlyMethods(
100+
['getId',]
101+
)->disableOriginalConstructor()
102+
->getMock();
103+
80104
$this->objectManagerHelper = new ObjectManagerHelper($this);
81105

82106
$this->model = $this->objectManagerHelper->getObject(
@@ -85,7 +109,9 @@ protected function setUp(): void
85109
'helper' => $this->helperMock,
86110
'productUrl' => $this->productUrlMock,
87111
'outputHelper' => $this->outputHelperMock,
88-
'scopeConfig' => $this->scopeConfigMock
112+
'scopeConfig' => $this->scopeConfigMock,
113+
'storeManager' => $this->storeManagerMock
114+
89115
]
90116
);
91117
}
@@ -196,7 +222,8 @@ public function testGetSectionData()
196222
$this->helperMock->expects($this->once())
197223
->method('getListUrl')
198224
->willReturn('http://list.url');
199-
225+
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
226+
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
200227
$this->assertEquals(
201228
[
202229
'count' => $count,
@@ -224,7 +251,8 @@ public function testGetSectionData()
224251
'remove_url' => 'http://remove.url/3',
225252
'productScope' => null
226253
]
227-
]
254+
],
255+
'websiteId' => 1
228256
],
229257
$this->model->getSectionData()
230258
);
@@ -245,12 +273,16 @@ public function testGetSectionDataNoItems()
245273
->method('getListUrl')
246274
->willReturn('http://list.url');
247275

276+
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
277+
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
278+
248279
$this->assertEquals(
249280
[
250281
'count' => $count,
251282
'countCaption' => __('%1 items', $count),
252283
'listUrl' => 'http://list.url',
253-
'items' => []
284+
'items' => [],
285+
'websiteId' => 1
254286
],
255287
$this->model->getSectionData()
256288
);
@@ -264,6 +296,9 @@ public function testGetSectionDataSingleItem()
264296
->method('getItemCount')
265297
->willReturn($count);
266298

299+
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
300+
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
301+
267302
$items = $this->prepareProductsWithCorrespondingMocks(
268303
[
269304
[
@@ -296,7 +331,8 @@ public function testGetSectionDataSingleItem()
296331
'remove_url' => 'http://remove.url/12345',
297332
'productScope' => null
298333
]
299-
]
334+
],
335+
'websiteId' => 1
300336
],
301337
$this->model->getSectionData()
302338
);

0 commit comments

Comments
 (0)