-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSwagShippingRestriction.php
82 lines (69 loc) · 2.88 KB
/
SwagShippingRestriction.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
<?php
namespace SwagShippingRestriction;
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 Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Class SwagShippingRestriction
* @package SwagShippingRestriction
*/
class SwagShippingRestriction extends Plugin
{
/**
* @param InstallContext $context
* @throws \Exception
*/
public function install(InstallContext $context)
{
$this->container->get('shopware_attribute.crud_service')->update('s_core_countries_attributes', 'swag_allow_shipping', 'boolean', [
'displayInBackend' => true,
'translatable' => true,
'label' => 'Allow as Shipping Country'
]);
$this->container->get('models')->generateAttributeModels(['s_core_countries_attributes']);
// Fix default value
$this->container->get('dbal_connection')->executeQuery('ALTER TABLE `s_core_countries_attributes` CHANGE `swag_allow_shipping` `swag_allow_shipping` int(1) NULL DEFAULT \'1\' AFTER `countryID`;');
$this->container->get('dbal_connection')->executeQuery('UPDATE `s_core_countries_attributes` SET swag_allow_shipping = 1 WHERE swag_allow_shipping IS NULL');
try {
$this->container->get('dbal_connection')->executeQuery('INSERT INTO s_core_countries_attributes (countryId) (SELECT s_core_countries.id FROM s_core_countries LEFT JOIN s_core_countries_attributes ON s_core_countries_attributes.countryId = s_core_countries.id WHERE s_core_countries_attributes.id IS NULL)');
} catch (\Exception $e) {}
$context->scheduleClearCache(UninstallContext::CACHE_LIST_ALL);
}
/**
* @param UninstallContext $context
* @throws \Exception
*/
public function uninstall(UninstallContext $context)
{
if ($context->keepUserData()) {
return;
}
$this->container->get('shopware_attribute.crud_service')->delete('s_core_countries_attributes', 'swag_allow_shipping');
$this->container->get('models')->generateAttributeModels(['s_core_countries_attributes']);
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context)
{
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context)
{
$context->scheduleClearCache(UninstallContext::CACHE_LIST_ALL);
}
/**
* @param ContainerBuilder $container
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->setParameter('swag_shipping_restriction.plugin_dir', $this->getPath());
}
}