Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
paulpartington-cti committed May 5, 2020
2 parents 813e898 + 926c789 commit 0399492
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 2 deletions.
135 changes: 135 additions & 0 deletions Component/Sequence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

namespace CtiDigital\Configurator\Component;

use CtiDigital\Configurator\Api\ComponentInterface;
use CtiDigital\Configurator\Exception\ComponentException;
use Magento\SalesSequence\Model\Builder;
use Magento\SalesSequence\Model\EntityPool;
use Magento\SalesSequence\Model\Config;
use Magento\Store\Api\StoreRepositoryInterface;
use CtiDigital\Configurator\Api\LoggerInterface;

class Sequence implements ComponentInterface
{
/**
* @var Builder
*/
protected $sequenceBuilder;

/**
* @var EntityPool
*/
protected $entityPool;

/**
* @var Config
*/
protected $sequenceConfig;

/**
* @var StoreRepositoryInterface
*/
protected $storeRepository;

protected $logger;

protected $alias = 'sequence';
protected $description = 'Component to allow manual configuring of the sequence tables.';

public function __construct(
Builder $sequenceBuilder,
EntityPool $entityPool,
Config $sequenceConfig,
StoreRepositoryInterface $repository,
LoggerInterface $logger
) {
$this->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'];
$configValues = [];
foreach ($configKeys as $key) {
$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(__(
'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());
}
}
}
}
7 changes: 7 additions & 0 deletions Samples/Components/Sequence/sequence.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
stores:
default:
prefix: PREFIX_
startValue: 5000
usa_en_us:
prefix: USA_
startValue: 1000
5 changes: 5 additions & 0 deletions Samples/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
],
"require": {
"symfony/yaml": "~4.0|~5.0",
"symfony/console": "~4.1.0",
"firegento/fastsimpleimport": "1.3.1"
},
"require-dev": {
Expand All @@ -21,7 +20,7 @@
"phpunit/phpunit": "^6.2",
"magento/magento-coding-standard": "5"
},
"version": "3.0.1",
"version": "3.1.1",
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<argument name="components" xsi:type="array">
<item name="websites" xsi:type="object">CtiDigital\Configurator\Component\Websites</item>
<item name="config" xsi:type="object">CtiDigital\Configurator\Component\Config</item>
<item name="sequence" xsi:type="object">CtiDigital\Configurator\Component\Sequence</item>
<item name="attributes" xsi:type="object">CtiDigital\Configurator\Component\Attributes</item>
<item name="attribute_sets" xsi:type="object">CtiDigital\Configurator\Component\AttributeSets</item>
<item name="adminroles" xsi:type="object">CtiDigital\Configurator\Component\AdminRoles</item>
Expand Down

0 comments on commit 0399492

Please sign in to comment.