first commit
This commit is contained in:
108
bundles/External/FlexiBeeBundle/Util/FlexiBeeConfiguration.php
vendored
Normal file
108
bundles/External/FlexiBeeBundle/Util/FlexiBeeConfiguration.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace External\FlexiBeeBundle\Util;
|
||||
|
||||
use External\FlexiBeeBundle\Exception\FlexiBeeException;
|
||||
use KupShop\SynchronizationBundle\Util\SynchronizationConfiguration;
|
||||
|
||||
class FlexiBeeConfiguration
|
||||
{
|
||||
private SynchronizationConfiguration $configuration;
|
||||
|
||||
public function __construct(SynchronizationConfiguration $configuration)
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci pro API potřebnou pro připojení (url, user, password, company).
|
||||
*/
|
||||
public function getAPIConfig(): array
|
||||
{
|
||||
$api = $this->getConfig()['api'] ?? [];
|
||||
|
||||
foreach (['company', 'url', 'user', 'password'] as $requiredField) {
|
||||
if (empty($api[$requiredField])) {
|
||||
throw new FlexiBeeException(
|
||||
sprintf('Missing required value in API config: %s', $requiredField)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci objednávek.
|
||||
*/
|
||||
public function getOrderConfig(): array
|
||||
{
|
||||
return $this->getConfig()['config']['order'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci doprav.
|
||||
*/
|
||||
public function getDeliveriesConfig(): array
|
||||
{
|
||||
return $this->getConfig()['config']['delivery'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci plateb.
|
||||
*/
|
||||
public function getPaymentsConfig(): array
|
||||
{
|
||||
return $this->getConfig()['config']['payment'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci stavů objednávek.
|
||||
*/
|
||||
public function getOrderStatusesConfig(): array
|
||||
{
|
||||
return $this->getOrderConfig()['statuses'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací povolené typy synchronizací, které se mají spouštět.
|
||||
*/
|
||||
public function getEnabledSynchronizerTypes(): array
|
||||
{
|
||||
return $this->getConfig()['config']['enabled_types'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací ID skladů ve FlexiBee, které máme synchronizovat.
|
||||
*/
|
||||
public function getEnabledStoreIds(): array
|
||||
{
|
||||
return array_map(fn ($x) => (int) $x, $this->getConfig()['config']['stores'] ?? [0]);
|
||||
}
|
||||
|
||||
public function getEnabledPricelists(): array
|
||||
{
|
||||
return array_map(fn ($x) => (int) $x, $this->getConfig()['config']['pricelists'] ?? [-1]);
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->configuration->clear('flexibee');
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrací konfiguraci z settings tabulky.
|
||||
*/
|
||||
private function getConfig(): array
|
||||
{
|
||||
$dbcfg = \Settings::getDefault();
|
||||
|
||||
if (!$this->configuration->has('flexibee')) {
|
||||
$this->configuration->set('flexibee', fn () => $dbcfg->loadValue('flexibee') ?: []);
|
||||
}
|
||||
|
||||
return $this->configuration->get('flexibee');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user