Completed
Push — master ( cfaf77...b5ed7c )
by Kamil
47:11 queued 29:42
created

getPriceForCurrentChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Templating\Helper;
13
14
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Core\Model\ProductVariantInterface;
17
use Sylius\Component\Order\Context\CartContextInterface;
18
use Symfony\Component\Templating\Helper\Helper;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
class ChannelBasedPriceHelper extends Helper implements ChannelBasedPriceHelperInterface
24
{
25
    /**
26
     * @var CartContextInterface
27
     */
28
    private $cartContext;
29
30
    /**
31
     * @var ProductVariantPriceCalculatorInterface
32
     */
33
    private $productVariantPriceCalculator;
34
35
    /**
36
     * @param CartContextInterface $cartContext
37
     * @param ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
38
     */
39
    public function __construct(
40
        CartContextInterface $cartContext,
41
        ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $productVariantPriceCalculator exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
42
    ) {
43
        $this->cartContext = $cartContext;
44
        $this->productVariantPriceCalculator = $productVariantPriceCalculator;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getPriceForCurrentChannel(ProductVariantInterface $productVariant)
51
    {
52
        /** @var OrderInterface $currentCart */
53
        $currentCart = $this->cartContext->getCart();
54
55
        return $this
56
            ->productVariantPriceCalculator
57
            ->calculate($productVariant, ['channel' => $currentCart->getChannel()])
58
        ;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getName()
65
    {
66
        return 'sylius_channel_variant_price';
67
    }
68
}
69