Completed
Push — master ( c8e10c...47e8bc )
by
unknown
21s queued 16s
created

MerchantSwitcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Spryker Marketplace License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerShop\Yves\MerchantSwitcherWidget\MerchantSwitcher;
9
10
use Generated\Shared\Transfer\MerchantSwitchRequestTransfer;
11
use SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSwitcherClientInterface;
12
use SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToQuoteClientInterface;
13
14
class MerchantSwitcher implements MerchantSwitcherInterface
15
{
16
    /**
17
     * @var \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToQuoteClientInterface
18
     */
19
    protected $quoteClient;
20
21
    /**
22
     * @var \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSwitcherClientInterface
23
     */
24
    protected $merchantSwitcherClient;
25
26
    /**
27
     * @param \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToQuoteClientInterface $quoteClient
28
     * @param \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSwitcherClientInterface $merchantSwitcherClient
29
     */
30
    public function __construct(
31
        MerchantSwitcherWidgetToQuoteClientInterface $quoteClient,
32
        MerchantSwitcherWidgetToMerchantSwitcherClientInterface $merchantSwitcherClient
33
    ) {
34
        $this->quoteClient = $quoteClient;
35
        $this->merchantSwitcherClient = $merchantSwitcherClient;
36
    }
37
38
    /**
39
     * @param string $merchantReference
40
     *
41
     * @return void
42
     */
43
    public function switchMerchantInQuote(string $merchantReference): void
44
    {
45
        $quoteTransfer = $this->quoteClient->getQuote();
46
47
        if ($quoteTransfer->getMerchantReference() === $merchantReference) {
48
            return;
49
        }
50
51
        $merchantSwitchRequestTransfer = new MerchantSwitchRequestTransfer();
52
        $merchantSwitchRequestTransfer->setMerchantReference($merchantReference);
53
        $merchantSwitchRequestTransfer->setQuote($quoteTransfer);
54
55
        $quoteTransfer = $this->merchantSwitcherClient->switchMerchantInQuote($merchantSwitchRequestTransfer)->getQuote();
56
57
        $this->quoteClient->setQuote($quoteTransfer);
58
    }
59
}
60