From 0deb6acb03a8e06cc9872110766a76651f4b4bb0 Mon Sep 17 00:00:00 2001 From: Raj Chevli Date: Mon, 2 Mar 2020 12:45:54 +0000 Subject: [PATCH 1/3] Initial Sequence Component --- Component/Sequence.php | 133 ++++++++++++++++++++++ Samples/Components/Sequence/sequence.yaml | 3 + Samples/master.yaml | 5 + etc/di.xml | 1 + 4 files changed, 142 insertions(+) create mode 100644 Component/Sequence.php create mode 100644 Samples/Components/Sequence/sequence.yaml diff --git a/Component/Sequence.php b/Component/Sequence.php new file mode 100644 index 0000000..5d7ed9d --- /dev/null +++ b/Component/Sequence.php @@ -0,0 +1,133 @@ +sequenceBuilder = $sequenceBuilder; + $this->entityPool = $entityPool; + $this->sequenceConfig = $sequenceConfig; + $this->storeRepository = $repository; + $this->logger = $logger; + } + + public function execute($data) + { + if (!isset($data['stores'])) { + throw new ComponentException("No stores found."); + } + + foreach ($data['stores'] as $code => $overrides) { + try { + $this->logger->logInfo(__("Starting creating sequence tables for %1", $code)); + $store = $this->storeRepository->get($code); + $this->newSequenceTable($store, $overrides); + $this->logger->logInfo(__("Finished creating sequence tables for %1", $code)); + // todo handle existing sequence tables + } catch (\Exception $exception) { + $this->logger->logError($exception->getMessage()); + } + } + } + + public function getAlias() + { + return $this->alias; + } + + public function getDescription() + { + return $this->description; + } + + protected function newSequenceTable($store, $overrides) + { + $configKeys = ['suffix', 'startValue', 'step', 'warningValue', 'maxValue', 'prefix']; + $configValues = []; + foreach ($configKeys as $key) { + if ($key != 'prefix') { + $configValues[$key] = $this->sequenceConfig->get($key); + } else { + $configValues[$key] = $store->getId(); + } + if (isset($overrides[$key])) { + $configValues[$key] = $overrides[$key]; + } + } + + foreach ($this->entityPool->getEntities() as $entityType) { + try { + $this->logger->logComment(__( + 'Store: %1 '. + 'Prefix: %2, '. + 'Suffix: %3, '. + 'Start Value: %4, '. + 'Step: %5, '. + 'Warning Value: %6, '. + 'Max Value: %7, '. + 'Entity Type: %8', + $store->getCode(), + $configValues['prefix'], + $configValues['suffix'], + $configValues['startValue'], + $configValues['step'], + $configValues['warningValue'], + $configValues['maxValue'], + $entityType + ), 1); + $this->sequenceBuilder->setPrefix($configValues['prefix']) + ->setSuffix($configValues['suffix']) + ->setStartValue($configValues['startValue']) + ->setStoreId($store->getId()) + ->setStep($configValues['step']) + ->setWarningValue($configValues['warningValue']) + ->setMaxValue($configValues['maxValue']) + ->setEntityType($entityType) + ->create(); + $this->logger->logInfo(__("Sequence table created for %1", $entityType), 1); + } catch (\Exception $exception) { + $this->logger->logError($exception->getMessage()); + } + } + } +} diff --git a/Samples/Components/Sequence/sequence.yaml b/Samples/Components/Sequence/sequence.yaml new file mode 100644 index 0000000..ade9a04 --- /dev/null +++ b/Samples/Components/Sequence/sequence.yaml @@ -0,0 +1,3 @@ +stores: + base: + prefix: PREFIX_ \ No newline at end of file diff --git a/Samples/master.yaml b/Samples/master.yaml index a6d890e..dd6d280 100644 --- a/Samples/master.yaml +++ b/Samples/master.yaml @@ -18,6 +18,11 @@ config: sources: - ../configurator/Configuration/global.yaml - ../configurator/Configuration/base-website-config.yaml +sequence: + enabled: 1 + method: code + sources: + - ../configurator/Sequence/sequence.yaml attributes: enabled: 1 method: code diff --git a/etc/di.xml b/etc/di.xml index d7857ce..403bb43 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -24,6 +24,7 @@ CtiDigital\Configurator\Component\Websites CtiDigital\Configurator\Component\Config + CtiDigital\Configurator\Component\Sequence CtiDigital\Configurator\Component\Attributes CtiDigital\Configurator\Component\AttributeSets CtiDigital\Configurator\Component\AdminRoles From 1e846ab4467c91c2c0b903dbc3e67f17a5e2684f Mon Sep 17 00:00:00 2001 From: Raj Chevli Date: Mon, 2 Mar 2020 12:55:29 +0000 Subject: [PATCH 2/3] Resolve unnecessary else statement and prepare new version number --- Component/Sequence.php | 14 ++++++++------ composer.json | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Component/Sequence.php b/Component/Sequence.php index 5d7ed9d..6fc1b4c 100644 --- a/Component/Sequence.php +++ b/Component/Sequence.php @@ -82,19 +82,21 @@ public function getDescription() protected function newSequenceTable($store, $overrides) { - $configKeys = ['suffix', 'startValue', 'step', 'warningValue', 'maxValue', 'prefix']; + $configKeys = ['suffix', 'startValue', 'step', 'warningValue', 'maxValue']; $configValues = []; foreach ($configKeys as $key) { - if ($key != 'prefix') { - $configValues[$key] = $this->sequenceConfig->get($key); - } else { - $configValues[$key] = $store->getId(); - } + $configValues[$key] = $this->sequenceConfig->get($key); if (isset($overrides[$key])) { $configValues[$key] = $overrides[$key]; } } + // Prefix Value + $configValues['prefix'] = $store->getId(); + if (isset($overrides['prefix'])) { + $configValues['prefix'] = $overrides['prefix']; + } + foreach ($this->entityPool->getEntities() as $entityType) { try { $this->logger->logComment(__( diff --git a/composer.json b/composer.json index 27d63f5..073d851 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "phpunit/phpunit": "^6.2", "magento/magento-coding-standard": "5" }, - "version": "3.0.0", + "version": "3.1.0", "autoload": { "files": [ "registration.php" ], "psr-4": { From fd589f05992c0fe87e629cc61ebc0edc7e345745 Mon Sep 17 00:00:00 2001 From: Raj Chevli Date: Mon, 2 Mar 2020 13:21:36 +0000 Subject: [PATCH 3/3] Update sample data with usable data for tests --- Samples/Components/Sequence/sequence.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Samples/Components/Sequence/sequence.yaml b/Samples/Components/Sequence/sequence.yaml index ade9a04..9e562e0 100644 --- a/Samples/Components/Sequence/sequence.yaml +++ b/Samples/Components/Sequence/sequence.yaml @@ -1,3 +1,7 @@ stores: - base: - prefix: PREFIX_ \ No newline at end of file + default: + prefix: PREFIX_ + startValue: 5000 + usa_en_us: + prefix: USA_ + startValue: 1000 \ No newline at end of file