-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLdNanoIntegration.php
More file actions
90 lines (79 loc) · 2.54 KB
/
LdNanoIntegration.php
File metadata and controls
90 lines (79 loc) · 2.54 KB
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
<?php
namespace LdNanoIntegration;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
class LdNanoIntegration extends Plugin
{
/**
* @param InstallContext $context
*/
public function install(InstallContext $context)
{
$this->addPayment($context->getPlugin());
$this->addTokenAttribute();
$context->scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT);
}
private function addTokenAttribute()
{
$service = $this->container->get('shopware_attribute.crud_service');
$service->update('s_order_attributes', 'brainblocks_token', 'text', [
'displayInBackend' => true,
'label' => 'Brainblocks Token'
]);
}
private function addPayment(\Shopware\Models\Plugin\Plugin $plugin)
{
/** @var \Shopware\Components\Plugin\PaymentInstaller $installer */
$installer = $this->container->get('shopware.plugin_payment_installer');
$options = [
'name' => 'nano_payment',
'description' => 'Pay with Nano',
'action' => 'NanoPayment',
'active' => 0,
'position' => 0,
'additionalDescription' =>
'<div id="payment_desc">'
. ' Pay with Nano (using brainblocks.io)'
. '</div>'
];
$installer->createOrUpdate($plugin, $options);
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context)
{
$this->setPaymentActiveFlag($context, false);
$context->scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT);
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context)
{
$this->setPaymentActiveFlag($context, false);
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context)
{
$this->setPaymentActiveFlag($context, true);
}
/**
* @param InstallContext $context
* @param bool $active
*/
private function setPaymentActiveFlag(InstallContext $context, $active)
{
$em = $this->container->get('models');
$payments = $context->getPlugin()->getPayments();
foreach ($payments as $payment) {
$payment->setActive($active);
}
$em->flush();
}
}