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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\CoreBundle\Templating\Helper; |
15
|
|
|
|
16
|
|
|
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface; |
17
|
|
|
use Sylius\Component\Core\Calculator\ProductVariantPricesCalculatorInterface; |
18
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
19
|
|
|
use Symfony\Component\Templating\Helper\Helper; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
class PriceHelper extends Helper |
23
|
|
|
{ |
24
|
|
|
/** @var ProductVariantPriceCalculatorInterface */ |
25
|
|
|
private $productVariantPriceCalculator; |
26
|
|
|
|
27
|
|
|
public function __construct(ProductVariantPriceCalculatorInterface $productVariantPriceCalculator) |
28
|
|
|
{ |
29
|
|
|
$this->productVariantPriceCalculator = $productVariantPriceCalculator; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
* |
35
|
|
|
* @throws \InvalidArgumentException |
36
|
|
|
*/ |
37
|
|
|
public function getPrice(ProductVariantInterface $productVariant, array $context): int |
38
|
|
|
{ |
39
|
|
|
Assert::keyExists($context, 'channel'); |
40
|
|
|
|
41
|
|
|
return $this |
42
|
|
|
->productVariantPriceCalculator |
43
|
|
|
->calculate($productVariant, $context) |
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
* |
50
|
|
|
* @throws \InvalidArgumentException |
51
|
|
|
*/ |
52
|
|
|
public function getOriginalPrice(ProductVariantInterface $productVariant, array $context): int |
53
|
|
|
{ |
54
|
|
|
Assert::keyExists($context, 'channel'); |
55
|
|
|
Assert::isInstanceOf($this->productVariantPriceCalculator, ProductVariantPricesCalculatorInterface::class); |
56
|
|
|
|
57
|
|
|
return $this |
|
|
|
|
58
|
|
|
->productVariantPriceCalculator |
59
|
|
|
->calculateOriginal($productVariant, $context); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
* |
65
|
|
|
* @throws \InvalidArgumentException |
66
|
|
|
*/ |
67
|
|
|
public function hasDiscount(ProductVariantInterface $productVariant, array $context): bool |
68
|
|
|
{ |
69
|
|
|
Assert::keyExists($context, 'channel'); |
70
|
|
|
Assert::isInstanceOf($this->productVariantPriceCalculator, ProductVariantPricesCalculatorInterface::class); |
71
|
|
|
|
72
|
|
|
return $this->getOriginalPrice($productVariant, $context) > $this->getPrice($productVariant, $context); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getName(): string |
79
|
|
|
{ |
80
|
|
|
return 'sylius_calculate_price'; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.