|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gewebe\SyliusProductDepositPlugin\Templating\Helper; |
|
6
|
|
|
|
|
7
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface; |
|
8
|
|
|
use Gewebe\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
|
|
|
class ProductVariantsDepositHelper extends Helper |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ProductVariantsDepositsProviderInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $productVariantsDepositProvider; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(ProductVariantsDepositsProviderInterface $productVariantsDepositProvider) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->productVariantsDepositProvider = $productVariantsDepositProvider; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get deposit price by given product variant and channel |
|
30
|
|
|
* @param ProductVariantInterface $productVariant |
|
31
|
|
|
* @param ChannelInterface $channel |
|
32
|
|
|
* @return int|null |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getDeposit(ProductVariantInterface $productVariant, ChannelInterface $channel): ?int |
|
35
|
|
|
{ |
|
36
|
|
|
$channelDeposit = $productVariant->getChannelDepositForChannel($channel); |
|
37
|
|
|
if (null != $channelDeposit) { |
|
38
|
|
|
return $channelDeposit->getPrice(); |
|
39
|
|
|
} |
|
40
|
|
|
return null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get deposit prices by given product and channel |
|
45
|
|
|
* @param ProductInterface $product |
|
46
|
|
|
* @param ChannelInterface $channel |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getDepositsByProduct(ProductInterface $product, ChannelInterface $channel): array |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->productVariantsDepositProvider->provideVariantsDeposits($product, $channel); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getName(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return 'gewebe_product_variants_deposit'; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|