1
0
mirror of synced 2025-01-18 17:01:41 +03:00

Bug fix for php5.3, catalog options (#27)

* Bug fix for php5.3, catalog options
* Product price in order from cart
This commit is contained in:
Akolzin Dmitry 2017-11-24 16:04:28 +03:00 committed by Alex Lushpai
parent 59841e21e4
commit 9851b29f04
6 changed files with 87 additions and 40 deletions

View File

@ -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;

View File

@ -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(

View File

@ -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;

View File

@ -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];
@ -372,18 +372,22 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$_product = wc_get_product($uid);
if ($_product) {
$product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0;
$product_tax = $item->get_total_tax() ? $item->get_total_tax() / $item->get_quantity() : 0;
$price_item = $product_price + $product_tax;
if ($this->retailcrm_settings['api_version'] != 'v3') {
$order_item = array(
'offer' => array('externalId' => $uid),
'productName' => $item['name'],
'initialPrice' => (float)$_product->get_price(),
'initialPrice' => (float)$price_item,
'quantity' => $item['qty'],
);
} else {
$order_item = array(
'productId' => $uid,
'productName' => $item['name'],
'initialPrice' => (float)$_product->get_price(),
'initialPrice' => (float)$price_item,
'quantity' => $item['qty'],
);
}

View File

@ -1,6 +1,6 @@
<?php
/**
* Version: 1.2.1
* Version: 1.2.3
* Plugin Name: WooCommerce RetailCRM
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
* Description: Integration plugin for WooCommerce & RetailCRM

View File

@ -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();
wp_cache_flush();