2018-04-27 11:19:02 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* RetailCRM Integration.
|
|
|
|
*
|
|
|
|
* @package WC_Retailcrm_Base
|
|
|
|
* @category Integration
|
|
|
|
* @author RetailCRM
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!class_exists('WC_Retailcrm_Base')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class WC_Retailcrm_Base
|
|
|
|
*/
|
|
|
|
class WC_Retailcrm_Base extends WC_Integration {
|
|
|
|
|
|
|
|
public static $option_key;
|
|
|
|
|
|
|
|
protected $api_url;
|
|
|
|
protected $api_key;
|
|
|
|
|
|
|
|
private $apiClient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init and hook in the integration.
|
|
|
|
* @param $retailcrm (default = false)
|
|
|
|
*/
|
|
|
|
public function __construct($retailcrm = false) {
|
|
|
|
//global $woocommerce;
|
|
|
|
|
|
|
|
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) {
|
|
|
|
include_once( __DIR__ . '/api/class-wc-retailcrm-proxy.php' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->id = 'integration-retailcrm';
|
2018-08-15 17:01:29 +03:00
|
|
|
$this->method_title = __('retailCRM', 'retailcrm');
|
|
|
|
$this->method_description = __('Integration with retailCRM management system.', 'retailcrm');
|
2018-04-27 11:19:02 +03:00
|
|
|
|
|
|
|
if ($retailcrm === false) {
|
|
|
|
$this->apiClient = $this->getApiClient();
|
|
|
|
} else {
|
|
|
|
$this->apiClient = $retailcrm;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$option_key = $this->get_option_key();
|
|
|
|
// Load the settings.
|
|
|
|
$this->init_form_fields();
|
|
|
|
$this->init_settings();
|
|
|
|
|
|
|
|
// Actions.
|
|
|
|
add_action('woocommerce_update_options_integration_' . $this->id, array($this, 'process_admin_options'));
|
2018-08-22 15:54:47 +03:00
|
|
|
add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'api_sanitized'));
|
2018-08-30 14:52:48 +03:00
|
|
|
add_action('admin_bar_menu', array($this, 'add_retailcrm_button'), 100 );
|
2018-04-27 11:19:02 +03:00
|
|
|
add_action('woocommerce_checkout_order_processed', array($this, 'retailcrm_process_order'), 10, 1);
|
|
|
|
add_action('retailcrm_history', array($this, 'retailcrm_history_get'));
|
|
|
|
add_action('retailcrm_icml', array($this, 'generate_icml'));
|
|
|
|
add_action('retailcrm_inventories', array($this, 'load_stocks'));
|
|
|
|
add_action('wp_ajax_do_upload', array($this, 'upload_to_crm'));
|
|
|
|
add_action('wp_ajax_generate_icml', array($this, 'generate_icml'));
|
2018-05-28 12:56:19 +03:00
|
|
|
add_action('wp_ajax_order_upload', array($this, 'order_upload'));
|
2018-04-27 11:19:02 +03:00
|
|
|
add_action('admin_print_footer_scripts', array($this, 'ajax_upload'), 99);
|
|
|
|
add_action('admin_print_footer_scripts', array($this, 'ajax_generate_icml'), 99);
|
2018-05-28 12:56:19 +03:00
|
|
|
add_action('admin_print_footer_scripts', array($this, 'ajax_selected_order'), 99);
|
2018-04-27 11:19:02 +03:00
|
|
|
add_action('woocommerce_created_customer', array($this, 'create_customer'), 10, 1);
|
|
|
|
add_action('woocommerce_update_customer', array($this, 'update_customer'), 10, 1);
|
|
|
|
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);
|
2018-08-31 11:13:16 +03:00
|
|
|
|
|
|
|
// Deactivate hook
|
|
|
|
add_action('retailcrm_deactivate', array($this, 'deactivate'));
|
2018-04-27 11:19:02 +03:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:54:47 +03:00
|
|
|
public function api_sanitized($settings)
|
|
|
|
{
|
|
|
|
if (isset($settings['sync']) && $settings['sync'] == 'yes') {
|
|
|
|
if (!wp_next_scheduled('retailcrm_inventories')) {
|
|
|
|
wp_schedule_event(time(), 'fiveteen_minutes', 'retailcrm_inventories');
|
|
|
|
}
|
|
|
|
} elseif (isset($settings['sync']) && $settings['sync'] == 'no') {
|
|
|
|
wp_clear_scheduled_hook('retailcrm_inventories');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($settings['history']) && $settings['history'] == 'yes') {
|
|
|
|
if (!wp_next_scheduled('retailcrm_history')) {
|
|
|
|
wp_schedule_event(time(), 'five_minutes', 'retailcrm_history');
|
|
|
|
}
|
|
|
|
} elseif (isset($settings['history']) && $settings['history'] == 'no') {
|
|
|
|
wp_clear_scheduled_hook('retailcrm_history');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($settings['icml']) && $settings['icml'] == 'yes') {
|
|
|
|
if (!wp_next_scheduled('retailcrm_icml')) {
|
|
|
|
wp_schedule_event(time(), 'three_hours', 'retailcrm_icml');
|
|
|
|
}
|
|
|
|
} elseif (isset($settings['icml']) && $settings['icml'] == 'no') {
|
|
|
|
wp_clear_scheduled_hook('retailcrm_icml');
|
|
|
|
}
|
|
|
|
|
2018-08-31 11:13:16 +03:00
|
|
|
if (!$this->get_errors() && !get_option('retailcrm_active_in_crm')) {
|
|
|
|
$this->activate_integration($settings);
|
|
|
|
}
|
|
|
|
|
2018-08-22 15:54:47 +03:00
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
/**
|
|
|
|
* Check custom file
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function checkCustomFile($file) {
|
|
|
|
if (file_exists( WP_CONTENT_DIR . '/retailcrm-custom/class-wc-retailcrm-' . $file . '.php' )) {
|
|
|
|
return WP_CONTENT_DIR . '/retailcrm-custom/class-wc-retailcrm-' . $file . '.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'class-wc-retailcrm-' . $file . '.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generate_icml() {
|
|
|
|
if (!class_exists('WC_Retailcrm_Icml')) {
|
|
|
|
require_once (self::checkCustomFile('icml'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcrm_icml = new WC_Retailcrm_Icml();
|
|
|
|
$retailcrm_icml->generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get history
|
|
|
|
*/
|
|
|
|
public function retailcrm_history_get() {
|
|
|
|
if (!class_exists('WC_Retailcrm_History')) {
|
|
|
|
include_once(self::checkCustomFile('history'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcrm_history = new WC_Retailcrm_History($this->apiClient);
|
|
|
|
$retailcrm_history->getHistory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $order_id
|
|
|
|
*/
|
|
|
|
public function retailcrm_process_order($order_id) {
|
|
|
|
if (!class_exists('WC_Retailcrm_Orders')) {
|
|
|
|
include_once(self::checkCustomFile('orders'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcm_order = new WC_Retailcrm_Orders($this->apiClient);
|
|
|
|
$retailcm_order->orderCreate($order_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load stock from retailCRM
|
|
|
|
*/
|
|
|
|
public function load_stocks() {
|
|
|
|
if (!class_exists('WC_Retailcrm_Inventories')) {
|
|
|
|
include_once(self::checkCustomFile('inventories'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$inventories = new WC_Retailcrm_Inventories($this->apiClient);
|
|
|
|
$inventories->updateQuantity();
|
|
|
|
}
|
|
|
|
|
2018-05-28 12:56:19 +03:00
|
|
|
/**
|
|
|
|
* Upload selected orders
|
|
|
|
*/
|
|
|
|
public function order_upload() {
|
|
|
|
if (!class_exists('WC_Retailcrm_Orders')) {
|
|
|
|
include_once(self::checkCustomFile('orders'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids = false;
|
|
|
|
|
|
|
|
if (isset($_GET['order_ids_retailcrm'])) {
|
|
|
|
$ids = explode(',', $_GET['order_ids_retailcrm']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcm_order = new WC_Retailcrm_Orders($this->apiClient);
|
|
|
|
|
|
|
|
if ($ids) {
|
|
|
|
$retailcm_order->ordersUpload($ids, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
/**
|
|
|
|
* Upload archive customers and order to retailCRM
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function upload_to_crm()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists('WC_Retailcrm_Orders')) {
|
|
|
|
include_once(self::checkCustomFile('orders'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('WC_Retailcrm_Customers')) {
|
|
|
|
include_once(self::checkCustomFile('customers'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$options = array_filter(get_option(self::$option_key));
|
|
|
|
|
|
|
|
$retailcrm_customers = new WC_Retailcrm_Customers($this->apiClient);
|
|
|
|
$retailcrm_orders = new WC_Retailcrm_Orders($this->apiClient);
|
|
|
|
|
|
|
|
$retailcrm_customers->customersUpload();
|
|
|
|
$retailcrm_orders->ordersUpload();
|
|
|
|
|
|
|
|
$options['uploads'] = 'yes';
|
2018-05-28 12:56:19 +03:00
|
|
|
update_option(self::$option_key, $options);
|
2018-04-27 11:19:02 +03:00
|
|
|
}
|
|
|
|
|
2018-07-19 12:16:30 +03:00
|
|
|
public function ajax_upload()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$ajax_url = admin_url('admin-ajax.php');
|
|
|
|
?>
|
2018-05-28 12:56:19 +03:00
|
|
|
<script type="text/javascript">
|
2018-04-27 11:19:02 +03:00
|
|
|
jQuery('#uploads-retailcrm').bind('click', function() {
|
|
|
|
jQuery.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: '<?php echo $ajax_url; ?>?action=do_upload',
|
|
|
|
success: function (response) {
|
2018-08-15 17:01:29 +03:00
|
|
|
alert('<?php echo __('Customers and orders were uploaded', 'retailcrm'); ?>');
|
2018-04-27 11:19:02 +03:00
|
|
|
console.log('AJAX response : ',response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2018-07-19 12:16:30 +03:00
|
|
|
public function ajax_generate_icml()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$ajax_url = admin_url('admin-ajax.php');
|
|
|
|
?>
|
2018-05-28 12:56:19 +03:00
|
|
|
<script type="text/javascript">
|
2018-08-30 14:52:48 +03:00
|
|
|
jQuery('#icml-retailcrm, #wp-admin-bar-retailcrm_ajax_generate_icml').bind('click', function() {
|
2018-04-27 11:19:02 +03:00
|
|
|
jQuery.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: '<?php echo $ajax_url; ?>?action=generate_icml',
|
|
|
|
success: function (response) {
|
2018-08-15 17:01:29 +03:00
|
|
|
alert('<?php echo __('Catalog was generated', 'retailcrm'); ?>');
|
2018-04-27 11:19:02 +03:00
|
|
|
console.log('AJAX response : ', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2018-07-19 12:16:30 +03:00
|
|
|
public function ajax_selected_order()
|
|
|
|
{
|
2018-05-28 12:56:19 +03:00
|
|
|
$ajax_url = admin_url('admin-ajax.php');
|
|
|
|
$ids = $this->plugin_id . $this->id . '_single_order';
|
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
jQuery('#single_order_btn').bind('click', function() {
|
|
|
|
if (jQuery('#<?php echo $ids; ?>').val() == '') {
|
2018-08-15 17:01:29 +03:00
|
|
|
alert('<?php echo __('The field cannot be empty, enter the order ID', 'retailcrm'); ?>');
|
2018-05-28 12:56:19 +03:00
|
|
|
} else {
|
|
|
|
jQuery.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: '<?php echo $ajax_url; ?>?action=order_upload&order_ids_retailcrm=' + jQuery('#<?php echo $ids; ?>').val(),
|
|
|
|
success: function (response) {
|
2018-08-15 17:01:29 +03:00
|
|
|
alert('<?php echo __('Orders were uploaded', 'retailcrm'); ?>');
|
2018-05-28 12:56:19 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
/**
|
|
|
|
* Create customer in retailCRM
|
|
|
|
* @param int $customer_id
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function create_customer($customer_id)
|
|
|
|
{
|
|
|
|
if (WC_Retailcrm_Plugin::history_running() === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists( 'WC_Retailcrm_Customers')) {
|
|
|
|
include_once(self::checkCustomFile('customers'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcrm_customer = new WC_Retailcrm_Customers($this->apiClient);
|
|
|
|
$retailcrm_customer->createCustomer($customer_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit customer in retailCRM
|
|
|
|
* @param int $customer_id
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function update_customer($customer_id)
|
|
|
|
{
|
|
|
|
if (WC_Retailcrm_Plugin::history_running() === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists('WC_Retailcrm_Customers')) {
|
|
|
|
include_once(self::checkCustomFile('customers'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcrm_customer = new WC_Retailcrm_Customers($this->apiClient);
|
|
|
|
$retailcrm_customer->updateCustomer($customer_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit order in retailCRM
|
|
|
|
* @param int $order_id
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function update_order($order_id)
|
|
|
|
{
|
|
|
|
if (WC_Retailcrm_Plugin::history_running() === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists('WC_Retailcrm_Orders')) {
|
|
|
|
include_once(self::checkCustomFile('orders'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$retailcrm_order = new WC_Retailcrm_Orders($this->apiClient);
|
|
|
|
$retailcrm_order->updateOrder($order_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init google analytics code
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function initialize_analytics()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists('WC_Retailcrm_Google_Analytics')) {
|
|
|
|
include_once(self::checkCustomFile('ga'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->get_option('ua') && $this->get_option('ua_code')) {
|
|
|
|
$retailcrm_analytics = WC_Retailcrm_Google_Analytics::getInstance($this->settings);
|
|
|
|
echo $retailcrm_analytics->initialize_analytics();
|
|
|
|
} else {
|
|
|
|
echo '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Google analytics send code
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function send_analytics()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
if (!class_exists('WC_Retailcrm_Google_Analytics')) {
|
|
|
|
include_once(self::checkCustomFile('ga'));
|
|
|
|
}
|
|
|
|
|
2018-05-28 12:56:19 +03:00
|
|
|
if ($this->get_option('ua') && $this->get_option('ua_code') && is_checkout()) {
|
2018-04-27 11:19:02 +03:00
|
|
|
$retailcrm_analytics = WC_Retailcrm_Google_Analytics::getInstance($this->settings);
|
|
|
|
echo $retailcrm_analytics->send_analytics();
|
|
|
|
} else {
|
|
|
|
echo '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize integration settings form fields.
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function init_form_fields()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$this->form_fields = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
array( 'title' => __( 'Main settings', 'retailcrm' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
|
|
|
|
'api_url' => array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __( 'API of URL', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'text',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __( 'Enter API of URL (https://yourdomain.retailcrm.pro).', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'desc_tip' => true,
|
|
|
|
'default' => ''
|
|
|
|
),
|
|
|
|
'api_key' => array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __( 'API key', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'text',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __( 'Enter your API key. You can find it in the administration section of retailCRM', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'desc_tip' => true,
|
|
|
|
'default' => ''
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$api_version_list = array(
|
|
|
|
'v4' => 'v4',
|
|
|
|
'v5' => 'v5'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'title' => __( 'API settings', 'retailcrm' ),
|
|
|
|
'type' => 'title',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'api_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['api_version'] = array(
|
|
|
|
'title' => __( 'API version', 'retailcrm' ),
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __( 'Select API version', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'css' => 'min-width:50px;',
|
|
|
|
'class' => 'select',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $api_version_list,
|
|
|
|
'desc_tip' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'title' => __( 'Catalog settings', 'retailcrm' ),
|
|
|
|
'type' => 'title',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'catalog_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach (get_post_statuses() as $status_key => $status_value) {
|
|
|
|
$this->form_fields['p_' . $status_key] = array(
|
|
|
|
'title' => $status_value,
|
|
|
|
'label' => ' ',
|
|
|
|
'description' => '',
|
|
|
|
'class' => 'checkbox',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'desc_tip' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->apiClient) {
|
|
|
|
if (isset($_GET['page']) && $_GET['page'] == 'wc-settings'
|
|
|
|
&& isset($_GET['tab']) && $_GET['tab'] == 'integration'
|
|
|
|
) {
|
|
|
|
add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Order methods options
|
|
|
|
*/
|
|
|
|
$order_methods_option = array();
|
|
|
|
$order_methods_list = $this->apiClient->orderMethodsList();
|
|
|
|
|
|
|
|
if ($order_methods_list->isSuccessful()) {
|
|
|
|
foreach ($order_methods_list['orderMethods'] as $order_method) {
|
|
|
|
if ($order_method['active'] == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$order_methods_option[$order_method['code']] = $order_method['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'title' => __('Order methods', 'retailcrm'),
|
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'order_methods_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['order_methods'] = array(
|
|
|
|
'label' => ' ',
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Order methods available for uploading from retailCRM', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'class' => '',
|
|
|
|
'type' => 'multiselect',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('Select order methods which will be uploaded from retailCRM to the website', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'options' => $order_methods_option,
|
2018-08-22 15:54:47 +03:00
|
|
|
'css' => 'min-height:100px;',
|
2018-04-27 11:19:02 +03:00
|
|
|
'select_buttons' => true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shipping options
|
|
|
|
*/
|
|
|
|
$shipping_option_list = array();
|
|
|
|
$retailcrm_shipping_list = $this->apiClient->deliveryTypesList();
|
|
|
|
|
|
|
|
if ($retailcrm_shipping_list->isSuccessful()) {
|
|
|
|
foreach ($retailcrm_shipping_list['deliveryTypes'] as $retailcrm_shipping_type) {
|
|
|
|
$shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$wc_shipping_list = get_wc_shipping_methods();
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Delivery types', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'shipping_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($wc_shipping_list as $shipping_code => $shipping) {
|
|
|
|
if (isset($shipping['enabled']) && $shipping['enabled'] == 'yes') {
|
|
|
|
$this->form_fields[$shipping_code] = array(
|
|
|
|
'title' => __($shipping['title'], 'woocommerce'),
|
|
|
|
'description' => __($shipping['description'], 'woocommerce'),
|
|
|
|
'css' => 'min-width:350px;',
|
|
|
|
'class' => 'select',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $shipping_option_list,
|
|
|
|
'desc_tip' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Payment options
|
|
|
|
*/
|
|
|
|
$payment_option_list = array();
|
|
|
|
$retailcrm_payment_list = $this->apiClient->paymentTypesList();
|
|
|
|
|
|
|
|
if ($retailcrm_payment_list->isSuccessful()) {
|
|
|
|
foreach ($retailcrm_payment_list['paymentTypes'] as $retailcrm_payment_type) {
|
|
|
|
$payment_option_list[$retailcrm_payment_type['code']] = $retailcrm_payment_type['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$wc_payment = WC_Payment_Gateways::instance();
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Payment types', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'payment_options'
|
|
|
|
);
|
|
|
|
|
2018-07-19 12:16:30 +03:00
|
|
|
foreach ($wc_payment->payment_gateways() as $payment) {
|
2018-04-27 11:19:02 +03:00
|
|
|
if (isset($payment->enabled) && $payment->enabled == 'yes') {
|
|
|
|
$this->form_fields[$payment->id] = array(
|
|
|
|
'title' => __($payment->method_title, 'woocommerce'),
|
|
|
|
'description' => __($payment->method_description, 'woocommerce'),
|
|
|
|
'css' => 'min-width:350px;',
|
|
|
|
'class' => 'select',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $payment_option_list,
|
|
|
|
'desc_tip' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statuses options
|
|
|
|
*/
|
|
|
|
$statuses_option_list = array();
|
|
|
|
$retailcrm_statuses_list = $this->apiClient->statusesList();
|
|
|
|
|
|
|
|
if ($retailcrm_statuses_list->isSuccessful()) {
|
|
|
|
foreach ($retailcrm_statuses_list['statuses'] as $retailcrm_status) {
|
|
|
|
$statuses_option_list[$retailcrm_status['code']] = $retailcrm_status['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$wc_statuses = wc_get_order_statuses();
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'title' => __('Statuses', 'retailcrm'),
|
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'statuses_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($wc_statuses as $idx => $name) {
|
|
|
|
$uid = str_replace('wc-', '', $idx);
|
|
|
|
$this->form_fields[$uid] = array(
|
|
|
|
'title' => __($name, 'woocommerce'),
|
|
|
|
'css' => 'min-width:350px;',
|
|
|
|
'class' => 'select',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => $statuses_option_list,
|
|
|
|
'desc_tip' => true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inventories options
|
|
|
|
*/
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Setting of the stock balance', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'invent_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['sync'] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'label' => __('Synchronization of the stock balance', 'retailcrm'),
|
|
|
|
'title' => __('Stock balance', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'class' => 'checkbox',
|
|
|
|
'type' => 'checkbox',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('Enable this setting if you would like to get information on leftover stocks from retailCRM to the website.', 'retailcrm')
|
2018-04-27 11:19:02 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UA options
|
|
|
|
*/
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'title' => __('UA settings', 'retailcrm'),
|
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'invent_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['ua'] = array(
|
|
|
|
'label' => __('Activate UA', 'retailcrm'),
|
|
|
|
'title' => __('UA', 'retailcrm'),
|
|
|
|
'class' => 'checkbox',
|
|
|
|
'type' => 'checkbox',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('Enable this setting for uploading data to UA', 'retailcrm')
|
2018-04-27 11:19:02 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['ua_code'] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('UA tracking code', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'class' => 'input',
|
|
|
|
'type' => 'input'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['ua_custom'] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('User parameter', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'class' => 'input',
|
|
|
|
'type' => 'input'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uploads options
|
|
|
|
*/
|
|
|
|
$options = array_filter(get_option(self::$option_key));
|
|
|
|
|
|
|
|
if (!isset($options['uploads'])) {
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Settings of uploading', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'heading',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'upload_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['upload-button'] = array(
|
|
|
|
'label' => __('Upload', 'retailcrm'),
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Uploading all customers and orders', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'button',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('Uploading the existing customers and orders to retailCRM', 'retailcrm' ),
|
2018-04-27 11:19:02 +03:00
|
|
|
'desc_tip' => true,
|
|
|
|
'id' => 'uploads-retailcrm'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate icml file
|
|
|
|
*/
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Generating ICML catalog', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'title',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'icml_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'label' => __('Generate now', 'retailcrm'),
|
|
|
|
'title' => __('Generating ICML', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'type' => 'button',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('This functionality allows to generate ICML products catalog for uploading to retailCRM.', 'retailcrm'),
|
2018-04-27 11:19:02 +03:00
|
|
|
'desc_tip' => true,
|
|
|
|
'id' => 'icml-retailcrm'
|
|
|
|
);
|
2018-05-28 12:56:19 +03:00
|
|
|
|
2018-08-22 15:54:47 +03:00
|
|
|
$this->form_fields['icml'] = array(
|
|
|
|
'label' => __('Generating ICML', 'retailcrm'),
|
|
|
|
'title' => __('Generating ICML catalog by wp-cron', 'retailcrm'),
|
|
|
|
'class' => 'checkbox',
|
|
|
|
'type' => 'checkbox'
|
|
|
|
);
|
|
|
|
|
2018-05-28 12:56:19 +03:00
|
|
|
/*
|
|
|
|
* Upload single order
|
|
|
|
*/
|
|
|
|
$this->form_field[] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'title' => __('Upload the order by ID', 'retailcrm'),
|
2018-05-28 12:56:19 +03:00
|
|
|
'type' => 'title',
|
|
|
|
'description' => '',
|
|
|
|
'id' => 'order_options'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields['single_order'] = array(
|
2018-08-15 17:01:29 +03:00
|
|
|
'label' => __('Order identifier', 'retailcrm'),
|
|
|
|
'title' => __('Orders identifiers', 'retailcrm'),
|
2018-05-28 12:56:19 +03:00
|
|
|
'type' => 'input',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('Enter orders identifiers separated by a comma.', 'retailcrm'),
|
2018-05-28 12:56:19 +03:00
|
|
|
'desc_tip' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->form_fields[] = array(
|
|
|
|
'label' => __('Upload', 'retailcrm'),
|
2018-08-15 17:30:43 +03:00
|
|
|
'title' => __('Uploading orders by identifiers.', 'retailcrm'),
|
2018-05-28 12:56:19 +03:00
|
|
|
'type' => 'button',
|
2018-08-15 17:01:29 +03:00
|
|
|
'description' => __('This functionality allows to upload orders to CRM differentially.', 'retailcrm'),
|
2018-05-28 12:56:19 +03:00
|
|
|
'desc_tip' => true,
|
|
|
|
'id' => 'single_order_btn'
|
|
|
|
);
|
2018-08-22 15:54:47 +03:00
|
|
|
|
|
|
|
$this->form_fields['history'] = array(
|
|
|
|
'label' => __('Activate history uploads', 'retailcrm'),
|
|
|
|
'title' => __('Upload data from retailCRM', 'retailcrm'),
|
|
|
|
'class' => 'checkbox',
|
|
|
|
'type' => 'checkbox'
|
|
|
|
);
|
2018-04-27 11:19:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate html button
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function generate_button_html($key, $data)
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$field = $this->plugin_id . $this->id . '_' . $key;
|
|
|
|
$defaults = array(
|
|
|
|
'class' => 'button-secondary',
|
|
|
|
'css' => '',
|
|
|
|
'custom_attributes' => array(),
|
|
|
|
'desc_tip' => false,
|
|
|
|
'description' => '',
|
|
|
|
'title' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = wp_parse_args( $data, $defaults );
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['label'] ); ?></span></legend>
|
|
|
|
<button id="<?php echo $data['id']; ?>" class="<?php echo esc_attr( $data['class'] ); ?>" type="button" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo wp_kses_post( $data['label'] ); ?></button>
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate html title block settings
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function generate_heading_html($key, $data)
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$field_key = $this->get_field_key( $key );
|
|
|
|
$defaults = array(
|
|
|
|
'title' => '',
|
|
|
|
'class' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = wp_parse_args( $data, $defaults );
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
<h2 class="wc-settings-sub-title retailcrm_hidden <?php echo esc_attr( $data['class'] ); ?>" id="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <span style="opacity:0.5;float: right;">⬇</span></h2>
|
|
|
|
<?php if ( ! empty( $data['description'] ) ) : ?>
|
|
|
|
<p><?php echo wp_kses_post( $data['description'] ); ?></p>
|
|
|
|
<?php endif; ?>
|
|
|
|
<table class="form-table" style="display: none;">
|
|
|
|
<?php
|
|
|
|
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate API version
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function validate_api_version_field($key, $value)
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$post = $this->get_post_data();
|
|
|
|
|
|
|
|
$versionMap = array(
|
|
|
|
'v4' => '4.0',
|
|
|
|
'v5' => '5.0'
|
|
|
|
);
|
|
|
|
|
|
|
|
$api = new WC_Retailcrm_Proxy(
|
|
|
|
$post[$this->plugin_id . $this->id . '_api_url'],
|
|
|
|
$post[$this->plugin_id . $this->id . '_api_key']
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $api->apiVersions();
|
|
|
|
|
|
|
|
if ($response && $response->isSuccessful()) {
|
|
|
|
if (!in_array($versionMap[$value], $response['versions'])) {
|
2018-08-15 17:01:29 +03:00
|
|
|
WC_Admin_Settings::add_error( esc_html__( 'The selected API version is unavailable', 'retailcrm' ) );
|
2018-04-27 11:19:02 +03:00
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 11:13:16 +03:00
|
|
|
|
|
|
|
return $value;
|
2018-04-27 11:19:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate API url
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function validate_api_url_field($key, $value)
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$post = $this->get_post_data();
|
|
|
|
$api = new WC_Retailcrm_Proxy(
|
|
|
|
$value,
|
|
|
|
$post[$this->plugin_id . $this->id . '_api_key']
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $api->apiVersions();
|
|
|
|
|
|
|
|
if ($response == null) {
|
2018-08-15 17:01:29 +03:00
|
|
|
WC_Admin_Settings::add_error(esc_html__( 'Enter the correct URL of CRM', 'retailcrm'));
|
2018-04-27 11:19:02 +03:00
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate API key
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function validate_api_key_field($key, $value)
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
$post = $this->get_post_data();
|
|
|
|
$api = new WC_Retailcrm_Proxy(
|
|
|
|
$post[$this->plugin_id . $this->id . '_api_url'],
|
|
|
|
$value
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $api->apiVersions();
|
|
|
|
|
|
|
|
if (!is_object($response)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$response->isSuccessful()) {
|
|
|
|
WC_Admin_Settings::add_error( esc_html__( 'Enter the correct API key', 'retailcrm' ) );
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scritp show|hide block settings
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
function show_blocks()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
jQuery('h2.retailcrm_hidden').hover().css({
|
|
|
|
'cursor':'pointer',
|
2018-08-15 17:01:29 +03:00
|
|
|
'width':'310px'
|
2018-04-27 11:19:02 +03:00
|
|
|
});
|
|
|
|
jQuery('h2.retailcrm_hidden').toggle(
|
|
|
|
function() {
|
|
|
|
jQuery(this).next('table.form-table').show(100);
|
|
|
|
jQuery(this).find('span').html('⬆');
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
jQuery(this).next('table.form-table').hide(100);
|
|
|
|
jQuery(this).find('span').html('⬇');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get retailcrm api client
|
|
|
|
*
|
|
|
|
* @return bool|WC_Retailcrm_Proxy
|
|
|
|
*/
|
2018-07-19 12:16:30 +03:00
|
|
|
public function getApiClient()
|
|
|
|
{
|
2018-04-27 11:19:02 +03:00
|
|
|
if ($this->get_option('api_url') && $this->get_option('api_key')) {
|
|
|
|
return new WC_Retailcrm_Proxy(
|
|
|
|
$this->get_option('api_url'),
|
|
|
|
$this->get_option('api_key'),
|
|
|
|
$this->get_option('api_version')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-31 11:13:16 +03:00
|
|
|
|
2018-08-30 14:52:48 +03:00
|
|
|
/**
|
|
|
|
* Add button in admin
|
|
|
|
*/
|
|
|
|
function add_retailcrm_button() {
|
|
|
|
global $wp_admin_bar;
|
|
|
|
if ( !is_super_admin() || !is_admin_bar_showing() || !is_admin())
|
|
|
|
return;
|
|
|
|
|
|
|
|
$wp_admin_bar->add_menu(
|
|
|
|
array(
|
|
|
|
'id' => 'retailcrm_top_menu',
|
|
|
|
'title' => __('retailCRM', 'retailcrm')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$wp_admin_bar->add_menu(
|
|
|
|
array(
|
|
|
|
'id' => 'retailcrm_ajax_generate_icml',
|
|
|
|
'title' => __('Generating ICML catalog', 'retailcrm'),
|
|
|
|
'href' => '#',
|
|
|
|
'parent' => 'retailcrm_top_menu',
|
|
|
|
'class' => 'retailcrm_ajax_generate_icml'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$wp_admin_bar->add_menu(
|
|
|
|
array(
|
|
|
|
'id' => 'retailcrm_ajax_generate_setings',
|
|
|
|
'title' => __('Settings', 'retailcrm'),
|
|
|
|
'href'=> get_site_url().'/wp-admin/admin.php?page=wc-settings&tab=integration§ion=integration-retailcrm',
|
|
|
|
'parent' => 'retailcrm_top_menu',
|
|
|
|
'class' => 'retailcrm_ajax_settings'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2018-08-31 11:13:16 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-27 11:19:02 +03:00
|
|
|
}
|
|
|
|
}
|