Skip to content

Commit 04d8290

Browse files
committed
Merge branch 'ACP2E-39' of https://github.com/magento-l3/magento2ce into ACP2E-39
2 parents a37b741 + e44c3f6 commit 04d8290

File tree

2 files changed

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

2 files changed

+90
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function addFilterByUserIdentities($customerId, $visitorId)
3737
} elseif ($visitorId) {
3838
$this->addFieldToFilter('visitor_id', $visitorId);
3939
} else {
40-
$this->addFieldToFilter('visitor_id', $visitorId)
41-
->addFieldToFilter('customer_id', $customerId);
40+
$this->_totalRecords = 0;
41+
$this->_setIsLoaded(true);
4242
}
4343

4444
return $this;

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
1919
*/
2020
private $synchronizer;
2121

22+
/** @var Session */
23+
private $session;
24+
25+
/** @var Visitor */
26+
private $visitor;
27+
2228
/**
2329
* @var ProductRepository
2430
*/
@@ -30,6 +36,8 @@ class SynchronizerTest extends \PHPUnit\Framework\TestCase
3036
protected function setUp(): void
3137
{
3238
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
39+
$this->session = $objectManager->get(\Magento\Customer\Model\Session::class);
40+
$this->visitor = $objectManager->get(\Magento\Customer\Model\Visitor::class);
3341

3442
$this->synchronizer = $objectManager->get(Synchronizer::class);
3543
$this->productRepository = $objectManager->get(ProductRepository::class);
@@ -110,4 +118,84 @@ public function testSyncActionsWithoutActionsType(): void
110118

111119
$this->synchronizer->syncActions($productsData, '');
112120
}
121+
122+
/**
123+
* @return void
124+
* @throws \Magento\Framework\Exception\LocalizedException
125+
* @throws \Magento\Framework\Exception\NoSuchEntityException
126+
*/
127+
public function testGetAllActionsWithoutCustomerAndVisitor(): void
128+
{
129+
$collection = $this->synchronizer->getAllActions();
130+
$this->assertEquals($collection->getSize(), 0);
131+
}
132+
133+
/**
134+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
135+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
136+
*
137+
* @return void
138+
* @throws \Magento\Framework\Exception\LocalizedException
139+
* @throws \Magento\Framework\Exception\NoSuchEntityException
140+
*/
141+
public function testGetAllActionsOfVisitor(): void
142+
{
143+
$this->visitor->setId(123);
144+
$actionsType = 'recently_viewed_product';
145+
$productScope = 'website';
146+
$scopeId = 1;
147+
$product1 = $this->productRepository->get('simple');
148+
$product2 = $this->productRepository->get('simple2');
149+
$product1Id = $product1->getId();
150+
$product2Id = $product2->getId();
151+
$productsData = [
152+
$productScope . '-' . $scopeId . '-' . $product1Id => [
153+
'added_at' => '1576582660',
154+
'product_id' => $product1Id,
155+
],
156+
$productScope . '-' . $scopeId . '-' . $product2Id => [
157+
'added_at' => '1576587153',
158+
'product_id' => $product2Id,
159+
],
160+
];
161+
162+
$this->synchronizer->syncActions($productsData, $actionsType);
163+
$collection = $this->synchronizer->getAllActions();
164+
$this->assertEquals($collection->getSize(), 2);
165+
}
166+
167+
/**
168+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
169+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
170+
*
171+
* @return void
172+
* @throws \Magento\Framework\Exception\LocalizedException
173+
* @throws \Magento\Framework\Exception\NoSuchEntityException
174+
*/
175+
public function testGetAllActionsOfCustomer(): void
176+
{
177+
$this->session->setCustomerId(1);
178+
$this->visitor->setId(null);
179+
$actionsType = 'recently_viewed_product';
180+
$productScope = 'website';
181+
$scopeId = 1;
182+
$product1 = $this->productRepository->get('simple');
183+
$product2 = $this->productRepository->get('simple2');
184+
$product1Id = $product1->getId();
185+
$product2Id = $product2->getId();
186+
$productsData = [
187+
$productScope . '-' . $scopeId . '-' . $product1Id => [
188+
'added_at' => '1576582660',
189+
'product_id' => $product1Id,
190+
],
191+
$productScope . '-' . $scopeId . '-' . $product2Id => [
192+
'added_at' => '1576587153',
193+
'product_id' => $product2Id,
194+
],
195+
];
196+
197+
$this->synchronizer->syncActions($productsData, $actionsType);
198+
$collection = $this->synchronizer->getAllActions();
199+
$this->assertEquals($collection->getSize(), 2);
200+
}
113201
}

0 commit comments

Comments
 (0)