1
0
mirror of synced 2025-01-31 07:11:42 +03:00

fix form validation on save settings (#10)

This commit is contained in:
Akolzin Dmitry 2017-08-18 11:27:11 +02:00 committed by Alex Lushpai
parent 7201d9fe08
commit 1cb97f9e92

View File

@ -23,6 +23,10 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
public function __construct() {
//global $woocommerce;
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) {
include_once( __DIR__ . '/api/class-wc-retailcrm-proxy.php' );
}
$this->id = 'integration-retailcrm';
$this->method_title = __( 'RetailCRM', 'woocommerce-integration-retailcrm' );
$this->method_description = __( 'Интеграция с системой управления Retailcrm.', 'woocommerce-integration-retailcrm' );
@ -81,10 +85,6 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
if ($this->get_option( 'api_url' ) != '' && $this->get_option( 'api_key' ) != '') {
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) {
include_once( __DIR__ . '/api/class-wc-retailcrm-proxy.php' );
}
$retailcrm = new WC_Retailcrm_Proxy(
$this->get_option( 'api_url' ),
$this->get_option( 'api_key' ),
@ -282,13 +282,29 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
$value
);
$response = $api->statisticUpdate();
$response = $api->deliveryTypesList();
if ($response['errorMsg'] == 'API method not found') {
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-demo' ) );
}
if (isset($response['errorMsg']) && $response['errorMsg'] == 'API method not found') {
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-retailcrm' ) );
} else {
return $value;
}
}
return $value;
public function validate_api_url_field( $key, $value ) {
$api = new WC_Retailcrm_Proxy(
$value,
$_POST['woocommerce_integration-retailcrm_api_key'],
'v4'
);
$response = $api->deliveryTypesList();
if ($response == NULL) {
WC_Admin_Settings::add_error( esc_html__( '"Введите корректный адрес CRM"', 'woocommerce-integration-retailcrm' ) );
} else {
return $value;
}
}
}