-
Notifications
You must be signed in to change notification settings - Fork 39
/
SwagBackendOrder.php
52 lines (44 loc) · 1.83 KB
/
SwagBackendOrder.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
<?php
declare(strict_types=1);
/**
* (c) shopware AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace SwagBackendOrder;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class SwagBackendOrder extends Plugin
{
public function build(ContainerBuilder $container): void
{
$container->setParameter('swag_backend_orders.plugin_dir', $this->getPath());
parent::build($container);
}
/**
* {@inheritdoc}
*/
public function install(InstallContext $context): void
{
/*
* The following code sets the initial value of the sendMail configuration in the plugin to the core config value of "sendOrderMail".
* If the plugin has been configured already, it will not overwrite the existing value.
*/
$pluginConfig = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName($this->getName());
$sendMailConfigGlobal = (bool) $this->container->get('config')->get('sendOrderMail');
/*
* If there is a plugin configuration already, or the core value equals false anyway, it's not required to set
* the initial config value again. Therefore it returns before executing the next part.
*/
if (!$sendMailConfigGlobal || isset($pluginConfig['sendMail'])) {
return;
}
$pluginManager = $this->container->get('shopware_plugininstaller.plugin_manager');
$plugin = $pluginManager->getPluginByName($this->getName());
// Finally set the plugin config value to the core config value.
$pluginManager->saveConfigElement($plugin, 'sendMail', $sendMailConfigGlobal);
}
}