Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourcesSelection.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
19 {
23  private $sourceRepository;
24 
28  private $bulkSessionProductsStorage;
29 
33  private $searchCriteriaBuilder;
34 
38  private $getSourceCodesBySkus;
39 
47  public function __construct(
48  SourceRepositoryInterface $sourceRepository,
49  SearchCriteriaBuilder $searchCriteriaBuilder,
50  GetSourceCodesBySkusInterface $getSourceCodesBySkus,
51  BulkSessionProductsStorage $bulkSessionProductsStorage
52  ) {
53  $this->sourceRepository = $sourceRepository;
54  $this->bulkSessionProductsStorage = $bulkSessionProductsStorage;
55  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
56  $this->getSourceCodesBySkus = $getSourceCodesBySkus;
57  }
58 
63  public function getSources(): array
64  {
65  return $this->sourceRepository->getList()->getItems();
66  }
67 
72  public function getAssignedSources(): array
73  {
74  $skus = $this->bulkSessionProductsStorage->getProductsSkus();
75  $sourceCodes = $this->getSourceCodesBySkus->execute($skus);
76 
77  $searchCriteria = $this->searchCriteriaBuilder
78  ->addFilter(
80  $sourceCodes,
81  'in'
82  )
83  ->create();
84 
85  return $this->sourceRepository->getList($searchCriteria)->getItems();
86  }
87 
91  public function getProductsCount(): int
92  {
93  return count($this->bulkSessionProductsStorage->getProductsSkus());
94  }
95 }
__construct(SourceRepositoryInterface $sourceRepository, SearchCriteriaBuilder $searchCriteriaBuilder, GetSourceCodesBySkusInterface $getSourceCodesBySkus, BulkSessionProductsStorage $bulkSessionProductsStorage)
foreach($websiteCodes as $websiteCode) $skus
$searchCriteria
$searchCriteriaBuilder
$sourceRepository
Definition: source.php:20