-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZerintBarzahlenViacash.php
110 lines (97 loc) · 3.43 KB
/
ZerintBarzahlenViacash.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
<?php
namespace ZerintBarzahlenViacash;
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\Models\Payment\Payment;
class ZerintBarzahlenViacash extends Plugin
{
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PreDispatch_Frontend' => ['onFrontend',-100],
'Enlight_Controller_Action_PreDispatch_Widgets' => ['onFrontend',-100]
];
}
/**
* @param InstallContext $context
*/
public function install(InstallContext $context)
{
/** @var \Shopware\Components\Plugin\PaymentInstaller $installer */
$installer = $this->container->get('shopware.plugin_payment_installer');
$options = [
'name' => 'barzahlen',
'description' => ' Barzahlen/viacash - Online Payment',
'action' => 'frontend/barzahlen',
'active' => 1,
'position' => 0,
'additionalDescription' =>
'<img src="https://cdn.barzahlen.de/images/viafintech_splitlogo.png"/>'
. '<div id="payment_desc">'
. ' Pay online in cash | Online bar bezahlen '
. '</div>'
];
$installer->createOrUpdate($context->getPlugin(), $options);
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context)
{
$this->setActiveFlag($context->getPlugin()->getPayments(), false);
/** @var \Shopware\Components\CacheManager $cacheManager */
$cacheManager = Shopware()->Container()->get('shopware.cache_manager');
$cacheManager->clearHttpCache();
$cacheManager->clearConfigCache();
$cacheManager->clearTemplateCache();
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context)
{
$this->setActiveFlag($context->getPlugin()->getPayments(), false);
/** @var \Shopware\Components\CacheManager $cacheManager */
$cacheManager = Shopware()->Container()->get('shopware.cache_manager');
$cacheManager->clearHttpCache();
$cacheManager->clearConfigCache();
$cacheManager->clearTemplateCache();
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context)
{
$this->setActiveFlag($context->getPlugin()->getPayments(), true);
/** @var \Shopware\Components\CacheManager $cacheManager */
$cacheManager = Shopware()->Container()->get('shopware.cache_manager');
$cacheManager->clearHttpCache();
$cacheManager->clearConfigCache();
$cacheManager->clearTemplateCache();
}
/**
* @param Payment[] $payments
* @param $active bool
*/
private function setActiveFlag($payments, $active)
{
$em = $this->container->get('models');
foreach ($payments as $payment) {
$payment->setActive($active);
}
$em->flush();
}
/**
* @param \Enlight_Event_EventArgs $args
* @throws \Exception
*/
public function onFrontend(\Enlight_Event_EventArgs $args)
{
$this->container->get('Template')->addTemplateDir(
$this->getPath() . '/Resources/views/'
);
}
}