1
0
mirror of synced 2024-11-22 04:56:07 +03:00

Добавлена возможность создания нескольких модулей в маркетплейсе

This commit is contained in:
Akolzin Dmitry 2018-10-25 12:35:03 +03:00
parent f47af54f1a
commit 15da35916a
3 changed files with 33 additions and 23 deletions

View File

@ -8,7 +8,6 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
{ {
private $api; private $api;
private $request; private $request;
private $helper;
private $integrationModule; private $integrationModule;
/** /**
@ -20,7 +19,6 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param \Magento\Framework\App\Request\Http $request * @param \Magento\Framework\App\Request\Http $request
* @param \Retailcrm\Retailcrm\Helper\Data $helper
* @param \Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule * @param \Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule
* @param ApiClient $api * @param ApiClient $api
* @param array $data * @param array $data
@ -33,14 +31,12 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
\Magento\Framework\App\Request\Http $request, \Magento\Framework\App\Request\Http $request,
\Retailcrm\Retailcrm\Helper\Data $helper,
\Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule, \Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule,
ApiClient $api, ApiClient $api,
array $data = [] array $data = []
) { ) {
$this->api = $api; $this->api = $api;
$this->request = $request; $this->request = $request;
$this->helper = $helper;
$this->integrationModule = $integrationModule; $this->integrationModule = $integrationModule;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
@ -107,14 +103,10 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
*/ */
private function sendModuleConfiguration($api) private function sendModuleConfiguration($api)
{ {
$clientId = $this->helper->getGeneralSettings('client_id_in_crm');
if (!$clientId) {
$this->integrationModule->setApiVersion($api->getVersion()); $this->integrationModule->setApiVersion($api->getVersion());
$this->integrationModule->setAccountUrl($this->request->getUriString()); $this->integrationModule->setAccountUrl($this->request->getUriString());
$this->integrationModule->sendConfiguration($api); $this->integrationModule->sendConfiguration($api);
} }
}
/** /**
* @param array $data * @param array $data

View File

@ -7,18 +7,28 @@ use Retailcrm\Retailcrm\Helper\Data as Helper;
class IntegrationModule class IntegrationModule
{ {
const LOGO = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b846b1fef57e-magento.svg'; const LOGO = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b846b1fef57e-magento.svg';
const CODE = 'magento'; const INTEGRATION_CODE = 'magento';
const NAME = 'Magento 2'; const NAME = 'Magento 2';
private $accountUrl = null; private $accountUrl = null;
private $resourceConfig;
private $apiVersion = 'v5'; private $apiVersion = 'v5';
private $configuration = []; private $configuration = [];
private $resourceConfig;
private $clientId;
private $helper;
/**
* IntegrationModule constructor.
*
* @param \Magento\Config\Model\ResourceModel\Config $resourceConfig
* @param \Retailcrm\Retailcrm\Helper\Data $helper
*/
public function __construct( public function __construct(
\Magento\Config\Model\ResourceModel\Config $resourceConfig \Magento\Config\Model\ResourceModel\Config $resourceConfig,
Helper $helper
) { ) {
$this->resourceConfig = $resourceConfig; $this->resourceConfig = $resourceConfig;
$this->helper = $helper;
} }
/** /**
@ -52,21 +62,25 @@ class IntegrationModule
*/ */
private function setConfiguration($active) private function setConfiguration($active)
{ {
$this->clientId = $this->helper->getGeneralSettings('client_id_in_crm');
if (!$this->clientId) {
$this->clientId = uniqid();
}
if ($this->apiVersion == 'v4') { if ($this->apiVersion == 'v4') {
$this->configuration = [ $this->configuration = [
'name' => self::NAME, 'name' => self::NAME,
'code' => self::CODE, 'code' => self::INTEGRATION_CODE . '-' . $this->clientId,
'logo' => self::LOGO, 'logo' => self::LOGO,
'configurationUrl' => $this->accountUrl, 'configurationUrl' => $this->accountUrl,
'active' => $active 'active' => $active
]; ];
} else { } else {
$clientId = hash('md5', date('Y-m-d H:i:s'));
$this->configuration = [ $this->configuration = [
'clientId' => $clientId, 'clientId' => $this->clientId,
'code' => self::CODE, 'code' => self::INTEGRATION_CODE . '-' . $this->clientId,
'integrationCode' => self::CODE, 'integrationCode' => self::INTEGRATION_CODE,
'active' => $active, 'active' => $active,
'name' => self::NAME, 'name' => self::NAME,
'logo' => self::LOGO, 'logo' => self::LOGO,
@ -95,8 +109,11 @@ class IntegrationModule
return false; return false;
} }
if ($response->isSuccessful() && isset($clientId)) { if ($response->isSuccessful() && $active == true) {
$this->resourceConfig->saveConfig(Helper::XML_PATH_RETAILCRM . 'general/client_id_in_crm', $clientId); $this->resourceConfig->saveConfig(
Helper::XML_PATH_RETAILCRM . 'general/client_id_in_crm',
$this->clientId
);
return true; return true;
} }

View File

@ -20,6 +20,7 @@ class Uninstall implements \Magento\Framework\Setup\UninstallInterface
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context) public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
{ {
$this->integrationModule->sendConfiguration($this->apiClient, $this->apiClient->getVersion(), false); $this->integrationModule->setApiVersion($this->apiClient->getVersion());
$this->integrationModule->sendConfiguration($this->apiClient, false);
} }
} }