diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee628e..174740a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2018-12-06 v3.3.6 +* Исправлена активация модуля в маркетплейсе retailCRM при использовании api v4 +* Расширена отправляемая конфигурация + ## 2018-10-25 v3.3.5 * Добавлена активация модуля в маркетплейсе retailCRM diff --git a/VERSION b/VERSION index 0163af7..eedb52b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.5 \ No newline at end of file +3.3.6 \ No newline at end of file diff --git a/src/include/class-wc-retailcrm-plugin.php b/src/include/class-wc-retailcrm-plugin.php index f000ed0..089effe 100644 --- a/src/include/class-wc-retailcrm-plugin.php +++ b/src/include/class-wc-retailcrm-plugin.php @@ -90,21 +90,31 @@ class WC_Retailcrm_Plugin { * * @return boolean */ - public static function integration_module($api_client, $client_id, $active = true) { + public static function integration_module($api_client, $client_id, $api_version, $active = true) { + if (!$api_client) { return false; } $configuration = array( - 'clientId' => $client_id, - 'code' => self::INTEGRATION_CODE . '-' . $client_id, - 'integrationCode' => self::INTEGRATION_CODE, - 'active' => $active, 'name' => 'WooCommerce', - 'logo' => self::MARKETPLACE_LOGO + 'logo' => self::MARKETPLACE_LOGO, + 'code' => self::INTEGRATION_CODE . '-' . $client_id, + 'active' => $active, ); - $response = $api_client->integrationModulesEdit($configuration); + if ($api_version == 'v4') { + $configuration['configurationUrl'] = get_site_url(); + + $response = $api_client->marketplaceSettingsEdit($configuration); + } else { + $configuration['integrationCode'] = self::INTEGRATION_CODE; + $configuration['baseUrl'] = get_site_url(); + $configuration['clientId'] = $client_id; + $configuration['accountUrl'] = get_site_url(); + + $response = $api_client->integrationModulesEdit($configuration); + } if (!$response) { return false; diff --git a/src/readme.txt b/src/readme.txt index 3a4806e..839f438 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина 2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании). == Changelog == += 3.3.6 = +* Исправлена активация модуля в маркетплейсе retailCRM при использовании api v4 + = 3.3.5 = * Добавлена активация модуля в маркетплейсе retailCRM diff --git a/src/retailcrm.php b/src/retailcrm.php index 5441f82..abd7a77 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -1,6 +1,6 @@ responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper') + ->disableOriginalConstructor() + ->setMethods(array( + 'isSuccessful' + )) + ->getMock(); + + $this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy') + ->disableOriginalConstructor() + ->setMethods(array( + 'marketplaceSettingsEdit' + )) + ->getMock(); + + parent::setUp(); + } + + /** + * @param $retailcrm + * @param $response + * @param $apiVersion + * + * @dataProvider dataProviderIntegrationModule + */ + public function test_integration_module($retailcrm,$response, $apiVersion) + { + $client_id = uniqid(); + $result = WC_Retailcrm_Plugin::integration_module($retailcrm, $client_id, $apiVersion); + + if (!$retailcrm || $response['success'] == false) { + $this->assertEquals(false, $result); + } else { + $this->assertEquals(true, $result); + } + } + + private function getResponseData() + { + return array( + 'v4' => array( + "true" => array( + "success" => true + ), + "false" => array( + "success" => false + ) + ), + 'v5' => array( + "true" => array( + "success" => true + ), + "false" => array( + "success" => false, + "errorMsg" => "Forbidden" + ) + ) + ); + } + + public function dataProviderIntegrationModule() + { + $this->setUp(); + + return array( + array( + 'retailcrm' => $this->getApiMock( + 'v4', + $this->getResponseData['v4']['true'] + ), + 'response' => $this->getResponseData['v4']['true'], + 'apiVersion' => 'v4' + ), + array( + 'retailcrm' => false, + 'response' => $this->getResponseData['v4']['true'], + 'apiVersion' => 'v4' + ), + array( + 'retailcrm' => $this->getApiMock( + 'v4', + $this->getResponseData['v4']['false'] + ), + 'response' => $this->getResponseData['v4']['false'], + 'apiVersion' => 'v4' + ), + array( + 'retailcrm' => false, + 'response' => $this->getResponseData['v4']['false'], + 'apiVersion' => 'v4' + ), + array( + 'retailcrm' => $this->getApiMock( + 'v5', + $this->getResponseData['v5']['true'] + ), + 'response' => $this->getResponseData['v5']['true'], + 'apiVersion' => 'v5' + ), + array( + 'retailcrm' => false, + 'response' => $this->getResponseData['v5']['true'], + 'apiVersion' => 'v5' + ), + array( + 'retailcrm' => $this->getApiMock( + 'v5', + $this->getResponseData['v5']['false'] + ), + 'response' => $this->getResponseData['v5']['false'], + 'apiVersion' => 'v5' + ), + array( + 'retailcrm' => false, + 'response' => $this->getResponseData['v5']['false'], + 'apiVersion' => 'v5' + ) + ); + } + + private function getApiMock($apiVersion, $response) + { + $responseMock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper') + ->disableOriginalConstructor() + ->setMethods(array( + 'isSuccessful' + )) + ->getMock(); + + if ($response['success'] == true) { + $responseMock->expects($this->any()) + ->method('isSuccessful') + ->willReturn(true); + } elseif ($response['success'] == false) { + $responseMock->expects($this->any()) + ->method('isSuccessful') + ->willReturn(false); + } + + $responseMock->setResponse($response); + + if ($apiVersion == 'v4') { + $apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy') + ->disableOriginalConstructor() + ->setMethods(array( + 'marketplaceSettingsEdit' + )) + ->getMock(); + + $apiMock->expects($this->any()) + ->method('marketplaceSettingsEdit') + ->willReturn($responseMock); + } else { + $apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy') + ->disableOriginalConstructor() + ->setMethods(array( + 'integrationModulesEdit' + )) + ->getMock(); + + $apiMock->expects($this->any()) + ->method('integrationModulesEdit') + ->willReturn($responseMock); + } + + return $apiMock; + } +} +