1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\InvoiceBundle\EventListener; |
14
|
|
|
|
15
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Shop; |
16
|
|
|
use WellCommerce\Bundle\CoreBundle\EventListener\AbstractEventSubscriber; |
17
|
|
|
use WellCommerce\Bundle\InvoiceBundle\Processor\InvoiceProcessorInterface; |
18
|
|
|
use WellCommerce\Component\Form\Event\FormEvent; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class InvoiceSubscriber |
22
|
|
|
* |
23
|
|
|
* @author Adam Piotrowski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class InvoiceSubscriber extends AbstractEventSubscriber |
26
|
|
|
{ |
27
|
|
|
public static function getSubscribedEvents() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
'admin.shop.pre_form_init' => ['onShopFormAdminInit'], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function onShopFormAdminInit(FormEvent $event) |
35
|
|
|
{ |
36
|
|
|
$resource = $event->getResource(); |
37
|
|
|
if ($resource instanceof Shop) { |
38
|
|
|
$form = $event->getForm(); |
39
|
|
|
$builder = $event->getFormBuilder(); |
40
|
|
|
|
41
|
|
|
$invoiceData = $form->addChild($builder->getElement('nested_fieldset', [ |
42
|
|
|
'name' => 'invoice_data', |
43
|
|
|
'label' => 'invoice.fieldset.settings', |
44
|
|
|
])); |
45
|
|
|
|
46
|
|
|
$invoiceData->addChild($builder->getElement('text_field', [ |
47
|
|
|
'name' => 'invoiceMaturity', |
48
|
|
|
'label' => 'invoice.label.maturity', |
49
|
|
|
'default' => 7, |
50
|
|
|
])); |
51
|
|
|
|
52
|
|
|
$options = []; |
53
|
|
|
$processors = $this->get('invoice.processor.collection'); |
54
|
|
|
$processorKeys = $processors->keys(); |
55
|
|
|
|
56
|
|
|
/** @var InvoiceProcessorInterface $processor */ |
57
|
|
|
foreach ($processors->all() as $processor) { |
58
|
|
|
$processorName = $processor->getAlias(); |
59
|
|
|
$options[$processorName] = $processorName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$defaultProcessor = reset($processorKeys); |
63
|
|
|
|
64
|
|
|
$invoiceData->addChild($builder->getElement('select', [ |
65
|
|
|
'name' => 'invoiceProcessor', |
66
|
|
|
'label' => 'invoice.label.processor', |
67
|
|
|
'default' => $defaultProcessor, |
68
|
|
|
'options' => $options, |
69
|
|
|
])); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|