From 1cb97f9e9247db3b5d99675f223aca463a0699a6 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 18 Aug 2017 11:27:11 +0200 Subject: [PATCH 1/3] fix form validation on save settings (#10) --- retailcrm/include/class-wc-retailcrm-base.php | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/retailcrm/include/class-wc-retailcrm-base.php b/retailcrm/include/class-wc-retailcrm-base.php index 746f9f5..f9002ef 100644 --- a/retailcrm/include/class-wc-retailcrm-base.php +++ b/retailcrm/include/class-wc-retailcrm-base.php @@ -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; + } } } From 3f54a8fc893e338f8e314ddea8a23839b63c8931 Mon Sep 17 00:00:00 2001 From: dewalt201 Date: Thu, 24 Aug 2017 08:40:05 +0300 Subject: [PATCH 2/3] Some fixes (#11) --- .gitignore | 1 + .../include/class-wc-retailcrm-orders.php | 44 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bc68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ \ No newline at end of file diff --git a/retailcrm/include/class-wc-retailcrm-orders.php b/retailcrm/include/class-wc-retailcrm-orders.php index a471dba..7e0a27e 100644 --- a/retailcrm/include/class-wc-retailcrm-orders.php +++ b/retailcrm/include/class-wc-retailcrm-orders.php @@ -91,7 +91,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data['customer']['externalId'] = $search['customer']['externalId']; } } - + $res = $this->retailcrm->ordersCreate($order_data); } @@ -105,7 +105,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $response = $this->retailcrm->ordersEdit($address); } - + /** * Update order status * @@ -158,7 +158,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } } } - + /** * Update order payment * @@ -181,7 +181,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $this->retailcrm->ordersPaymentsEdit($payment); } - + } /** @@ -234,7 +234,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $shipping_cost = str_replace(',', '.', $shipping_cost); $order_data['delivery']['cost'] = $shipping_cost; } - + $response = $this->retailcrm->ordersEdit($order_data); } @@ -285,39 +285,49 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $status = $order->get_status(); $order_data['status'] = $this->retailcrm_settings[$status]; - + $user_data_billing = $order->get_address('billing'); if (!empty($user_data_billing)) { + if (!empty($user_data_billing['phone'])) $order_data['phone'] = $user_data_billing['phone']; if (!empty($user_data_billing['email'])) $order_data['email'] = $user_data_billing['email']; + if (!empty($user_data_billing['first_name'])) $order_data['firstName'] = $user_data_billing['first_name']; + if (!empty($user_data_billing['last_name'])) $order_data['lastName'] = $user_data_billing['last_name']; + if (!empty($user_data_billing['postcode'])) $order_data['delivery']['address']['index'] = $user_data_billing['postcode']; + if (!empty($user_data_billing['city'])) $order_data['delivery']['address']['city'] = $user_data_billing['city']; + if (!empty($user_data_billing['country'])) $order_data['delivery']['address']['countryIso'] = $user_data_billing['country']; + } $user_data = $order->get_address('shipping'); if (!empty($user_data)) { + if (!empty($user_data['phone'])) $order_data['phone'] = $user_data['phone']; + if (!empty($user_data['email'])) $order_data['email'] = $user_data['email']; if (!empty($user_data['first_name'])) $order_data['firstName'] = $user_data['first_name']; - if (!empty($user_data['last_name'])) $order_data['lastName'] = $user_data['last_name']; + if (!empty($user_data['last_name'])) $order_data['lastName'] = $user_data['last_name']; if (!empty($user_data['postcode'])) $order_data['delivery']['address']['index'] = $user_data['postcode']; if (!empty($user_data['city'])) $order_data['delivery']['address']['city'] = $user_data['city']; if (!empty($user_data['country'])) $order_data['delivery']['address']['countryIso'] = $user_data['country']; - $order_data['delivery']['address']['text'] = sprintf( - "%s %s %s %s", - $user_data['postcode'], - $user_data['city'], - $user_data['address_1'], - $user_data['address_2'] - ); } + $order_data['delivery']['address']['text'] = sprintf( + "%s %s %s %s", + !empty($user_data_billing['postcode']) ? $user_data_billing['postcode'] : $user_data['postcode'], + !empty($user_data_billing['city']) ? $user_data_billing['city'] : $user_data['city'], + !empty($user_data_billing['address_1']) ? $user_data_billing['address_1'] : $user_data['address_1'], + !empty($user_data_billing['address_2']) ? $user_data_billing['address_2'] : $user_data['address_2'] + ); + $order_items = array(); foreach ($order->get_items() as $item) { $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $_product = wc_get_product($uid); - + if ($_product) { if ($this->retailcrm_settings['api_version'] != 'v3') { $order_item = array( @@ -393,7 +403,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $pay_date = $order->get_date_paid(); $payment['paidAt'] = $pay_date->date('Y-m-d H:i:s'); } - + $this->retailcrm->ordersPaymentCreate($payment); } @@ -410,4 +420,4 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } } } -endif; +endif; \ No newline at end of file From 77c84ba1f36bc3f52be69f945adf8e0729a9a092 Mon Sep 17 00:00:00 2001 From: dewalt201 Date: Fri, 25 Aug 2017 17:24:16 +0300 Subject: [PATCH 3/3] Fix for payment types ,in admin interface (#13) --- retailcrm/include/class-wc-retailcrm-base.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/retailcrm/include/class-wc-retailcrm-base.php b/retailcrm/include/class-wc-retailcrm-base.php index f9002ef..e7286b7 100644 --- a/retailcrm/include/class-wc-retailcrm-base.php +++ b/retailcrm/include/class-wc-retailcrm-base.php @@ -26,7 +26,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : 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' ); @@ -141,7 +141,6 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : } $wc_payment = new WC_Payment_Gateways(); - $wc_payment_list = $wc_payment->get_available_payment_gateways(); $this->form_fields[] = array( 'title' => __( 'Способы оплаты', 'woocommerce' ), @@ -150,7 +149,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : 'id' => 'payment_options' ); - foreach ( $wc_payment_list as $payment ) { + foreach ( $wc_payment->payment_gateways as $payment ) { if ( isset( $payment->enabled ) && $payment->enabled == 'yes' ) { $key = $payment->id; $name = $key; @@ -230,7 +229,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : 'description' => '', 'id' => 'upload_options' ); - + $this->form_fields['upload-button'] = array( 'label' => 'Выгрузить', 'title' => __( 'Выгрузка клиентов и заказов', 'woocommerce-integration-retailcrm' ), @@ -283,12 +282,12 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : ); $response = $api->deliveryTypesList(); - + if (isset($response['errorMsg']) && $response['errorMsg'] == 'API method not found') { WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-retailcrm' ) ); } else { return $value; - } + } } public function validate_api_url_field( $key, $value ) { @@ -299,7 +298,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : ); $response = $api->deliveryTypesList(); - + if ($response == NULL) { WC_Admin_Settings::add_error( esc_html__( '"Введите корректный адрес CRM"', 'woocommerce-integration-retailcrm' ) ); } else {