1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace Spryker\Glue\ProductLabelsRestApi\Processor\Expander; |
||
9 | |||
10 | use Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface; |
||
11 | use Spryker\Glue\ProductLabelsRestApi\Processor\Reader\ProductLabelReaderInterface; |
||
12 | |||
13 | class ProductLabelResourceRelationshipExpander implements ProductLabelResourceRelationshipExpanderInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var \Spryker\Glue\ProductLabelsRestApi\Processor\Reader\ProductLabelReaderInterface |
||
17 | */ |
||
18 | protected $productLabelReader; |
||
19 | |||
20 | /** |
||
21 | * @param \Spryker\Glue\ProductLabelsRestApi\Processor\Reader\ProductLabelReaderInterface $productLabelReader |
||
22 | */ |
||
23 | public function __construct(ProductLabelReaderInterface $productLabelReader) |
||
24 | { |
||
25 | $this->productLabelReader = $productLabelReader; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param array<\Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface> $resources |
||
30 | * @param \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface $restRequest |
||
31 | * |
||
32 | * @return array<\Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface> |
||
33 | */ |
||
34 | public function addRelationshipsByAbstractSku(array $resources, RestRequestInterface $restRequest): array |
||
35 | { |
||
36 | foreach ($resources as $resource) { |
||
37 | $abstractSku = $resource->getId(); |
||
38 | |||
39 | $productLabels = $this->productLabelReader->getProductLabelsByAbstractSku( |
||
40 | $abstractSku, |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
41 | $restRequest->getMetadata()->getLocale(), |
||
42 | ); |
||
43 | foreach ($productLabels as $productLabel) { |
||
44 | $resource->addRelationship($productLabel); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return $resources; |
||
49 | } |
||
50 | } |
||
51 |