ProductUrlExpander::expandItemsWithUrl()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace Pyz\Zed\ProductUrlCartConnector\Business\Expander;
11
12
use Generated\Shared\Transfer\CartChangeTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CartChangeTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\ProductAbstractTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ProductAbstractTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Spryker\Zed\Locale\Business\LocaleFacadeInterface;
16
use Spryker\Zed\Product\Business\ProductFacadeInterface;
17
18
class ProductUrlExpander implements ProductUrlExpanderInterface
19
{
20
    /**
21
     * @var \Spryker\Zed\Product\Business\ProductFacadeInterface
22
     */
23
    protected $productFacade;
24
25
    /**
26
     * @var \Spryker\Zed\Locale\Business\LocaleFacadeInterface
27
     */
28
    protected $localeFacade;
29
30
    /**
31
     * @param \Spryker\Zed\Product\Business\ProductFacadeInterface $productFacade
32
     * @param \Spryker\Zed\Locale\Business\LocaleFacadeInterface $localeFacade
33
     */
34
    public function __construct(
35
        ProductFacadeInterface $productFacade,
36
        LocaleFacadeInterface $localeFacade,
37
    ) {
38
        $this->productFacade = $productFacade;
39
        $this->localeFacade = $localeFacade;
40
    }
41
42
    /**
43
     * @param \Generated\Shared\Transfer\CartChangeTransfer $cartChangeTransfer
44
     *
45
     * @return \Generated\Shared\Transfer\CartChangeTransfer
46
     */
47
    public function expandItems(CartChangeTransfer $cartChangeTransfer): CartChangeTransfer
48
    {
49
        foreach ($cartChangeTransfer->getItems() as $itemTransfer) {
50
            $this->expandItemsWithUrl($itemTransfer);
51
        }
52
53
        return $cartChangeTransfer;
54
    }
55
56
    /**
57
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
58
     *
59
     * @return void
60
     */
61
    protected function expandItemsWithUrl(ItemTransfer $itemTransfer): void
62
    {
63
        $idLocale = $this->localeFacade->getCurrentLocale()->getIdLocale();
64
        $productAbstractTransfer = new ProductAbstractTransfer();
65
        $productAbstractTransfer
66
            ->setSku($itemTransfer->getAbstractSku())
67
            ->setIdProductAbstract($itemTransfer->getIdProductAbstract());
68
        $productUrlTransfer = $this->productFacade->getProductUrl($productAbstractTransfer);
69
        foreach ($productUrlTransfer->getUrls() as $localizedUrlTransfer) {
70
            if ($localizedUrlTransfer->getLocale() === null || $localizedUrlTransfer->getLocale()->getIdLocale() !== $idLocale) {
71
                continue;
72
            }
73
74
            $itemTransfer->setUrl($localizedUrlTransfer->getUrl());
75
        }
76
    }
77
}
78