fix form validation on save settings (#10)
This commit is contained in:
parent
7201d9fe08
commit
1cb97f9e92
@ -23,6 +23,10 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
//global $woocommerce;
|
//global $woocommerce;
|
||||||
|
|
||||||
|
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) {
|
||||||
|
include_once( __DIR__ . '/api/class-wc-retailcrm-proxy.php' );
|
||||||
|
}
|
||||||
|
|
||||||
$this->id = 'integration-retailcrm';
|
$this->id = 'integration-retailcrm';
|
||||||
$this->method_title = __( 'RetailCRM', 'woocommerce-integration-retailcrm' );
|
$this->method_title = __( 'RetailCRM', 'woocommerce-integration-retailcrm' );
|
||||||
$this->method_description = __( 'Интеграция с системой управления 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 ($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(
|
$retailcrm = new WC_Retailcrm_Proxy(
|
||||||
$this->get_option( 'api_url' ),
|
$this->get_option( 'api_url' ),
|
||||||
$this->get_option( 'api_key' ),
|
$this->get_option( 'api_key' ),
|
||||||
@ -282,13 +282,29 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
|||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $api->statisticUpdate();
|
$response = $api->deliveryTypesList();
|
||||||
|
|
||||||
if ($response['errorMsg'] == 'API method not found') {
|
if (isset($response['errorMsg']) && $response['errorMsg'] == 'API method not found') {
|
||||||
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-demo' ) );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user