1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gewebe\SyliusProductDepositPlugin\Templating\Helper; |
6
|
|
|
|
7
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\AdjustmentInterface; |
8
|
|
|
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface; |
9
|
|
|
use Gewebe\SyliusProductDepositPlugin\Provider\ProductVariantsDepositsProviderInterface; |
10
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
11
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
12
|
|
|
use Sylius\Component\Core\Model\OrderItemUnit; |
13
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
14
|
|
|
use Symfony\Component\Templating\Helper\Helper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Template helper to get product variant deposit prices |
18
|
|
|
*/ |
19
|
|
|
class ProductVariantsDepositHelper extends Helper |
20
|
|
|
{ |
21
|
|
|
/** @var ProductVariantsDepositsProviderInterface */ |
22
|
|
|
private $productVariantsDepositProvider; |
23
|
|
|
|
24
|
|
|
public function __construct(ProductVariantsDepositsProviderInterface $productVariantsDepositProvider) |
25
|
|
|
{ |
26
|
|
|
$this->productVariantsDepositProvider = $productVariantsDepositProvider; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get deposit price by given product variant and channel |
31
|
|
|
*/ |
32
|
|
|
public function getDeposit(ProductVariantInterface $productVariant, ChannelInterface $channel): ?int |
33
|
|
|
{ |
34
|
|
|
return $productVariant->getDepositPriceByChannel($channel) ?? null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get deposit prices by given product and channel |
39
|
|
|
*/ |
40
|
|
|
public function getDepositsByProduct(ProductInterface $product, ChannelInterface $channel): array |
41
|
|
|
{ |
42
|
|
|
return $this->productVariantsDepositProvider->provideVariantsDeposits($product, $channel); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getDepositByOrderItem(OrderItemInterface $orderItem): ?int |
46
|
|
|
{ |
47
|
|
|
if ($orderItem->getUnits()->count() === 0) { |
48
|
|
|
return null; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @var OrderItemUnit $firstUnit */ |
52
|
|
|
$firstUnit = $orderItem->getUnits()->first(); |
53
|
|
|
|
54
|
|
|
return $firstUnit->getAdjustmentsTotal(AdjustmentInterface::DEPOSIT_ADJUSTMENT); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getName(): string |
58
|
|
|
{ |
59
|
|
|
return 'gewebe_product_variants_deposit'; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|