commit
5b6a9762d8
@ -1,3 +1,6 @@
|
||||
## 2018-10-25 v.2.3.1
|
||||
* Добавлена активация модуля в маркетплейсе retailCRM
|
||||
|
||||
## 2018-08-21 v.2.3.0
|
||||
* Добавлены консольные команды для выгрузки архива клиентов и заказов
|
||||
* Обработка данных для формирования структуры перед отправкой вынесена в сервисы
|
||||
|
@ -7,6 +7,8 @@ use Retailcrm\Retailcrm\Helper\Proxy as ApiClient;
|
||||
class ApiVersion extends \Magento\Framework\App\Config\Value
|
||||
{
|
||||
private $api;
|
||||
private $request;
|
||||
private $integrationModule;
|
||||
|
||||
/**
|
||||
* ApiVersion constructor.
|
||||
@ -16,6 +18,8 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
|
||||
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
|
||||
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
|
||||
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
|
||||
* @param \Magento\Framework\App\Request\Http $request
|
||||
* @param \Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule
|
||||
* @param ApiClient $api
|
||||
* @param array $data
|
||||
*/
|
||||
@ -24,12 +28,17 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface $config,
|
||||
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
|
||||
ApiClient $api,
|
||||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
|
||||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
|
||||
\Magento\Framework\App\Request\Http $request,
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule,
|
||||
ApiClient $api,
|
||||
array $data = []
|
||||
) {
|
||||
$this->api = $api;
|
||||
$this->request = $request;
|
||||
$this->integrationModule = $integrationModule;
|
||||
|
||||
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
|
||||
}
|
||||
|
||||
@ -79,6 +88,8 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
|
||||
if (isset($availableVersions)) {
|
||||
if (in_array($apiVersions[$apiVersion], $availableVersions)) {
|
||||
$this->setValue($this->getValue());
|
||||
|
||||
$this->sendModuleConfiguration($api);
|
||||
} else {
|
||||
throw new \Magento\Framework\Exception\ValidatorException(
|
||||
__('The selected API version is unavailable')
|
||||
@ -87,6 +98,16 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $api
|
||||
*/
|
||||
private function sendModuleConfiguration($api)
|
||||
{
|
||||
$this->integrationModule->setApiVersion($api->getVersion());
|
||||
$this->integrationModule->setAccountUrl($this->request->getUriString());
|
||||
$this->integrationModule->sendConfiguration($api);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
|
123
src/Model/Service/IntegrationModule.php
Normal file
123
src/Model/Service/IntegrationModule.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Model\Service;
|
||||
|
||||
use Retailcrm\Retailcrm\Helper\Data as Helper;
|
||||
|
||||
class IntegrationModule
|
||||
{
|
||||
const LOGO = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b846b1fef57e-magento.svg';
|
||||
const INTEGRATION_CODE = 'magento';
|
||||
const NAME = 'Magento 2';
|
||||
|
||||
private $accountUrl = null;
|
||||
private $apiVersion = 'v5';
|
||||
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(
|
||||
\Magento\Config\Model\ResourceModel\Config $resourceConfig,
|
||||
Helper $helper
|
||||
) {
|
||||
$this->resourceConfig = $resourceConfig;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $accountUrl
|
||||
*/
|
||||
public function setAccountUrl($accountUrl)
|
||||
{
|
||||
$this->accountUrl = $accountUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiVersion
|
||||
*/
|
||||
public function setApiVersion($apiVersion)
|
||||
{
|
||||
$this->apiVersion = $apiVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $active
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setConfiguration($active)
|
||||
{
|
||||
$this->clientId = $this->helper->getGeneralSettings('client_id_in_crm');
|
||||
|
||||
if (!$this->clientId) {
|
||||
$this->clientId = uniqid();
|
||||
}
|
||||
|
||||
if ($this->apiVersion == 'v4') {
|
||||
$this->configuration = [
|
||||
'name' => self::NAME,
|
||||
'code' => self::INTEGRATION_CODE . '-' . $this->clientId,
|
||||
'logo' => self::LOGO,
|
||||
'configurationUrl' => $this->accountUrl,
|
||||
'active' => $active
|
||||
];
|
||||
} else {
|
||||
$this->configuration = [
|
||||
'clientId' => $this->clientId,
|
||||
'code' => self::INTEGRATION_CODE . '-' . $this->clientId,
|
||||
'integrationCode' => self::INTEGRATION_CODE,
|
||||
'active' => $active,
|
||||
'name' => self::NAME,
|
||||
'logo' => self::LOGO,
|
||||
'accountUrl' => $this->accountUrl
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Retailcrm\Retailcrm\Helper\Proxy $apiClient
|
||||
* @param boolean $active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function sendConfiguration($apiClient, $active = true)
|
||||
{
|
||||
$this->setConfiguration($active);
|
||||
|
||||
if ($this->apiVersion == 'v4') {
|
||||
$response = $apiClient->marketplaceSettingsEdit(Helper::filterRecursive($this->configuration));
|
||||
} else {
|
||||
$response = $apiClient->integrationModulesEdit(Helper::filterRecursive($this->configuration));
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->isSuccessful() && $active == true) {
|
||||
$this->resourceConfig->saveConfig(
|
||||
Helper::XML_PATH_RETAILCRM . 'general/client_id_in_crm',
|
||||
$this->clientId
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
26
src/Setup/Uninstall.php
Normal file
26
src/Setup/Uninstall.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Setup;
|
||||
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
|
||||
class Uninstall implements \Magento\Framework\Setup\UninstallInterface
|
||||
{
|
||||
private $apiClient;
|
||||
private $integrationModule;
|
||||
|
||||
public function __construct(
|
||||
\Retailcrm\Retailcrm\Helper\Proxy $apiClient,
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule
|
||||
) {
|
||||
$this->apiClient = $apiClient;
|
||||
$this->integrationModule = $integrationModule;
|
||||
}
|
||||
|
||||
public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)
|
||||
{
|
||||
$this->integrationModule->setApiVersion($this->apiClient->getVersion());
|
||||
$this->integrationModule->sendConfiguration($this->apiClient, false);
|
||||
}
|
||||
}
|
145
src/Test/Unit/Model/Service/IntegrationModuleTest.php
Normal file
145
src/Test/Unit/Model/Service/IntegrationModuleTest.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
|
||||
|
||||
class IntegrationModuleTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $mockResourceConfig;
|
||||
private $mockApiClient;
|
||||
private $mockData;
|
||||
private $unit;
|
||||
|
||||
const ACCOUNT_URL = 'test';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockData = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Data::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockResourceConfig = $this->getMockBuilder(\Magento\Config\Model\ResourceModel\Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockApiClient = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([
|
||||
'marketplaceSettingsEdit',
|
||||
'integrationModulesEdit'
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$this->unit = new \Retailcrm\Retailcrm\Model\Service\IntegrationModule(
|
||||
$this->mockResourceConfig,
|
||||
$this->mockData
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $active
|
||||
* @param $apiVersion
|
||||
* @param $isSuccessful
|
||||
*
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testSendConfiguration($active, $apiVersion, $isSuccessful)
|
||||
{
|
||||
$response = $this->getMockBuilder(\RetailCrm\Response\ApiResponse::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response->expects($this->any())->method('isSuccessful')->willReturn($isSuccessful);
|
||||
|
||||
if ($apiVersion == 'v4') {
|
||||
$this->mockApiClient->expects($this->any())->method('marketplaceSettingsEdit')
|
||||
->willReturn($response);
|
||||
} else {
|
||||
$this->mockApiClient->expects($this->any())->method('integrationModulesEdit')
|
||||
->willReturn($response);
|
||||
}
|
||||
|
||||
$this->unit->setAccountUrl(self::ACCOUNT_URL);
|
||||
$this->unit->setApiVersion($apiVersion);
|
||||
$this->unit->sendConfiguration($this->mockApiClient, $active);
|
||||
$configuration = $this->unit->getConfiguration();
|
||||
|
||||
$this->assertNotEmpty($configuration);
|
||||
$this->assertArrayHasKey('name', $configuration);
|
||||
$this->assertEquals(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::NAME,
|
||||
$configuration['name']
|
||||
);
|
||||
$this->assertArrayHasKey('logo', $configuration);
|
||||
$this->assertEquals(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::LOGO,
|
||||
$configuration['logo']
|
||||
);
|
||||
$this->assertArrayHasKey('code', $configuration);
|
||||
$this->assertContains(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE,
|
||||
$configuration['code']
|
||||
);
|
||||
$this->assertArrayHasKey('active', $configuration);
|
||||
$this->assertEquals($active, $configuration['active']);
|
||||
|
||||
if ($apiVersion == 'v4') {
|
||||
$this->assertArrayHasKey('configurationUrl', $configuration);
|
||||
$this->assertEquals(self::ACCOUNT_URL, $configuration['configurationUrl']);
|
||||
} else {
|
||||
$this->assertArrayHasKey('accountUrl', $configuration);
|
||||
$this->assertEquals(self::ACCOUNT_URL, $configuration['accountUrl']);
|
||||
$this->assertArrayHasKey('integrationCode', $configuration);
|
||||
$this->assertContains(
|
||||
\Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE,
|
||||
$configuration['integrationCode']
|
||||
);
|
||||
$this->assertArrayHasKey('clientId', $configuration);
|
||||
$this->assertNotEmpty($configuration['clientId']);
|
||||
}
|
||||
}
|
||||
|
||||
public function dataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'active' => true,
|
||||
'api_version' => 'v4',
|
||||
'is_successful' => true
|
||||
],
|
||||
[
|
||||
'active' => false,
|
||||
'api_version' => 'v4',
|
||||
'is_successful' => true
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'api_version' => 'v4',
|
||||
'is_successful' => false
|
||||
],
|
||||
[
|
||||
'active' => false,
|
||||
'api_version' => 'v4',
|
||||
'is_successful' => false
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'api_version' => 'v5',
|
||||
'is_successful' => true
|
||||
],
|
||||
[
|
||||
'active' => false,
|
||||
'api_version' => 'v5',
|
||||
'is_successful' => true
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'api_version' => 'v5',
|
||||
'is_successful' => false
|
||||
],
|
||||
[
|
||||
'active' => false,
|
||||
'api_version' => 'v5',
|
||||
'is_successful' => false
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
"retailcrm/api-client-php": "~5.0"
|
||||
},
|
||||
"type": "magento2-module",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"license": [
|
||||
"OSL-3.0",
|
||||
"AFL-3.0"
|
||||
@ -13,7 +13,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "RetailDriver LLC",
|
||||
"email": "gorokh@retailcrm.ru",
|
||||
"email": "integration@retailcrm.ru",
|
||||
"homepage": "https://www.retailcrm.ru",
|
||||
"role": "Developer"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user