Skip to content

Commit 73f4963

Browse files
committed
Merge remote-tracking branch 'origin/MC-31171' into 2.4-develop-pr15
2 parents e74cc49 + feb9f01 commit 73f4963

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*
2121
* Service which allows to sync product widget information, such as product id with db. In order to reuse this info
2222
* on different devices
23+
*
24+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2325
*/
2426
class Synchronizer
2527
{
@@ -94,6 +96,7 @@ public function __construct(
9496
*
9597
* @param string $namespace
9698
* @return int
99+
* @throws \Magento\Framework\Exception\LocalizedException
97100
*/
98101
private function getLifeTimeByNamespace($namespace)
99102
{
@@ -119,6 +122,7 @@ private function getLifeTimeByNamespace($namespace)
119122
* @param array $productsData (product action data, that came from frontend)
120123
* @param string $typeId namespace (type of action)
121124
* @return array
125+
* @throws \Magento\Framework\Exception\LocalizedException
122126
*/
123127
private function filterNewestActions(array $productsData, $typeId)
124128
{
@@ -166,6 +170,7 @@ private function getProductIdsByActions(array $actions)
166170
* @param array $productsData
167171
* @param string $typeId
168172
* @return void
173+
* @throws \Exception
169174
*/
170175
public function syncActions(array $productsData, $typeId)
171176
{
@@ -189,16 +194,15 @@ public function syncActions(array $productsData, $typeId)
189194
foreach ($collection as $item) {
190195
$this->entityManager->delete($item);
191196
}
192-
193-
foreach ($productsData as $productId => $productData) {
197+
foreach ($productsData as $productData) {
194198
/** @var ProductFrontendActionInterface $action */
195199
$action = $this->productFrontendActionFactory->create(
196200
[
197201
'data' => [
198202
'visitor_id' => $customerId ? null : $visitorId,
199203
'customer_id' => $this->session->getCustomerId(),
200204
'added_at' => $productData['added_at'],
201-
'product_id' => $productId,
205+
'product_id' => $productData['product_id'],
202206
'type_id' => $typeId
203207
]
204208
]

app/code/Magento/Catalog/Test/Unit/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public function testFilterProductActions()
8282
{
8383
$typeId = 'recently_compared_product';
8484
$productsData = [
85-
1 => [
85+
'website-1-1' => [
8686
'added_at' => 12,
8787
'product_id' => 1,
8888
],
89-
2 => [
89+
'website-1-2' => [
9090
'added_at' => 13,
9191
'product_id' => '2',
9292
],
93-
3 => [
93+
'website-2-3' => [
9494
'added_at' => 14,
9595
'product_id' => 3,
9696
]

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/ProductFrontendAction/SynchronizerTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,24 @@ protected function setUp()
4040
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
4141
*
4242
* @return void
43+
* @throws \Magento\Framework\Exception\LocalizedException
44+
* @throws \Magento\Framework\Exception\NoSuchEntityException
4345
*/
4446
public function testSyncActions(): void
4547
{
4648
$actionsType = 'recently_viewed_product';
49+
$productScope = 'website';
50+
$scopeId = 1;
4751
$product1 = $this->productRepository->get('simple');
4852
$product2 = $this->productRepository->get('simple2');
4953
$product1Id = $product1->getId();
5054
$product2Id = $product2->getId();
5155
$productsData = [
52-
$product1Id => [
56+
$productScope . '-' . $scopeId . '-' . $product1Id => [
5357
'added_at' => '1576582660',
5458
'product_id' => $product1Id,
5559
],
56-
$product2Id => [
60+
$productScope . '-' . $scopeId . '-' . $product2Id => [
5761
'added_at' => '1576587153',
5862
'product_id' => $product2Id,
5963
],
@@ -71,8 +75,9 @@ public function testSyncActions(): void
7175
);
7276

7377
foreach ($synchronizedCollection as $item) {
74-
$this->assertArrayHasKey($item->getProductId(), $productsData);
75-
$this->assertEquals($productsData[$item->getProductId()]['added_at'], $item->getAddedAt());
78+
$productScopeId = $productScope . '-' . $scopeId . '-' . $item->getProductId();
79+
$this->assertArrayHasKey($productScopeId, $productsData);
80+
$this->assertEquals($productsData[$productScopeId]['added_at'], $item->getAddedAt());
7681
}
7782
}
7883

@@ -81,6 +86,8 @@ public function testSyncActions(): void
8186
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
8287
*
8388
* @return void
89+
* @throws \Magento\Framework\Exception\LocalizedException
90+
* @throws \Magento\Framework\Exception\NoSuchEntityException
8491
*/
8592
public function testSyncActionsWithoutActionsType(): void
8693
{

0 commit comments

Comments
 (0)