From 2c1c025b2b8370cdea0c806036965811f048785c Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 17 Nov 2017 16:57:21 +0300 Subject: [PATCH] Bug fix for php5.3, catalog options --- .../api/class-wc-retailcrm-client-v5.php | 4 +- .../include/class-wc-retailcrm-base.php | 70 ++++++++++++------- .../include/class-wc-retailcrm-icml.php | 33 +++++++-- .../include/class-wc-retailcrm-orders.php | 4 +- woo-retailcrm/uninstall.php | 6 +- 5 files changed, 80 insertions(+), 37 deletions(-) diff --git a/woo-retailcrm/include/api/class-wc-retailcrm-client-v5.php b/woo-retailcrm/include/api/class-wc-retailcrm-client-v5.php index 8294ac0..5a54a2a 100644 --- a/woo-retailcrm/include/api/class-wc-retailcrm-client-v5.php +++ b/woo-retailcrm/include/api/class-wc-retailcrm-client-v5.php @@ -295,9 +295,9 @@ * * @return WC_Retailcrm_Response */ - public function customDictionariesList(array $filter = [], $limit = null, $page = null) + public function customDictionariesList(array $filter = array(), $limit = null, $page = null) { - $parameters = []; + $parameters = array(); if (count($filter)) { $parameters['filter'] = $filter; diff --git a/woo-retailcrm/include/class-wc-retailcrm-base.php b/woo-retailcrm/include/class-wc-retailcrm-base.php index 8666400..6450ea7 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-base.php +++ b/woo-retailcrm/include/class-wc-retailcrm-base.php @@ -67,22 +67,40 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : $api_version_list = array('v4' => 'v4','v5' => 'v5'); $this->form_fields[] = array( - 'title' => __( 'Настройки API', 'woocommerce' ), - 'type' => 'title', + 'title' => __( 'Настройки API', 'woocommerce' ), + 'type' => 'title', 'description' => '', - 'id' => 'api_options' + 'id' => 'api_options' ); $this->form_fields['api_version'] = array( - 'title' => __( 'API версия', 'textdomain' ), + 'title' => __( 'API версия', 'textdomain' ), 'description' => __( 'Выберите версию API, которую Вы хотите использовать', 'textdomain' ), - 'css' => 'min-width:50px;', - 'class' => 'select', - 'type' => 'select', - 'options' => $api_version_list, + 'css' => 'min-width:50px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $api_version_list, 'desc_tip' => true, ); + $this->form_fields[] = array( + 'title' => __( 'Настройки каталога', 'woocommerce' ), + '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, 'textdomain' ), + 'label' => __( ' ', 'textdomain' ), + 'description' => '', + 'class' => 'checkbox', + 'type' => 'checkbox', + 'desc_tip' => true, + ); + } + if ($this->get_option( 'api_url' ) != '' && $this->get_option( 'api_key' ) != '') { if (isset($_GET['page']) && $_GET['page'] == 'wc-settings' && isset($_GET['tab']) && $_GET['tab'] == 'integration') { $retailcrm = new WC_Retailcrm_Proxy( @@ -180,21 +198,21 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : $wc_statuses = wc_get_order_statuses(); $this->form_fields[] = array( - 'title' => __( 'Статусы', 'woocommerce' ), - 'type' => 'title', + 'title' => __( 'Статусы', 'woocommerce' ), + 'type' => 'title', 'description' => '', - 'id' => 'statuses_options' + 'id' => 'statuses_options' ); foreach ( $wc_statuses as $idx => $name ) { $uid = str_replace('wc-', '', $idx); $this->form_fields[$uid] = array( - 'title' => __( $name, 'textdomain' ), - 'css' => 'min-width:350px;', - 'class' => 'select', - 'type' => 'select', - 'options' => $statuses_option_list, - 'desc_tip' => true, + 'title' => __( $name, 'textdomain' ), + 'css' => 'min-width:350px;', + 'class' => 'select', + 'type' => 'select', + 'options' => $statuses_option_list, + 'desc_tip' => true, ); } } @@ -203,17 +221,17 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : * Inventories options */ $this->form_fields[] = array( - 'title' => __( 'Настройки остатков', 'woocommerce' ), - 'type' => 'title', + 'title' => __( 'Настройки остатков', 'woocommerce' ), + 'type' => 'title', 'description' => '', - 'id' => 'invent_options' + 'id' => 'invent_options' ); $this->form_fields['sync'] = array( - 'label' => __( 'Выгружать остатки из CRM', 'textdomain' ), + 'label' => __( 'Выгружать остатки из CRM', 'textdomain' ), 'title' => 'Inventories', - 'class' => 'checkbox', - 'type' => 'checkbox', + 'class' => 'checkbox', + 'type' => 'checkbox', 'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.' ); @@ -224,10 +242,10 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) : if (!isset($options['uploads'])) { $this->form_fields[] = array( - 'title' => __( 'Выгрузка клиентов и заказов', 'woocommerce' ), - 'type' => 'title', + 'title' => __( 'Выгрузка клиентов и заказов', 'woocommerce' ), + 'type' => 'title', 'description' => '', - 'id' => 'upload_options' + 'id' => 'upload_options' ); $this->form_fields['upload-button'] = array( diff --git a/woo-retailcrm/include/class-wc-retailcrm-icml.php b/woo-retailcrm/include/class-wc-retailcrm-icml.php index ad796eb..7d78bd0 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-icml.php +++ b/woo-retailcrm/include/class-wc-retailcrm-icml.php @@ -73,8 +73,9 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) : $this->writeCategories($categories); unset($categories); } - - $this->get_wc_products_taxonomies(); + + $status_args = $this->checkPostStatuses(); + $this->get_wc_products_taxonomies($status_args); $dom = dom_import_simplexml(simplexml_load_file($this->tmpFile))->ownerDocument; $dom->formatOutput = true; $formatted = $dom->saveXML(); @@ -310,13 +311,24 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) : * * @return array */ - private function get_wc_products_taxonomies() { + private function get_wc_products_taxonomies($status_args) { + if (!$status_args) { + $status_args = array('publish'); + } + $full_product_list = array(); $offset = 0; $limit = 100; do { - $loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => $limit, 'offset' => $offset)); + $loop = new WP_Query( + array( + 'post_type' => array('product', 'product_variation'), + 'post_status' => $status_args, + 'posts_per_page' => $limit, + 'offset' => $offset + ) + ); while ($loop->have_posts()) : $loop->the_post(); $theid = get_the_ID(); @@ -484,6 +496,19 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) : return wc_get_price_including_tax($product); } } + + private function checkPostStatuses() { + $options = get_option( 'woocommerce_integration-retailcrm_settings' ); + $status_args = array(); + + foreach (get_post_statuses() as $key => $value) { + if (isset($options['p_' . $key]) && $options['p_' . $key] == 'yes') { + $status_args[] = $key; + } + } + + return $status_args; + } } endif; diff --git a/woo-retailcrm/include/class-wc-retailcrm-orders.php b/woo-retailcrm/include/class-wc-retailcrm-orders.php index 16ec1cf..a2b5cbf 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-orders.php +++ b/woo-retailcrm/include/class-wc-retailcrm-orders.php @@ -247,7 +247,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : */ public function getOrderData($order_id) { $order = new WC_Order( $order_id ); - $order_data_arr = []; + $order_data_arr = array(); if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) { $order_data_arr['id'] = $order->id; @@ -306,7 +306,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data['paymentType'] = $this->retailcrm_settings[$order_data_info['payment_method']]; } - if(!empty($order->get_items( 'shipping' )) && $order->get_items( 'shipping' ) != '') { + if ($order->get_items( 'shipping' )) { $shipping = end($order->get_items( 'shipping' )); $shipping_code = explode(':', $shipping['method_id']); $shipping_method = $shipping_code[0]; diff --git a/woo-retailcrm/uninstall.php b/woo-retailcrm/uninstall.php index 84d9813..d515c7f 100644 --- a/woo-retailcrm/uninstall.php +++ b/woo-retailcrm/uninstall.php @@ -14,8 +14,8 @@ * - Repeat things for multisite. Once for a single site in the network, once sitewide. * * - * @link https://wordpress.org/plugins/retailcrm/ - * @since 1.1 + * @link https://wordpress.org/plugins/woo-retailcrm/ + * @since 1.2.1 * * @package RetailCRM */ @@ -39,4 +39,4 @@ wp_clear_scheduled_hook( 'retailcrm_inventories' ); $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = 'woocommerce_integration-retailcrm_settings';" ); // Clear any cached data that has been removed -wp_cache_flush(); \ No newline at end of file +wp_cache_flush();