1
0
mirror of synced 2024-11-24 22:16:13 +03:00

Merge pull request #16 from iyzoer/master

v2.3.1
This commit is contained in:
Alex Lushpai 2018-10-25 13:09:48 +03:00 committed by GitHub
commit 5b6a9762d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 322 additions and 4 deletions

View File

@ -1,3 +1,6 @@
## 2018-10-25 v.2.3.1
* Добавлена активация модуля в маркетплейсе retailCRM
## 2018-08-21 v.2.3.0 ## 2018-08-21 v.2.3.0
* Добавлены консольные команды для выгрузки архива клиентов и заказов * Добавлены консольные команды для выгрузки архива клиентов и заказов
* Обработка данных для формирования структуры перед отправкой вынесена в сервисы * Обработка данных для формирования структуры перед отправкой вынесена в сервисы

View File

@ -1 +1 @@
2.3.0 2.3.1

View File

@ -7,6 +7,8 @@ use Retailcrm\Retailcrm\Helper\Proxy as ApiClient;
class ApiVersion extends \Magento\Framework\App\Config\Value class ApiVersion extends \Magento\Framework\App\Config\Value
{ {
private $api; private $api;
private $request;
private $integrationModule;
/** /**
* ApiVersion constructor. * ApiVersion constructor.
@ -16,6 +18,8 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @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 \Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule
* @param ApiClient $api * @param ApiClient $api
* @param array $data * @param array $data
*/ */
@ -24,12 +28,17 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
\Magento\Framework\Registry $registry, \Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
ApiClient $api,
\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,
\Retailcrm\Retailcrm\Model\Service\IntegrationModule $integrationModule,
ApiClient $api,
array $data = [] array $data = []
) { ) {
$this->api = $api; $this->api = $api;
$this->request = $request;
$this->integrationModule = $integrationModule;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); 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 (isset($availableVersions)) {
if (in_array($apiVersions[$apiVersion], $availableVersions)) { if (in_array($apiVersions[$apiVersion], $availableVersions)) {
$this->setValue($this->getValue()); $this->setValue($this->getValue());
$this->sendModuleConfiguration($api);
} else { } else {
throw new \Magento\Framework\Exception\ValidatorException( throw new \Magento\Framework\Exception\ValidatorException(
__('The selected API version is unavailable') __('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 * @param array $data
*/ */

View 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
View 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);
}
}

View 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
]
];
}
}

View File

@ -5,7 +5,7 @@
"retailcrm/api-client-php": "~5.0" "retailcrm/api-client-php": "~5.0"
}, },
"type": "magento2-module", "type": "magento2-module",
"version": "2.3.0", "version": "2.3.1",
"license": [ "license": [
"OSL-3.0", "OSL-3.0",
"AFL-3.0" "AFL-3.0"
@ -13,7 +13,7 @@
"authors": [ "authors": [
{ {
"name": "RetailDriver LLC", "name": "RetailDriver LLC",
"email": "gorokh@retailcrm.ru", "email": "integration@retailcrm.ru",
"homepage": "https://www.retailcrm.ru", "homepage": "https://www.retailcrm.ru",
"role": "Developer" "role": "Developer"
} }