|
1 | 1 | <?php
|
| 2 | +declare(strict_types=1); |
2 | 3 |
|
3 | 4 | namespace Snowdog\Menu\Model\GraphQl\Resolver\DataProvider\Node;
|
4 | 5 |
|
5 |
| -use Magento\Catalog\Api\CategoryRepositoryInterface; |
6 | 6 | use Magento\Catalog\Api\Data\CategoryInterface;
|
7 | 7 | use Magento\Catalog\Api\Data\ProductInterface;
|
8 |
| -use Magento\Catalog\Api\ProductRepositoryInterface; |
9 | 8 | use Magento\Cms\Api\Data\PageInterface;
|
10 |
| -use Magento\Cms\Api\PageRepositoryInterface; |
11 |
| -use Magento\Framework\Exception\LocalizedException; |
12 |
| -use Magento\Framework\Exception\NoSuchEntityException; |
13 | 9 |
|
14 | 10 | class TypeModel
|
15 | 11 | {
|
16 | 12 | const TYPES = ["category", "product", "cms_page"];
|
17 |
| - |
18 |
| - /** |
19 |
| - * @var ProductRepositoryInterface |
20 |
| - */ |
21 |
| - private $productRepository; |
22 |
| - /** |
23 |
| - * @var CategoryRepositoryInterface |
24 |
| - */ |
25 |
| - private $categoryRepository; |
| 13 | + |
26 | 14 | /**
|
27 |
| - * @var PageRepositoryInterface |
| 15 | + * @var \Snowdog\Menu\Model\ResourceModel\NodeType\AbstractNode[] |
28 | 16 | */
|
29 |
| - private $pageRepository; |
| 17 | + private $typeModels = []; |
30 | 18 |
|
31 | 19 | public function __construct(
|
32 |
| - ProductRepositoryInterface $productRepository, |
33 |
| - CategoryRepositoryInterface $categoryRepository, |
34 |
| - PageRepositoryInterface $pageRepository |
| 20 | + array $typeModels = [] |
35 | 21 | ) {
|
36 |
| - $this->productRepository = $productRepository; |
37 |
| - $this->categoryRepository = $categoryRepository; |
38 |
| - $this->pageRepository = $pageRepository; |
| 22 | + $this->typeModels = $typeModels; |
39 | 23 | }
|
40 | 24 |
|
41 |
| - /** |
42 |
| - * @param $type |
43 |
| - * @param $modelId |
44 |
| - * @param $storeId |
45 |
| - * @return ProductInterface|CategoryInterface|PageInterface|null |
46 |
| - * @throws LocalizedException |
47 |
| - * @throws NoSuchEntityException |
48 |
| - */ |
49 |
| - public function getModel($type, $modelId, $storeId) |
| 25 | + public function getModels($type, $modelIds, $storeId) |
50 | 26 | {
|
51 |
| - $model = null; |
52 |
| - switch ($type) { |
53 |
| - case "product": |
54 |
| - $model = $this->productRepository->getById($modelId, false, $storeId); |
55 |
| - break; |
56 |
| - case "category": |
57 |
| - $model = $this->categoryRepository->get($modelId, $storeId); |
58 |
| - break; |
59 |
| - case "cms_page": |
60 |
| - $model = $this->pageRepository->getById($modelId); |
61 |
| - break; |
62 |
| - default: |
63 |
| - break; |
| 27 | + if (isset($this->typeModels[$type])) { |
| 28 | + return $this->typeModels[$type]->fetchData($storeId, $modelIds); |
64 | 29 | }
|
65 |
| - return $model; |
| 30 | + |
| 31 | + return []; |
66 | 32 | }
|
67 | 33 |
|
68 | 34 | public function getModelUrlKey($type, $model): ?string
|
|
0 commit comments