Skip to content

Commit 0eaaef8

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-39140' into 2.4-develop-pr50
2 parents 74fa143 + aec946d commit 0eaaef8

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,12 @@ public function addWebsiteFilter($websites = null)
916916
}
917917

918918
$this->_productLimitationFilters['website_ids'] = $websites;
919-
$this->_applyProductLimitations();
919+
920+
if ($this->getStoreId() == Store::DEFAULT_STORE_ID) {
921+
$this->_productLimitationJoinWebsite();
922+
} else {
923+
$this->_applyProductLimitations();
924+
}
920925

921926
return $this;
922927
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
3939
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
4040
use Magento\Framework\Validator\UniversalFactory;
41+
use Magento\Store\Model\Store;
4142
use Magento\Store\Model\StoreManagerInterface;
4243
use PHPUnit\Framework\MockObject\MockObject;
4344
use PHPUnit\Framework\TestCase;
@@ -93,6 +94,11 @@ class CollectionTest extends TestCase
9394
*/
9495
private $storeManager;
9596

97+
/**
98+
* @var ProductLimitation|MockObject
99+
*/
100+
private $productLimitationMock;
101+
96102
/**
97103
* @var EntityFactory|MockObject
98104
*/
@@ -192,7 +198,7 @@ protected function setUp(): void
192198
$this->entityMock->expects($this->any())->method('getTable')->willReturnArgument(0);
193199
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);
194200

195-
$productLimitationMock = $this->createMock(
201+
$this->productLimitationMock = $this->createMock(
196202
ProductLimitation::class
197203
);
198204
$productLimitationFactoryMock = $this->getMockBuilder(
@@ -201,7 +207,7 @@ protected function setUp(): void
201207
->setMethods(['create'])->getMock();
202208

203209
$productLimitationFactoryMock->method('create')
204-
->willReturn($productLimitationMock);
210+
->willReturn($this->productLimitationMock);
205211
$this->collection = $this->objectManager->getObject(
206212
Collection::class,
207213
[
@@ -432,4 +438,44 @@ public function testGetNewEmptyItem()
432438
$secondItem = $this->collection->getNewEmptyItem();
433439
$this->assertEquals($firstItem, $secondItem);
434440
}
441+
442+
/**
443+
* Test to add website filter in admin area
444+
*/
445+
public function testAddWebsiteFilterOnAdminStore(): void
446+
{
447+
$websiteIds = [2];
448+
$websiteTable = 'catalog_product_website';
449+
$joinCondition = 'join condition';
450+
$this->productLimitationMock->expects($this->atLeastOnce())
451+
->method('offsetSet')
452+
->with('website_ids', $websiteIds);
453+
$this->productLimitationMock->method('offsetExists')
454+
->with('website_ids')
455+
->willReturn(true);
456+
$this->productLimitationMock->method('offsetGet')
457+
->with('website_ids')
458+
->willReturn($websiteIds);
459+
$this->connectionMock->expects($this->once())
460+
->method('quoteInto')
461+
->with('product_website.website_id IN(?)', $websiteIds, 'int')
462+
->willReturn($joinCondition);
463+
$this->selectMock->method('getPart')->with(Select::FROM)->willReturn([]);
464+
/** @var AbstractEntity|MockObject $eavEntity */
465+
$eavEntity = $this->createMock(AbstractEntity::class);
466+
$eavEntity->method('getTable')
467+
->with('catalog_product_website')
468+
->willReturn($websiteTable);
469+
$this->selectMock->expects($this->once())
470+
->method('join')
471+
->with(
472+
['product_website' => $websiteTable],
473+
'product_website.product_id = e.entity_id AND ' . $joinCondition,
474+
[]
475+
);
476+
477+
$this->collection->setEntity($eavEntity);
478+
$this->collection->setStoreId(Store::DEFAULT_STORE_ID);
479+
$this->collection->addWebsiteFilter($websiteIds);
480+
}
435481
}

0 commit comments

Comments
 (0)