|
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\Validator\Constraints; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
|
15
|
|
|
use Sylius\Component\Core\Model\ChannelPricingInterface; |
|
16
|
|
|
use Symfony\Component\Validator\Constraint; |
|
17
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
|
18
|
|
|
use Webmozart\Assert\Assert; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class HasAllPricesDefinedValidator extends ConstraintValidator |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ChannelRepositoryInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $channelRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ChannelRepositoryInterface $channelRepository |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(ChannelRepositoryInterface $channelRepository) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->channelRepository = $channelRepository; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function validate($productVariant, Constraint $constraint) |
|
42
|
|
|
{ |
|
43
|
|
|
Assert::isInstanceOf($constraint, HasAllPricesDefined::class); |
|
44
|
|
|
|
|
45
|
|
|
$channels = $productVariant->getProduct()->getChannels(); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($channels as $channel) { |
|
48
|
|
|
/** @var ChannelPricingInterface $channelPricing */ |
|
49
|
|
|
$channelPricing = $productVariant->getChannelPricingForChannel($channel); |
|
50
|
|
|
if (null === $channelPricing || null === $channelPricing->getPrice()) { |
|
51
|
|
|
$this->context->buildViolation($constraint->message) |
|
52
|
|
|
->atPath('channelPricings') |
|
53
|
|
|
->addViolation() |
|
54
|
|
|
; |
|
55
|
|
|
|
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|