-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemoPostcodeEuPlugin.php
151 lines (134 loc) · 4.96 KB
/
MemoPostcodeEuPlugin.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
namespace MemoPostcodeEuPlugin;
use Shopware\Bundle\AttributeBundle\Service\TypeMapping;
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;
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
class MemoPostcodeEuPlugin extends Plugin
{
public function activate(ActivateContext $context)
{
parent::activate($context); // TODO: Change the autogenerated stub
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
public function deactivate(DeactivateContext $deactivateContext)
{
parent::deactivate($deactivateContext); // TODO: Change the autogenerated stub
$deactivateContext->scheduleClearCache(DeactivateContext::CACHE_LIST_ALL);
}
public function install(InstallContext $context)
{
$this->createAddressAttributes();
}
public function uninstall(UninstallContext $context)
{
if ($context->keepUserData()) {
return;
}
$this->removeAddressAttributes();
}
public function update(UpdateContext $context)
{
$existingVersion = $context->getCurrentVersion();
switch (true) {
case version_compare($existingVersion, '3.1.0', '<='):
$this->createAddressAttributes();
}
$context->scheduleClearCache(UpdateContext::CACHE_LIST_ALL);
}
private function createAddressAttributes()
{
$service = $this->container->get('shopware_attribute.crud_service');
$service->update(
's_user_addresses_attributes',
'postcode_eu_streetname',
TypeMapping::TYPE_STRING,
[
'position' => 1,
'displayInBackend' => true,
'label' => 'Postcode.eu Streetname',
'readonly' => true,
'translatable' => true,
]
);
$service->update(
's_user_addresses_attributes',
'postcode_eu_housenumber',
TypeMapping::TYPE_STRING,
[
'position' => 2,
'displayInBackend' => true,
'label' => 'Postcode.eu Housenumber',
'readonly' => true,
'translatable' => true,
]
);
$service->update(
's_user_addresses_attributes',
'postcode_eu_housenumber_addition',
TypeMapping::TYPE_STRING,
[
'position' => 3,
'displayInBackend' => true,
'label' => 'Postcode.eu Housenumber Addition',
'readonly' => true,
'translatable' => true,
]
);
$service->update(
's_user_addresses_attributes',
'postcode_eu_zipcode',
TypeMapping::TYPE_STRING,
[
'position' => 4,
'displayInBackend' => true,
'label' => 'Postcode.eu Zipcode',
'readonly' => true,
'translatable' => true,
]
);
$service->update(
's_user_addresses_attributes',
'postcode_eu_city',
TypeMapping::TYPE_STRING,
[
'position' => 5,
'displayInBackend' => true,
'label' => 'Postcode.eu City',
'readonly' => true,
'translatable' => true,
]
);
$service->update(
's_user_addresses_attributes',
'postcode_eu_autocomplete_address',
TypeMapping::TYPE_STRING,
[
'position' => 10,
'displayInBackend' => true,
'label' => 'Postcode.eu Autocomplete address',
'supportText' => "As returned by the Postcode.eu Autocomplete API",
'readonly' => true,
'translatable' => true,
]
);
Shopware()->Models()->generateAttributeModels(['s_user_addresses_attributes']);
}
private function removeAddressAttributes()
{
$service = $this->container->get('shopware_attribute.crud_service');
$service->delete('s_user_addresses_attributes', 'postcode_eu_streetname');
$service->delete('s_user_addresses_attributes', 'postcode_eu_housenumber');
$service->delete('s_user_addresses_attributes', 'postcode_eu_housenumber_addition');
$service->delete('s_user_addresses_attributes', 'postcode_eu_zipcode');
$service->delete('s_user_addresses_attributes', 'postcode_eu_city');
$service->delete('s_user_addresses_attributes', 'postcode_eu_autocomplete_address');
Shopware()->Models()->generateAttributeModels(['s_user_addresses_attributes']);
}
}