Added settings field
This commit is contained in:
parent
747456f6f5
commit
92a0e575d4
@ -182,4 +182,15 @@ class Configuration
|
|||||||
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\DeliveryDataField>")
|
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\DeliveryDataField>")
|
||||||
*/
|
*/
|
||||||
public $shipmentDataFieldList;
|
public $shipmentDataFieldList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Массив настроек модуля
|
||||||
|
*
|
||||||
|
* @var Settings
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("settings")
|
||||||
|
* @Serializer\Type("RetailCrm\DeliveryModuleBundle\Model\Settings")
|
||||||
|
*/
|
||||||
|
public $settings;
|
||||||
}
|
}
|
||||||
|
96
Model/Settings.php
Normal file
96
Model/Settings.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\DeliveryModuleBundle\Model;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
use RetailCrm\DeliveryModuleBundle\Model\Settings\ExtraData;
|
||||||
|
use RetailCrm\DeliveryModuleBundle\Model\Settings\PaymentType;
|
||||||
|
use RetailCrm\DeliveryModuleBundle\Model\Settings\ShipmentPoint;
|
||||||
|
use RetailCrm\DeliveryModuleBundle\Model\Settings\Status;
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
public const COST_CALCULATE_BY_MODULE = 'auto';
|
||||||
|
public const COST_CALCULATE_BY_SYSTEM = 'manual';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("defaultPayerType")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $defaultPayerType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("costCalculateBy")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $costCalculateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("nullDeclaredValue")
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
|
*/
|
||||||
|
public $nullDeclaredValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("lockedByDefault")
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
|
*/
|
||||||
|
public $lockedByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|PaymentType[]
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("paymentTypes")
|
||||||
|
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\Settings\PaymentType>")
|
||||||
|
*/
|
||||||
|
public $paymentTypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|ShipmentPoint[]
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("shipmentPoints")
|
||||||
|
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\Settings\ShipmentPoint>")
|
||||||
|
*/
|
||||||
|
public $shipmentPoints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|Status[]
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("statuses")
|
||||||
|
* @Serializer\Type("array<RetailCrm\DeliveryModuleBundle\Model\Settings\Status>")
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
35
Model/Settings/PaymentType.php
Normal file
35
Model/Settings/PaymentType.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\DeliveryModuleBundle\Model\Settings;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
class PaymentType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("code")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("active")
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
|
*/
|
||||||
|
public $active = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("cod")
|
||||||
|
* @Serializer\Type("boolean")
|
||||||
|
*/
|
||||||
|
public $cod = false;
|
||||||
|
}
|
35
Model/Settings/ShipmentPoint.php
Normal file
35
Model/Settings/ShipmentPoint.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\DeliveryModuleBundle\Model\Settings;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
class ShipmentPoint
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("code")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("shipmentPointId")
|
||||||
|
* @Serializer\Type("integer")
|
||||||
|
*/
|
||||||
|
public $shipmentPointId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("shipmentPointLabel")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $shipmentPointLabel;
|
||||||
|
}
|
26
Model/Settings/Status.php
Normal file
26
Model/Settings/Status.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RetailCrm\DeliveryModuleBundle\Model\Settings;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
class Status
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("code")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var mixed
|
||||||
|
*
|
||||||
|
* @Serializer\Groups({"set", "get"})
|
||||||
|
* @Serializer\SerializedName("trackingStatusCode")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
*/
|
||||||
|
public $trackingStatusCode;
|
||||||
|
}
|
@ -1,53 +1,3 @@
|
|||||||
retailcrm_delivery_module_connect:
|
|
||||||
path: /{_locale}/connect
|
|
||||||
defaults: { _controller: :Admin:connect }
|
|
||||||
requirements:
|
|
||||||
_locale: en|ru
|
|
||||||
|
|
||||||
retailcrm_delivery_module_connect_edit:
|
|
||||||
path: /{_locale}/connect/{clientId}/edit
|
|
||||||
defaults: { _controller: :Admin:connect }
|
|
||||||
requirements:
|
|
||||||
_locale: en|ru
|
|
||||||
|
|
||||||
############
|
|
||||||
# Admin
|
|
||||||
############
|
|
||||||
retailcrm_delivery_module_admin_list:
|
|
||||||
path: /omega
|
|
||||||
defaults: { _controller: :Admin:list }
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_new:
|
|
||||||
path: /omega/new
|
|
||||||
defaults: { _controller: :Admin:new }
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_edit:
|
|
||||||
path: /omega/{connectionId}/edit
|
|
||||||
defaults: { _controller: :Admin:edit }
|
|
||||||
requirements:
|
|
||||||
connectionId: \d+
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_update_configuration:
|
|
||||||
path: /omega/{connectionId}/update-configuration
|
|
||||||
defaults: { _controller: :Admin:updateConfiguration }
|
|
||||||
requirements:
|
|
||||||
connectionId: \d+
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_parcel_list:
|
|
||||||
path: /omega/parcels
|
|
||||||
defaults: { _controller: :Admin:parcelList }
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_parcel_new:
|
|
||||||
path: /omega/parcels/new
|
|
||||||
defaults: { _controller: :Admin:parcelNew }
|
|
||||||
|
|
||||||
retailcrm_delivery_module_admin_parcel_edit:
|
|
||||||
path: /omega/parcels/{parcelId}/edit
|
|
||||||
defaults: { _controller: :Admin:parcelEdit }
|
|
||||||
requirements:
|
|
||||||
parcelId: \d+
|
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# API
|
# API
|
||||||
############
|
############
|
||||||
|
@ -127,7 +127,7 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
$this->translator->setLocale($this->account->getLanguage());
|
$this->translator->setLocale($this->account->getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->retailCrmClient = $this->retailCrmClientFactory->createRetailCrmClient($this->account, $this->logger);
|
$this->retailCrmClient = $this->retailCrmClientFactory->createRetailCrmClient($this->account);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -140,7 +140,11 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
|
|
||||||
$integrationModule = $this->buildIntegrationModule();
|
$integrationModule = $this->buildIntegrationModule();
|
||||||
$integrationModule = $this->jmsSerializer
|
$integrationModule = $this->jmsSerializer
|
||||||
->serialize($integrationModule, 'json', SerializationContext::create()->setGroups(['get', 'request']));
|
->serialize(
|
||||||
|
$integrationModule,
|
||||||
|
'json',
|
||||||
|
SerializationContext::create()->setGroups(['get', 'request'])->setSerializeNull(true)
|
||||||
|
);
|
||||||
|
|
||||||
$client = $this->retailCrmClient;
|
$client = $this->retailCrmClient;
|
||||||
$response = $this->pinbaService->timerHandler(
|
$response = $this->pinbaService->timerHandler(
|
||||||
@ -158,6 +162,11 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
if ($response['success'] ?? false) {
|
if ($response['success'] ?? false) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
if ($this->logger) {
|
||||||
|
$errorMsg = $response['error_msg'] ?? '';
|
||||||
|
$this->logger->warning("Failed to update module configuration[account={$this->getAccount()->getCrmUrl()}]:{$errorMsg}");
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +180,7 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
$integrationModule->active = $this->account->isActive();
|
$integrationModule->active = $this->account->isActive();
|
||||||
$integrationModule->name = $this->moduleParameters['locales'][$this->translator->getLocale()]['name'];
|
$integrationModule->name = $this->moduleParameters['locales'][$this->translator->getLocale()]['name'];
|
||||||
$integrationModule->logo = $this->moduleParameters['locales'][$this->translator->getLocale()]['logo'];
|
$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->availableCountries = $this->moduleParameters['countries'];
|
||||||
$integrationModule->actions = [
|
$integrationModule->actions = [
|
||||||
'activity' => 'activity',
|
'activity' => 'activity',
|
||||||
@ -182,11 +191,7 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
[],
|
[],
|
||||||
UrlGeneratorInterface::ABSOLUTE_URL
|
UrlGeneratorInterface::ABSOLUTE_URL
|
||||||
);
|
);
|
||||||
$integrationModule->accountUrl = $this->router->generate(
|
$integrationModule->accountUrl = $this->getAccountUrl();
|
||||||
'retailcrm_delivery_module_connect',
|
|
||||||
['_locale' => $this->account->getLanguage()],
|
|
||||||
UrlGeneratorInterface::ABSOLUTE_URL
|
|
||||||
);
|
|
||||||
|
|
||||||
$integrationModule->integrations = ['delivery' => $this->doBuildConfiguration()];
|
$integrationModule->integrations = ['delivery' => $this->doBuildConfiguration()];
|
||||||
|
|
||||||
@ -195,6 +200,8 @@ abstract class ModuleManager implements ModuleManagerInterface
|
|||||||
|
|
||||||
abstract protected function doBuildConfiguration(): Configuration;
|
abstract protected function doBuildConfiguration(): Configuration;
|
||||||
|
|
||||||
|
abstract protected function getAccountUrl(): string;
|
||||||
|
|
||||||
public function calculateDelivery(RequestCalculate $data): array
|
public function calculateDelivery(RequestCalculate $data): array
|
||||||
{
|
{
|
||||||
throw new \LogicException('Method should be implemented');
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user