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\Form\Type\Pricing; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
15
|
|
|
use Symfony\Component\Form\AbstractType; |
16
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ZoneBasedConfigurationType extends AbstractType |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var RepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
protected $zoneRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param RepositoryInterface $zoneRepository |
31
|
|
|
*/ |
32
|
|
|
public function __construct(RepositoryInterface $zoneRepository) |
33
|
|
|
{ |
34
|
|
|
$this->zoneRepository = $zoneRepository; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
41
|
|
|
{ |
42
|
|
|
foreach ($this->getZones($options) as $zone) { |
43
|
|
|
$builder |
44
|
|
|
->add($zone->getId(), 'sylius_money', [ |
45
|
|
|
'label' => $zone->getName(), |
46
|
|
|
'required' => false, |
47
|
|
|
]) |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function configureOptions(OptionsResolver $resolver) |
56
|
|
|
{ |
57
|
|
|
$resolver |
58
|
|
|
->setDefaults([ |
59
|
|
|
'data_class' => null, |
60
|
|
|
'scope' => null, |
61
|
|
|
]) |
62
|
|
|
; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function getName() |
69
|
|
|
{ |
70
|
|
|
return 'sylius_price_calculator_zone_based'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $options |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
private function getZones(array $options) |
79
|
|
|
{ |
80
|
|
|
if (isset($options['scope'])) { |
81
|
|
|
return $this->zoneRepository->findBy(['scope' => $options['scope']]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this->zoneRepository->findAll(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|