Added activate/deactivate in marketplace methods
This commit is contained in:
parent
88363fa962
commit
7c6e55c60a
@ -53,7 +53,7 @@ class WC_Retailcrm_Client_V5
|
||||
|
||||
/**
|
||||
* Returns api versions list
|
||||
*
|
||||
*
|
||||
* @return WC_Retailcrm_Response
|
||||
*/
|
||||
public function apiVersions()
|
||||
@ -2292,6 +2292,34 @@ class WC_Retailcrm_Client_V5
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit module configuration
|
||||
*
|
||||
* @param array $configuration
|
||||
*
|
||||
* @throws WC_Retailcrm_Exception_Json
|
||||
* @throws WC_Retailcrm_Exception_Curl
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return WC_Retailcrm_Response
|
||||
*/
|
||||
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",
|
||||
WC_Retailcrm_Request::METHOD_POST,
|
||||
array('integrationModule' => json_encode($configuration))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update CRM basic statistic
|
||||
*
|
||||
|
@ -66,6 +66,9 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
add_action('woocommerce_update_order', array($this, 'update_order'), 11, 1);
|
||||
add_action('wp_print_scripts', array($this, 'initialize_analytics'), 98);
|
||||
add_action('wp_print_footer_scripts', array($this, 'send_analytics'), 99);
|
||||
|
||||
// Deactivate hook
|
||||
add_action('retailcrm_deactivate', array($this, 'deactivate'));
|
||||
}
|
||||
|
||||
public function api_sanitized($settings)
|
||||
@ -94,6 +97,10 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
wp_clear_scheduled_hook('retailcrm_icml');
|
||||
}
|
||||
|
||||
if (!$this->get_errors() && !get_option('retailcrm_active_in_crm')) {
|
||||
$this->activate_integration($settings);
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
@ -794,9 +801,9 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
WC_Admin_Settings::add_error( esc_html__( 'The selected API version is unavailable', 'retailcrm' ) );
|
||||
$value = '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -897,6 +904,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add button in admin
|
||||
*/
|
||||
@ -931,5 +939,31 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function deactivate()
|
||||
{
|
||||
$api_client = $this->getApiClient();
|
||||
$clientId = get_option('retailcrm_client_id');
|
||||
WC_Retailcrm_Plugin::integration_module($api_client, $clientId, false);
|
||||
}
|
||||
|
||||
private function activate_integration($settings)
|
||||
{
|
||||
$clientId = get_option('retailcrm_client_id');
|
||||
|
||||
if ($settings['api_url'] && $settings['api_key'] && $settings['api_version']) {
|
||||
$api_client = new WC_Retailcrm_Proxy(
|
||||
$settings['api_url'],
|
||||
$settings['api_key'],
|
||||
$settings['api_version']
|
||||
);
|
||||
|
||||
$result = WC_Retailcrm_Plugin::integration_module($api_client);
|
||||
|
||||
if ($result) {
|
||||
update_option('retailcrm_active_in_crm', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ class WC_Retailcrm_Plugin {
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
do_action('retailcrm_deactivate');
|
||||
|
||||
if (wp_next_scheduled('retailcrm_icml')) {
|
||||
wp_clear_scheduled_hook('retailcrm_icml');
|
||||
}
|
||||
@ -75,6 +77,48 @@ class WC_Retailcrm_Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit configuration in CRM
|
||||
*
|
||||
* @param WC_Retailcrm_Proxy $api_client
|
||||
* @param string $cliendId
|
||||
* @param bool $active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function integration_module($api_client, $cliendId, $active = true)
|
||||
{
|
||||
if (!$api_client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$configuration = array(
|
||||
'clientId' => $cliendId,
|
||||
'code' => 'woocommerce',
|
||||
'integrationCode' => 'woocommerce',
|
||||
'active' => $active,
|
||||
'name' => 'WooCommerce',
|
||||
'logo' => 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b69ce4bda663-woocommercesvg2.svg'
|
||||
);
|
||||
|
||||
$response = $api_client->integrationModulesEdit($configuration);
|
||||
|
||||
if (!$response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check running history
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function history_running()
|
||||
{
|
||||
return self::$history_run;
|
||||
|
Loading…
x
Reference in New Issue
Block a user