-
Notifications
You must be signed in to change notification settings - Fork 2
/
SwagProductDiscount.php
executable file
·72 lines (61 loc) · 2.18 KB
/
SwagProductDiscount.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
<?php declare(strict_types=1);
namespace SwagProductDiscount;
use Doctrine\DBAL\Connection;
use Shopware\Framework\Plugin\Context\InstallContext;
use Shopware\Framework\Plugin\Context\UninstallContext;
use Shopware\Framework\Plugin\Plugin;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class SwagProductDiscount extends Plugin
{
public function __construct($active = true)
{
parent::__construct($active);
}
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/DependencyInjection/'));
$loader->load('api.xml');
$loader->load('services.xml');
}
public function install(InstallContext $context)
{
/** @var Connection $dbal */
$dbal = $this->container->get('dbal_connection');
$sql = <<<SQL
CREATE TABLE `swag_product_discount` (
`uuid` varchar(42) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
`product_uuid` VARCHAR(42) NOT NULL UNIQUE,
`discount_percentage` DOUBLE NOT NULL DEFAULT 0,
PRIMARY KEY `uuid` (`uuid`),
FOREIGN KEY (`product_uuid`) REFERENCES product (`uuid`)
);
CREATE TABLE `swag_product_discount_translation` (
`swag_product_discount_uuid` varchar(42) COLLATE 'utf8mb4_unicode_ci' NOT NULL,
`language_uuid` varchar(42) NOT NULL,
`name` varchar(200) NOT NULL,
PRIMARY KEY `swag_product_discount_uuid_language_uuid` (`swag_product_discount_uuid`, `language_uuid`),
FOREIGN KEY (`swag_product_discount_uuid`) REFERENCES `swag_product_discount` (`uuid`),
FOREIGN KEY (`language_uuid`) REFERENCES `shop` (`uuid`)
);
SQL;
$dbal->exec($sql);
parent::install($context);
}
public function uninstall(UninstallContext $context)
{
/** @var Connection $dbal */
$dbal = $this->container->get('dbal_connection');
$sql = <<<SQL
DROP TABLE swag_product_discount_translation;
DROP TABLE swag_product_discount;
SQL;
$dbal->exec($sql);
parent::uninstall($context);
}
}