|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Koality\ShopwarePlugin; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Plugin\Context\InstallContext; |
|
6
|
|
|
use Shopware\Core\System\SystemConfig\SystemConfigService; |
|
7
|
|
|
use Symfony\Component\Config\Exception\LoaderLoadException; |
|
8
|
|
|
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
|
9
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
|
10
|
|
|
use Shopware\Core\Framework\Plugin; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class KoalityShopwarePlugin |
|
14
|
|
|
* |
|
15
|
|
|
* @package Koality\ShopwarePlugin |
|
16
|
|
|
* |
|
17
|
|
|
* @author Nils Langner <[email protected]> |
|
18
|
|
|
* created 2020-12-28 |
|
19
|
|
|
*/ |
|
20
|
|
|
class KoalityShopwarePlugin extends Plugin |
|
21
|
|
|
{ |
|
22
|
|
|
const VERSION = '1.0'; |
|
23
|
|
|
|
|
24
|
|
|
const CONFIG_KEY_API_KEY = 'apiKey'; |
|
25
|
|
|
|
|
26
|
|
|
const PLUGIN_NAME = 'KoalityShopwarePlugin'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param RouteCollectionBuilder $routes |
|
30
|
|
|
* @param string $environment |
|
31
|
|
|
* |
|
32
|
|
|
* @throws LoaderLoadException |
|
33
|
|
|
*/ |
|
34
|
|
|
// public function configureRoutes(RouteCollectionBuilder $routes, string $environment): void |
|
35
|
|
|
public function configureRoutes(RoutingConfigurator $routes, string $environment): void |
|
36
|
|
|
{ |
|
37
|
|
|
$routes->import(__DIR__ . '/Resources/routes.xml'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritDoc |
|
42
|
|
|
*/ |
|
43
|
|
|
public function install(InstallContext $installContext): void |
|
44
|
|
|
{ |
|
45
|
|
|
parent::install($installContext); |
|
46
|
|
|
|
|
47
|
|
|
$configService = $this->container->get(SystemConfigService::class); |
|
48
|
|
|
$fullKey = self::PLUGIN_NAME . '.config.' . self::CONFIG_KEY_API_KEY; |
|
49
|
|
|
$configService->set($fullKey, $this->createGuid()); |
|
50
|
|
|
$configService->savePluginConfiguration($this, true); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Create an UUID for the plugins access. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
private function createGuid() |
|
59
|
|
|
{ |
|
60
|
|
|
if (function_exists('com_create_guid') === true) { |
|
61
|
|
|
return trim(com_create_guid(), '{}'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|