1
0
Fork 0
mirror of synced 2025-04-06 07:13:33 +03:00

option to enable or disable corporate customers support

This commit is contained in:
Pavel 2019-12-04 11:26:36 +03:00 committed by Павел
parent 3ca90cca50
commit c4fe1eae72
10 changed files with 56 additions and 51 deletions

View file

@ -222,3 +222,9 @@ msgstr "Transferencia de un número de pedido"
msgid "Transferring the payment amount"
msgstr "Transferencia de un monto de pago"
msgid "Corporate customers support"
msgstr "Soporte a clientes corporativos"
msgid "Enabled"
msgstr "Habilitado"

View file

@ -231,3 +231,9 @@ msgstr "Передача номера заказа"
msgid "Transferring the payment amount"
msgstr "Передача суммы оплаты"
msgid "Corporate customers support"
msgstr "Поддержка корпоративных клиентов"
msgid "Enabled"
msgstr "Включено"

View file

@ -150,7 +150,16 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
'description' => '',
'class' => 'checkbox',
'type' => 'checkbox',
'desc_tip' => true,
'desc_tip' => true
);
$this->form_fields['corporate_enabled'] = array(
'title' => __('Corporate customers support', 'retailcrm'),
'label' => __('Enabled'),
'description' => '',
'class' => 'checkbox',
'type' => 'checkbox',
'desc_tip' => true
);
$this->form_fields[] = array(
@ -582,7 +591,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$api = new WC_Retailcrm_Proxy(
$post[$this->plugin_id . $this->id . '_api_url'],
$post[$this->plugin_id . $this->id . '_api_key']
$post[$this->plugin_id . $this->id . '_api_key'],
null,
$this->get_option('corporate_enabled', 'no') === 'yes'
);
$response = $api->apiVersions();
@ -610,7 +621,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$post = $this->get_post_data();
$api = new WC_Retailcrm_Proxy(
$value,
$post[$this->plugin_id . $this->id . '_api_key']
$post[$this->plugin_id . $this->id . '_api_key'],
null,
$this->get_option('corporate_enabled', 'no') === 'yes'
);
$response = $api->apiVersions();
@ -636,7 +649,9 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
$post = $this->get_post_data();
$api = new WC_Retailcrm_Proxy(
$post[$this->plugin_id . $this->id . '_api_url'],
$value
$value,
null,
$this->get_option('corporate_enabled', 'no') === 'yes'
);
$response = $api->apiVersions();

View file

@ -15,11 +15,13 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
class WC_Retailcrm_Proxy
{
protected $retailcrm;
protected $corporateEnabled;
protected $logger;
public function __construct($api_url, $api_key, $api_vers = null)
public function __construct($api_url, $api_key, $api_vers = null, $corporateEnabled = false)
{
$this->logger = new WC_Logger();
$this->corporateEnabled = $corporateEnabled;
if ( ! class_exists( 'WC_Retailcrm_Client_V4' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-client-v4.php' );
@ -42,6 +44,16 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
}
}
/**
* getCorporateEnabled
*
* @return bool
*/
public function getCorporateEnabled()
{
return $this->corporateEnabled;
}
public function __call($method, $arguments)
{
try {

View file

@ -359,7 +359,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
return new WC_Retailcrm_Proxy(
$this->get_option('api_url'),
$this->get_option('api_key'),
$this->get_option('api_version')
$this->get_option('api_version'),
$this->get_option('corporate_enabled', 'no') === 'yes'
);
}
@ -398,7 +399,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
$api_client = new WC_Retailcrm_Proxy(
$settings['api_url'],
$settings['api_key'],
$settings['api_version']
$settings['api_version'],
$settings['corporate_enabled'] === 'yes'
);
$result = WC_Retailcrm_Plugin::integration_module($api_client, $client_id, $settings['api_version']);

View file

@ -70,46 +70,6 @@ if (!class_exists('WC_Retailcrm_Customers')) :
return $this;
}
/**
* Returns true if corporate customers are enabled and accessible
*
* @param WC_Retailcrm_Client_V5|\WC_Retailcrm_Proxy $apiClient
*
* @return bool
*/
public static function isCorporateEnabledInApi($apiClient)
{
if (is_object($apiClient)) {
$requiredMethods = array(
"/api/customers-corporate",
"/api/customers-corporate/create",
"/api/customers-corporate/fix-external-ids",
"/api/customers-corporate/notes",
"/api/customers-corporate/notes/create",
"/api/customers-corporate/notes/{id}/delete",
"/api/customers-corporate/history",
"/api/customers-corporate/upload",
"/api/customers-corporate/{externalId}",
"/api/customers-corporate/{externalId}/edit"
);
$credentials = $apiClient->credentials();
if ($credentials && isset($credentials['credentials'])) {
$existingMethods = array_filter(
$credentials['credentials'],
function ($val) use ($requiredMethods) {
return in_array($val, $requiredMethods);
}
);
return count($requiredMethods) == count($existingMethods);
}
}
return false;
}
/**
* Is corporate customers enabled in provided API
*
@ -121,7 +81,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
return false;
}
return static::isCorporateEnabledInApi($this->retailcrm);
return $this->retailcrm->getCorporateEnabled();
}
/**

View file

@ -79,7 +79,11 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
}
$this->customersHistory($this->startDateCustomers->format('Y-m-d H:i:s'), $customers_since_id);
$this->customersCorporateHistory($this->startDateCustomersCorporate->format('Y-m-d H:i:s'), $customers_corporate_since_id);
if ($this->retailcrm->getCorporateEnabled()) {
$this->customersCorporateHistory($this->startDateCustomersCorporate->format('Y-m-d H:i:s'), $customers_corporate_since_id);
}
$this->ordersHistory($this->startDateOrders->format('Y-m-d H:i:s'), $orders_since_id);
}

View file

@ -72,7 +72,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
return null;
}
$isCorporateEnabled = WC_Retailcrm_Customers::isCorporateEnabledInApi($this->retailcrm);
$isCorporateEnabled = $this->retailcrm->getCorporateEnabled();
$uploader = new WC_Retailcrm_Customers(
$this->retailcrm,
$this->retailcrm_settings,
@ -212,7 +212,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
return null;
}
$isCorporateEnabled = $forceRegularCustomer ? false : WC_Retailcrm_Customers::isCorporateEnabledInApi($this->retailcrm);
$isCorporateEnabled = $forceRegularCustomer ? false : $this->retailcrm->getCorporateEnabled();
$wcOrder = wc_get_order($order_id);
$this->processOrder($wcOrder);
$wpUser = $wcOrder->get_user();

Binary file not shown.

Binary file not shown.