Skip to content

Commit e1bfbe2

Browse files
committed
Merge branch 'ACP2E-39' of https://github.com/magento-l3/magento2ce into PR1-21-01-2022
2 parents e88fa0c + 85c9b9d commit e1bfbe2

File tree

2 files changed

+76
-0
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/ProductFrontendAction
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Product/ProductFrontendAction

2 files changed

+76
-0
lines changed

app/code/Magento/Catalog/Model/ResourceModel/ProductFrontendAction/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function addFilterByUserIdentities($customerId, $visitorId)
3636
$this->addFieldToFilter('customer_id', $customerId);
3737
} elseif ($visitorId) {
3838
$this->addFieldToFilter('visitor_id', $visitorId);
39+
} else {
40+
$this->_totalRecords = 0;
41+
$this->_setIsLoaded(true);
3942
}
4043

4144
return $this;

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Magento\Catalog\Model\Product\ProductFrontendAction;
99

1010
use Magento\Catalog\Model\ProductRepository;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Model\Session;
13+
use Magento\Customer\Model\Visitor;
1114

1215
/**
1316
* Test for \Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer.
@@ -19,20 +22,34 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
1922
*/
2023
private $synchronizer;
2124

25+
/** @var Session */
26+
private $session;
27+
28+
/** @var Visitor */
29+
private $visitor;
30+
2231
/**
2332
* @var ProductRepository
2433
*/
2534
private $productRepository;
2635

36+
/**
37+
* @var CustomerRepositoryInterface
38+
*/
39+
private $customerRepository;
40+
2741
/**
2842
* @inheritDoc
2943
*/
3044
protected function setUp(): void
3145
{
3246
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
47+
$this->session = $objectManager->get(Session::class);
48+
$this->visitor = $objectManager->get(Visitor::class);
3349

3450
$this->synchronizer = $objectManager->get(Synchronizer::class);
3551
$this->productRepository = $objectManager->get(ProductRepository::class);
52+
$this->customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
3653
}
3754

3855
/**
@@ -110,4 +127,60 @@ public function testSyncActionsWithoutActionsType(): void
110127

111128
$this->synchronizer->syncActions($productsData, '');
112129
}
130+
131+
/**
132+
* Tests that product actions are returned correctly according to the provided customer or visitor.
133+
*
134+
* @param int|null $visitorId
135+
* @param string|null $customerEmail
136+
* @param int $expectedCollectionSize
137+
* @return void
138+
* @dataProvider getAllActionsDataProvider
139+
*
140+
* @magentoDataFixture Magento/Customer/_files/customer.php
141+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
142+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
143+
*/
144+
public function testGetAllActions(?int $visitorId, ?string $customerEmail, int $expectedCollectionSize): void
145+
{
146+
$customerId = $customerEmail ? $this->customerRepository->get($customerEmail)->getId() : null;
147+
$this->session->setCustomerId($customerId);
148+
$this->visitor->setId($visitorId);
149+
$actionsType = 'recently_viewed_product';
150+
$productScope = 'website';
151+
$scopeId = 1;
152+
$product1 = $this->productRepository->get('simple');
153+
$product2 = $this->productRepository->get('simple2');
154+
$product1Id = $product1->getId();
155+
$product2Id = $product2->getId();
156+
$productsData = [
157+
$productScope . '-' . $scopeId . '-' . $product1Id => [
158+
'added_at' => '1576582660',
159+
'product_id' => $product1Id,
160+
],
161+
$productScope . '-' . $scopeId . '-' . $product2Id => [
162+
'added_at' => '1576587153',
163+
'product_id' => $product2Id,
164+
],
165+
];
166+
167+
$this->synchronizer->syncActions($productsData, $actionsType);
168+
$collection = $this->synchronizer->getAllActions();
169+
170+
$this->assertEquals($expectedCollectionSize, $collection->getSize());
171+
}
172+
173+
/**
174+
* @return array[]
175+
* @throws \Magento\Framework\Exception\LocalizedException
176+
* @throws \Magento\Framework\Exception\NoSuchEntityException
177+
*/
178+
public function getAllActionsDataProvider()
179+
{
180+
return [
181+
['visitorId' => null, 'customerEmail' => 'customer@example.com', 'expectedCollectionSize' => 2],
182+
['visitorId' => 123, 'customerEmail' => null, 'expectedCollectionSize' => 2],
183+
['visitorId' => null, 'customerEmail' => null, 'expectedCollectionSize' => 0],
184+
];
185+
}
113186
}

0 commit comments

Comments
 (0)