1 | <?php |
||
12 | class CategoryResolver implements CategoryResolverInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var CategoryCollectionFactory |
||
16 | */ |
||
17 | private $categoryCollectionFactory; |
||
18 | |||
19 | /** |
||
20 | * @var StoreManagerInterface |
||
21 | */ |
||
22 | private $storeManager; |
||
23 | |||
24 | /** |
||
25 | * @param CategoryCollectionFactory $categoryCollectionFactory |
||
26 | * @param StoreManagerInterface $storeManager |
||
27 | */ |
||
28 | public function __construct( |
||
35 | |||
36 | /** |
||
37 | * @param string $urlKey |
||
38 | * @param int $storeId |
||
39 | * @param int $parentId |
||
40 | * |
||
41 | * @return EntityData |
||
42 | */ |
||
43 | public function resolveByUrlKey(string $urlKey, int $storeId, int $parentId) : EntityData |
||
58 | |||
59 | /** |
||
60 | * @param string $urlKey |
||
61 | * @param int $storeId |
||
62 | * @param int $parentId |
||
63 | * |
||
64 | * @return EntityData[] |
||
65 | */ |
||
66 | public function resolveAllByUrlKey(string $urlKey, int $storeId, int $parentId) : array |
||
81 | |||
82 | /** |
||
83 | * @param int $categoryId |
||
84 | * @param int $storeId |
||
85 | * |
||
86 | * @return EntityData |
||
87 | */ |
||
88 | public function resolveById(int $categoryId, int $storeId) : EntityData |
||
89 | { |
||
90 | $urlKey = $this->categoryCollectionFactory->create() |
||
91 | ->setStoreId($storeId) |
||
92 | ->addAttributeToSelect('url_key') |
||
93 | ->addFieldToFilter('entity_id', $categoryId) |
||
94 | ->getFirstItem() |
||
95 | ->getUrlKey(); |
||
96 | |||
97 | if (!$urlKey) { |
||
98 | throw new EntityDataNotFoundException('Category does not exist'); |
||
99 | } |
||
100 | |||
101 | return new EntityData('category', $categoryId, $urlKey); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param int $categoryId |
||
106 | * @param int $storeId |
||
107 | * |
||
108 | * @return int[] |
||
109 | */ |
||
110 | public function resolveParentIds(int $categoryId, int $storeId) : array |
||
133 | } |
||
134 |