-
Notifications
You must be signed in to change notification settings - Fork 3
/
CkoCheckoutPayment.php
134 lines (109 loc) · 5.15 KB
/
CkoCheckoutPayment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
namespace CkoCheckoutPayment;
use CkoCheckoutPayment\Components\DependencyInjection\PaymentMethodValidatorCompilerPass;
use CkoCheckoutPayment\Components\DependencyInjection\PaymentRequestHandlerCompilerPass;
use CkoCheckoutPayment\Installer\AttributeInstaller;
use CkoCheckoutPayment\Installer\DocumentInstaller;
use CkoCheckoutPayment\Installer\PaymentMethodInstaller;
use CkoCheckoutPayment\Installer\SchemaInstaller;
use Doctrine\DBAL\Connection;
use Shopware\Bundle\AttributeBundle\Service\CrudService;
use Shopware\Components\Model\ModelManager;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use Shopware\Components\Plugin\PaymentInstaller;
use Symfony\Component\DependencyInjection\ContainerBuilder;
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
class CkoCheckoutPayment extends Plugin
{
private const PLUGIN_MANAGER_NAMESPACE = 'backend/cko_checkout_payment/pluginmanager';
public function build(ContainerBuilder $container)
{
$container->setParameter('cko_checkout_payment.plugin_name', $this->getName());
$container->setParameter('cko_checkout_payment.plugin_dir', $this->getPath());
$container->addCompilerPass(new PaymentMethodValidatorCompilerPass());
$container->addCompilerPass(new PaymentRequestHandlerCompilerPass());
parent::build($container);
}
public function install(InstallContext $context)
{
$this->getPaymentMethodInstaller()->install($context);
$this->getAttributeInstaller()->install($context);
$this->getSchemaInstaller()->install($context);
$this->getDocumentInstaller()->install($context);
}
public function update(UpdateContext $context)
{
$this->getPaymentMethodInstaller()->update($context);
$this->getAttributeInstaller()->update($context);
$this->getSchemaInstaller()->update($context);
$this->getDocumentInstaller()->update($context);
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
public function uninstall(UninstallContext $context)
{
$this->getPaymentMethodInstaller()->uninstall($context);
$this->getAttributeInstaller()->uninstall($context);
$this->getSchemaInstaller()->uninstall($context);
$this->getDocumentInstaller()->uninstall($context);
}
public function deactivate(DeactivateContext $context)
{
$this->getPaymentMethodInstaller()->deactivate($context);
$this->getAttributeInstaller()->deactivate($context);
$this->getSchemaInstaller()->deactivate($context);
$this->getDocumentInstaller()->deactivate($context);
$context->scheduleClearCache(DeactivateContext::CACHE_LIST_ALL);
}
public function activate(ActivateContext $context)
{
$this->getPaymentMethodInstaller()->activate($context);
$this->getAttributeInstaller()->activate($context);
$this->getSchemaInstaller()->activate($context);
$this->getDocumentInstaller()->activate($context);
/** @var \Enlight_Components_Snippet_Manager $snippetManager */
$snippetManager = $this->container->get('snippets');
$snippetNamespace = $snippetManager->getNamespace(self::PLUGIN_MANAGER_NAMESPACE);
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
$context->scheduleMessage($snippetNamespace->get('reload/message'));
}
private function getPaymentMethodInstaller(): PaymentMethodInstaller
{
/** @var PaymentInstaller $paymentInstaller */
$paymentInstaller = $this->container->get('shopware.plugin_payment_installer');
/** @var ModelManager $modelManager */
$modelManager = $this->container->get('models');
return new PaymentMethodInstaller($paymentInstaller, $modelManager);
}
private function getAttributeInstaller(): AttributeInstaller
{
/** @var CrudService $crudService */
$crudService = $this->container->get('shopware_attribute.crud_service');
/** @var ModelManager $modelManager */
$modelManager = $this->container->get('models');
return new AttributeInstaller($crudService, $modelManager);
}
private function getSchemaInstaller(): SchemaInstaller
{
/** @var ModelManager $modelManager */
$modelManager = $this->container->get('models');
return new SchemaInstaller($modelManager);
}
private function getDocumentInstaller(): DocumentInstaller
{
/** @var ModelManager $modelManager */
$modelManager = $this->container->get('models');
/** @var Connection $connection */
$connection = $this->container->get('dbal_connection');
/** @var \Shopware_Components_Translation $translationService */
$translationService = $this->container->get('translation');
return new DocumentInstaller($modelManager, $connection, $translationService);
}
}