ref #90088 Types of deliveries and payments are displayed only active status and available stores

This commit is contained in:
Ivan Chaplygin 2023-06-02 13:55:00 +03:00
parent 090a5783c5
commit 3e1c19fd8d
3 changed files with 49 additions and 6 deletions

View File

@ -334,13 +334,17 @@ class ControllerExtensionModuleRetailcrm extends Controller
: null;
if (!empty($url) && !empty($key)) {
$_data['delivery'] = $this->model_extension_retailcrm_references
->getDeliveryTypes();
$sites = $this->model_extension_retailcrm_references->getApiSites();
$_data['delivery'] = $this->getAvailableTypes(
$sites,
$this->model_extension_retailcrm_references->getDeliveryTypes()
);
$_data['payments'] = $this->getAvailableTypes(
$sites,
$this->model_extension_retailcrm_references->getPaymentTypes()
);
$_data['statuses'] = $this->model_extension_retailcrm_references
->getOrderStatuses();
$_data['payments'] = $this->model_extension_retailcrm_references
->getPaymentTypes();
$_data['customFields'] = $this->model_extension_retailcrm_references
->getCustomFields();
@ -942,4 +946,29 @@ class ControllerExtensionModuleRetailcrm extends Controller
return $lastSinceId;
}
private function getAvailableTypes($availableSites, $types)
{
if (!empty($availableSites)) {
$availableSite = end($availableSites)['code'];
} else {
return $types;
}
$result = [];
foreach ($types as $type) {
if (
$type['active'] === true &&
(
empty($type['sites']) ||
in_array($availableSite, $type['sites'], true)
)
) {
$result[] = $type;
}
}
return $result;
}
}

View File

@ -158,6 +158,20 @@ class ModelExtensionRetailcrmReferences extends Model
return (!$response->isSuccessful()) ? array() : $response->deliveryTypes;
}
/**
* Get RetailCRM available sites list
*/
public function getApiSites()
{
$response = $this->retailcrmApiClient->sitesList();
if (!$response) {
return array();
}
return (!$response->isSuccessful()) ? array() : $response->sites;
}
/**
* Get RetailCRM order statuses
*

View File

@ -87,7 +87,7 @@ class OpencartApiClient {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=api/' . $method . (!empty($getParams) ? '&' . http_build_query($getParams) : ''));
curl_setopt($curl, CURLOPT_URL, 'https://chaplygin-is.proxy.retailcrm.tech/' . 'index.php?route=api/' . $method . (!empty($getParams) ? '&' . http_build_query($getParams) : ''));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postParams));