From 92a0e575d44e9ec66ec4e8786aa5d1507f215c9a Mon Sep 17 00:00:00 2001 From: 1on Date: Thu, 9 Apr 2020 14:47:34 +0300 Subject: [PATCH] Added settings field --- Model/Configuration.php | 11 ++++ Model/Settings.php | 96 ++++++++++++++++++++++++++++++++ Model/Settings/PaymentType.php | 35 ++++++++++++ Model/Settings/ShipmentPoint.php | 35 ++++++++++++ Model/Settings/Status.php | 26 +++++++++ Resources/config/routing.yaml | 50 ----------------- Service/ModuleManager.php | 47 +++++----------- 7 files changed, 218 insertions(+), 82 deletions(-) create mode 100644 Model/Settings.php create mode 100644 Model/Settings/PaymentType.php create mode 100644 Model/Settings/ShipmentPoint.php create mode 100644 Model/Settings/Status.php diff --git a/Model/Configuration.php b/Model/Configuration.php index 083b5c2..98ccaff 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -182,4 +182,15 @@ class Configuration * @Serializer\Type("array") */ public $shipmentDataFieldList; + + /** + * Массив настроек модуля + * + * @var Settings + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("settings") + * @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Settings") + */ + public $settings; } diff --git a/Model/Settings.php b/Model/Settings.php new file mode 100644 index 0000000..b97c484 --- /dev/null +++ b/Model/Settings.php @@ -0,0 +1,96 @@ +") + */ + public $paymentTypes; + + /** + * @var array|ShipmentPoint[] + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("shipmentPoints") + * @Serializer\Type("array") + */ + public $shipmentPoints; + + /** + * @var array|Status[] + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("statuses") + * @Serializer\Type("array") + */ + public $statuses; + + /** + * @var array|ExtraData[] + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("deliveryExtraData") + * @Serializer\Type("array") + */ + public $deliveryExtraData; + + /** + * @var array|ExtraData[] + * + * @Serializer\Groups({"set", "get"}) + * @Serializer\SerializedName("shipmentExtraData") + * @Serializer\Type("array") + */ + public $shipmentExtraData; +} diff --git a/Model/Settings/PaymentType.php b/Model/Settings/PaymentType.php new file mode 100644 index 0000000..3b2ff3f --- /dev/null +++ b/Model/Settings/PaymentType.php @@ -0,0 +1,35 @@ +translator->setLocale($this->account->getLanguage()); } - $this->retailCrmClient = $this->retailCrmClientFactory->createRetailCrmClient($this->account, $this->logger); + $this->retailCrmClient = $this->retailCrmClientFactory->createRetailCrmClient($this->account); return $this; } @@ -140,7 +140,11 @@ abstract class ModuleManager implements ModuleManagerInterface $integrationModule = $this->buildIntegrationModule(); $integrationModule = $this->jmsSerializer - ->serialize($integrationModule, 'json', SerializationContext::create()->setGroups(['get', 'request'])); + ->serialize( + $integrationModule, + 'json', + SerializationContext::create()->setGroups(['get', 'request'])->setSerializeNull(true) + ); $client = $this->retailCrmClient; $response = $this->pinbaService->timerHandler( @@ -158,6 +162,11 @@ abstract class ModuleManager implements ModuleManagerInterface if ($response['success'] ?? false) { return true; } else { + if ($this->logger) { + $errorMsg = $response['error_msg'] ?? ''; + $this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]:{$errorMsg}"); + } + return false; } } @@ -171,7 +180,7 @@ abstract class ModuleManager implements ModuleManagerInterface $integrationModule->active = $this->account->isActive(); $integrationModule->name = $this->moduleParameters['locales'][$this->translator->getLocale()]['name']; $integrationModule->logo = $this->moduleParameters['locales'][$this->translator->getLocale()]['logo']; - $integrationModule->clientId = $this->account->getId(); + $integrationModule->clientId = $this->account->getClientId(); $integrationModule->availableCountries = $this->moduleParameters['countries']; $integrationModule->actions = [ 'activity' => 'activity', @@ -182,11 +191,7 @@ abstract class ModuleManager implements ModuleManagerInterface [], UrlGeneratorInterface::ABSOLUTE_URL ); - $integrationModule->accountUrl = $this->router->generate( - 'retailcrm_delivery_module_connect', - ['_locale' => $this->account->getLanguage()], - UrlGeneratorInterface::ABSOLUTE_URL - ); + $integrationModule->accountUrl = $this->getAccountUrl(); $integrationModule->integrations = ['delivery' => $this->doBuildConfiguration()]; @@ -195,6 +200,8 @@ abstract class ModuleManager implements ModuleManagerInterface abstract protected function doBuildConfiguration(): Configuration; + abstract protected function getAccountUrl(): string; + public function calculateDelivery(RequestCalculate $data): array { throw new \LogicException('Method should be implemented'); @@ -351,28 +358,4 @@ abstract class ModuleManager implements ModuleManagerInterface ); } } - - private function createRetailCrmClient(): void - { - if (null === $this->account) { - throw new \LogicException('Account is not selected'); - } - - if (empty($this->account->getCrmUrl())) { - throw new \LogicException('Crm url is empty'); - } - - if (empty($this->account->getCrmApiKey())) { - throw new \LogicException('Crm apiKey is empty'); - } - - $this->retailCrmClient = new ApiClient( - $this->account->getCrmUrl(), - $this->account->getCrmApiKey(), - ApiClient::V5 - ); - if ($this->logger) { - $this->retailCrmClient->setLogger($this->logger); - } - } }