1 | <?php |
||
12 | class ProductResolver implements ProductResolverInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var ProductCollectionFactory |
||
16 | */ |
||
17 | private $productCollectionFactory; |
||
18 | |||
19 | /** |
||
20 | * @var ProductFactory |
||
21 | */ |
||
22 | private $productFactory; |
||
23 | |||
24 | /** |
||
25 | * @param ProductCollectionFactory $productCollectionFactory |
||
26 | * @param ProductFactory $productFactory |
||
27 | */ |
||
28 | public function __construct( |
||
35 | |||
36 | /** |
||
37 | * @param string $urlKey |
||
38 | * @param int $storeId |
||
39 | * |
||
40 | * @return EntityData |
||
41 | */ |
||
42 | public function resolveByUrlKey(string $urlKey, int $storeId) : EntityData |
||
43 | { |
||
44 | $productId = $this->productCollectionFactory->create() |
||
45 | ->addStoreFilter($storeId) |
||
46 | ->addAttributeToFilter('url_key', $urlKey) |
||
47 | ->getFirstItem() |
||
48 | ->getId(); |
||
49 | |||
50 | if (!$productId) { |
||
51 | throw new EntityDataNotFoundException('Product does not exist'); |
||
52 | } |
||
53 | |||
54 | return new EntityData('product', $productId, $urlKey); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $urlKey |
||
59 | * @param int $storeId |
||
60 | * |
||
61 | * @return EntityData[] |
||
62 | */ |
||
63 | public function resolveAllByUrlKey(string $urlKey, int $storeId) : array |
||
77 | |||
78 | /** |
||
79 | * @param int $productId |
||
80 | * @param int $storeId |
||
81 | * |
||
82 | * @return EntityData |
||
83 | */ |
||
84 | public function resolveById(int $productId, int $storeId) : EntityData |
||
85 | { |
||
86 | $urlKey = $this->productCollectionFactory->create() |
||
87 | ->addStoreFilter($storeId) |
||
88 | ->addAttributeToSelect('url_key') |
||
89 | ->addAttributeToFilter('entity_id', $productId) |
||
90 | ->getFirstItem() |
||
91 | ->getUrlKey(); |
||
92 | |||
93 | if (!$urlKey) { |
||
94 | throw new EntityDataNotFoundException('Product does not exist'); |
||
95 | } |
||
96 | |||
97 | return new EntityData('product', $productId, $urlKey); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param int $productId |
||
102 | * @param int $storeId |
||
103 | * |
||
104 | * @return int[] |
||
105 | */ |
||
106 | public function resolveCategoryIds(int $productId, int $storeId) : array |
||
119 | } |
||
120 |