Completed
Push — master ( 35f668...d57f4e )
by G
03:55
created

getDepositsByProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gweb\SyliusProductDepositPlugin\Templating\Helper;
6
7
use Gweb\SyliusProductDepositPlugin\Entity\ProductVariantInterface;
8
use Gweb\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProviderInterface;
9
use Sylius\Component\Core\Model\ChannelInterface;
10
use Sylius\Component\Core\Model\ProductInterface;
11
use Symfony\Component\Templating\Helper\Helper;
12
13
/**
14
 * Template helper to get product variant deposit prices
15
 *
16
 * @author Gerd Weitenberg <[email protected]>
17
 */
18
class ProductVariantsDepositHelper extends Helper
19
{
20
    /**
21
     * @var ProductVariantsDepositsProviderInterface
22
     */
23
    private $productVariantsDepositProvider;
24
25
    public function __construct(ProductVariantsDepositsProviderInterface $productVariantsDepositProvider)
26
    {
27
        $this->productVariantsDepositProvider = $productVariantsDepositProvider;
28
    }
29
30
    /**
31
     * Get deposit price by given product variant and channel
32
     * @param ProductVariantInterface $productVariant
33
     * @param ChannelInterface $channel
34
     * @return int|null
35
     */
36
    public function getDeposit(ProductVariantInterface $productVariant, ChannelInterface $channel): ?int
37
    {
38
        $channelDeposit = $productVariant->getChannelDepositForChannel($channel);
39
        if (null != $channelDeposit) {
40
            return $channelDeposit->getPrice();
41
        }
42
        return null;
43
    }
44
45
    /**
46
     * Get deposit prices by given product and channel
47
     * @param ProductInterface $product
48
     * @param ChannelInterface $channel
49
     * @return array
50
     */
51
    public function getDepositsByProduct(ProductInterface $product, ChannelInterface $channel): array
52
    {
53
        return $this->productVariantsDepositProvider->provideVariantsDeposits($product, $channel);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getName(): string
60
    {
61
        return 'gweb_product_variants_deposit';
62
    }
63
}
64