Skip to content

Commit

Permalink
Merge pull request #132 from AleksandrsKondratjevs/issue-2913
Browse files Browse the repository at this point in the history
Add check for product if present in current website
  • Loading branch information
carinadues authored Dec 9, 2021
2 parents 14834ea + 6c99545 commit 6974ea2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Model/Variant/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface;
use ScandiPWA\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CriteriaCheck;
use ScandiPWA\Performance\Model\Resolver\Products\CollectionPostProcessor;
Expand Down Expand Up @@ -73,6 +74,9 @@ class Collection
/** @var StockFilter */
protected $stockFilter;

/** @var StoreManagerInterface */
protected $storeManager;

/**
* Collection constructor.
*
Expand All @@ -85,7 +89,8 @@ class Collection
* @param DataPostProcessor $dataPostProcessor
* @param DataPostProcessor\Stocks $stocksPostProcessor
* @param ResourceConnection $connection
* @oaran StockFilter $stockFilter
* @param StockFilter $stockFilter
* @param StoreManagerInterface $storeManager
*/
public function __construct(
CollectionFactory $childCollectionFactory,
Expand All @@ -97,7 +102,8 @@ public function __construct(
DataPostProcessor $dataPostProcessor,
DataPostProcessor\Stocks $stocksPostProcessor,
ResourceConnection $connection,
StockFilter $stockFilter
StockFilter $stockFilter,
StoreManagerInterface $storeManager
) {
$this->childCollectionFactory = $childCollectionFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
Expand All @@ -109,6 +115,7 @@ public function __construct(
$this->collectionFactory = $collectionFactory;
$this->connection = $connection;
$this->stockFilter = $stockFilter;
$this->storeManager = $storeManager;

$this->searchCriteria = $this->searchCriteriaBuilder->create();
}
Expand Down Expand Up @@ -453,7 +460,10 @@ protected function fetchPlp($info) : array {
/** @var Product $product */
foreach ($products as $product) {
// Skip disabled products
if ($product->isDisabled()) {
if (
$product->isDisabled()
|| !in_array($this->storeManager->getWebsite()->getId(), $product->getWebsiteIds())
) {
continue;
}

Expand Down

0 comments on commit 6974ea2

Please sign in to comment.