mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 11:43:16 +03:00
Send module configuration in marketplace CRM
This commit is contained in:
parent
3767445f68
commit
12b133eaff
@ -1650,6 +1650,34 @@ class RetailcrmApiClientV4
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit marketplace configuration
|
||||||
|
*
|
||||||
|
* @param array $configuration
|
||||||
|
*
|
||||||
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||||
|
* @throws \RetailCrm\Exception\CurlException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function marketplaceSettingsEdit(array $configuration)
|
||||||
|
{
|
||||||
|
if (!count($configuration) || empty($configuration['code'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `configuration` must contains a data & configuration `code` must be set'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = $configuration['code'];
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/marketplace/external/setting/$code/edit",
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array('configuration' => json_encode($configuration))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current site
|
* Return current site
|
||||||
*
|
*
|
||||||
|
@ -178,7 +178,7 @@ class RetailcrmApiClientV5
|
|||||||
$parameters
|
$parameters
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create custom field
|
* Create custom field
|
||||||
*
|
*
|
||||||
@ -211,7 +211,7 @@ class RetailcrmApiClientV5
|
|||||||
array('customField' => json_encode($customField))
|
array('customField' => json_encode($customField))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit custom field
|
* Edit custom field
|
||||||
*
|
*
|
||||||
@ -718,7 +718,7 @@ class RetailcrmApiClientV5
|
|||||||
'Parameter `id` must be set'
|
'Parameter `id` must be set'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
sprintf('/orders/payments/%s/delete', $id),
|
sprintf('/orders/payments/%s/delete', $id),
|
||||||
RetailcrmHttpClient::METHOD_POST
|
RetailcrmHttpClient::METHOD_POST
|
||||||
@ -2292,6 +2292,34 @@ class RetailcrmApiClientV5
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit module configuration
|
||||||
|
*
|
||||||
|
* @param array $configuration
|
||||||
|
*
|
||||||
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||||
|
* @throws \RetailCrm\Exception\CurlException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function integrationModulesEdit(array $configuration)
|
||||||
|
{
|
||||||
|
if (!count($configuration) || empty($configuration['code'])) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Parameter `configuration` must contains a data & configuration `code` must be set'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = $configuration['code'];
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/integration-modules/$code/edit",
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array('integrationModule' => json_encode($configuration))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current site
|
* Return current site
|
||||||
*
|
*
|
||||||
|
@ -82,6 +82,16 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
{
|
{
|
||||||
|
$api = new RetailcrmProxy(
|
||||||
|
Configuration::get('RETAILCRM_ADDRESS'),
|
||||||
|
Configuration::get('RETAILCRM_API_TOKEN'),
|
||||||
|
_PS_ROOT_DIR_ . '/retailcrm.log',
|
||||||
|
Configuration::get('RETAILCRM_API_VERSION')
|
||||||
|
);
|
||||||
|
|
||||||
|
$clientId = Configuration::get('RETAILCRM_CLIENT_ID');
|
||||||
|
$this->integrationModule($api, $clientId, Configuration::get('RETAILCRM_API_VERSION'), false);
|
||||||
|
|
||||||
return parent::uninstall() &&
|
return parent::uninstall() &&
|
||||||
Configuration::deleteByName('RETAILCRM_ADDRESS') &&
|
Configuration::deleteByName('RETAILCRM_ADDRESS') &&
|
||||||
Configuration::deleteByName('RETAILCRM_API_TOKEN') &&
|
Configuration::deleteByName('RETAILCRM_API_TOKEN') &&
|
||||||
@ -110,14 +120,16 @@ class RetailCRM extends Module
|
|||||||
$deliveryDefault = json_encode(Tools::getValue('RETAILCRM_API_DELIVERY_DEFAULT'));
|
$deliveryDefault = json_encode(Tools::getValue('RETAILCRM_API_DELIVERY_DEFAULT'));
|
||||||
$paymentDefault = json_encode(Tools::getValue('RETAILCRM_API_PAYMENT_DEFAULT'));
|
$paymentDefault = json_encode(Tools::getValue('RETAILCRM_API_PAYMENT_DEFAULT'));
|
||||||
$statusExport = (string)(Tools::getValue('RETAILCRM_STATUS_EXPORT'));
|
$statusExport = (string)(Tools::getValue('RETAILCRM_STATUS_EXPORT'));
|
||||||
|
$clientId = Configuration::get('RETAILCRM_CLIENT_ID');
|
||||||
$settings = array(
|
$settings = array(
|
||||||
'address' => $address,
|
'address' => $address,
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'version' => $version
|
'version' => $version,
|
||||||
|
'clientId' => $clientId
|
||||||
);
|
);
|
||||||
|
|
||||||
$output .= $this->validateForm($settings, $output);
|
$output .= $this->validateForm($settings, $output);
|
||||||
|
|
||||||
if ($output === '') {
|
if ($output === '') {
|
||||||
Configuration::updateValue('RETAILCRM_ADDRESS', $address);
|
Configuration::updateValue('RETAILCRM_ADDRESS', $address);
|
||||||
Configuration::updateValue('RETAILCRM_API_TOKEN', $token);
|
Configuration::updateValue('RETAILCRM_API_TOKEN', $token);
|
||||||
@ -437,7 +449,7 @@ class RetailCRM extends Module
|
|||||||
if ($comment !== false) {
|
if ($comment !== false) {
|
||||||
$order['customerComment'] = $comment;
|
$order['customerComment'] = $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($comment);
|
unset($comment);
|
||||||
|
|
||||||
foreach ($orderdb->getProducts() as $item) {
|
foreach ($orderdb->getProducts() as $item) {
|
||||||
@ -612,7 +624,7 @@ class RetailCRM extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$order['customer']['externalId'] = $customer['externalId'];
|
$order['customer']['externalId'] = $customer['externalId'];
|
||||||
|
|
||||||
$this->api->ordersCreate($order);
|
$this->api->ordersCreate($order);
|
||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
@ -715,9 +727,19 @@ class RetailCRM extends Module
|
|||||||
_PS_ROOT_DIR_ . '/retailcrm.log',
|
_PS_ROOT_DIR_ . '/retailcrm.log',
|
||||||
$settings['version']
|
$settings['version']
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $api->deliveryTypesList();
|
$response = $api->deliveryTypesList();
|
||||||
|
|
||||||
if ($response !== false) {
|
if ($response !== false) {
|
||||||
|
if (!$settings['clientId']) {
|
||||||
|
$clientId = hash('md5', date('Y-m-d H:i:s'));
|
||||||
|
$result = $this->integrationModule($api, $clientId, $settings['version']);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
Configuration::updateValue('RETAILCRM_CLIENT_ID', $clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -736,4 +758,57 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activate/deactivate module in marketplace retailCRM
|
||||||
|
*
|
||||||
|
* @param \RetailcrmProxy $apiClient
|
||||||
|
* @param string $clientId
|
||||||
|
* @param string $apiVersion
|
||||||
|
* @param boolean $active
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function integrationModule($apiClient, $clientId, $apiVersion, $active = true)
|
||||||
|
{
|
||||||
|
$scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
|
||||||
|
$logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b845ce986911-prestashop2.svg';
|
||||||
|
$code = 'prestashop';
|
||||||
|
$name = 'PrestaShop';
|
||||||
|
$accountUrl = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
if ($apiVersion == 'v4') {
|
||||||
|
$configuration = array(
|
||||||
|
'name' => $name,
|
||||||
|
'code' => $code,
|
||||||
|
'logo' => $logo,
|
||||||
|
'configurationUrl' => $accountUrl,
|
||||||
|
'active' => $active
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $apiClient->marketplaceSettingsEdit($configuration);
|
||||||
|
} else {
|
||||||
|
$configuration = array(
|
||||||
|
'clientId' => $clientId,
|
||||||
|
'code' => $code,
|
||||||
|
'integrationCode' => $code,
|
||||||
|
'active' => $active,
|
||||||
|
'name' => $name,
|
||||||
|
'logo' => $logo,
|
||||||
|
'accountUrl' => $accountUrl
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $apiClient->integrationModulesEdit($configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$response) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response->isSuccessful()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user