1
0
mirror of synced 2025-03-23 00:23:51 +03:00

Edit order create hook, added check correct data in base class (#6)

This commit is contained in:
Akolzin Dmitry 2017-08-07 12:52:38 +02:00 committed by Alex Lushpai
parent 6aa9d3c1fd
commit 1e114cd22e
3 changed files with 97 additions and 86 deletions

View File

@ -49,24 +49,25 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
public function __call($method, $arguments) public function __call($method, $arguments)
{ {
try { if (!isset($this->retailcrm)) return;
$response = call_user_func_array(array($this->retailcrm, $method), $arguments); try {
$response = call_user_func_array(array($this->retailcrm, $method), $arguments);
if ($response->isSuccessful()) {
$result = ' Ok'; if ($response->isSuccessful()) {
} else { $result = ' Ok';
$result = sprintf( } else {
$method ." : Error: [HTTP-code %s] %s", $result = sprintf(
$response->getStatusCode(), $method ." : Error: [HTTP-code %s] %s",
$response->getErrorMsg() $response->getStatusCode(),
); $response->getErrorMsg()
);
if (isset($response['errors'])) { if (isset($response['errors'])) {
foreach ($response['errors'] as $error) { foreach ($response['errors'] as $error) {
$result .= " $error"; $result .= " $error";
}
} }
} }
}
$this->logger->add('retailcrm', sprintf("[%s] %s", $method, $result)); $this->logger->add('retailcrm', sprintf("[%s] %s", $method, $result));
} catch (WC_Retailcrm_Exception_Curl $exception) { } catch (WC_Retailcrm_Exception_Curl $exception) {

View File

@ -94,74 +94,76 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
/** /**
* Shipping options * Shipping options
*/ */
$shipping_option_list = array(); $shipping_option_list = array();
$retailcrm_shipping_list = $retailcrm->deliveryTypesList(); $retailcrm_shipping_list = $retailcrm->deliveryTypesList();
foreach ($retailcrm_shipping_list['deliveryTypes'] as $retailcrm_shipping_type) { if ($retailcrm_shipping_list->isSuccessful()) {
$shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name']; foreach ($retailcrm_shipping_list['deliveryTypes'] as $retailcrm_shipping_type) {
} $shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name'];
}
$wc_shipping = new WC_Shipping(); $wc_shipping = new WC_Shipping();
$wc_shipping_list = $wc_shipping->get_shipping_methods(); $wc_shipping_list = $wc_shipping->get_shipping_methods();
$this->form_fields[] = array( $this->form_fields[] = array(
'title' => __( 'Способы доставки', 'woocommerce' ), 'title' => __( 'Способы доставки', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
'description' => '', 'description' => '',
'id' => 'shipping_options' 'id' => 'shipping_options'
); );
foreach ( $wc_shipping_list as $shipping ) { foreach ( $wc_shipping_list as $shipping ) {
if ( isset( $shipping->enabled ) && $shipping->enabled == 'yes' ) { if ( isset( $shipping->enabled ) && $shipping->enabled == 'yes' ) {
$key = $shipping->id; $key = $shipping->id;
$name = $key; $name = $key;
$this->form_fields[$name] = array( $this->form_fields[$name] = array(
'title' => __( $shipping->method_title, 'textdomain' ), 'title' => __( $shipping->method_title, 'textdomain' ),
'description' => __( $shipping->method_description, 'textdomain' ), 'description' => __( $shipping->method_description, 'textdomain' ),
'css' => 'min-width:350px;', 'css' => 'min-width:350px;',
'class' => 'select', 'class' => 'select',
'type' => 'select', 'type' => 'select',
'options' => $shipping_option_list, 'options' => $shipping_option_list,
'desc_tip' => true, 'desc_tip' => true,
); );
}
} }
} }
/** /**
* Payment options * Payment options
*/ */
$payment_option_list = array(); $payment_option_list = array();
$retailcrm_payment_list = $retailcrm->paymentTypesList(); $retailcrm_payment_list = $retailcrm->paymentTypesList();
foreach ($retailcrm_payment_list['paymentTypes'] as $retailcrm_payment_type) { if ($retailcrm_payment_list->isSuccessful()) {
$payment_option_list[$retailcrm_payment_type['code']] = $retailcrm_payment_type['name']; foreach ($retailcrm_payment_list['paymentTypes'] as $retailcrm_payment_type) {
} $payment_option_list[$retailcrm_payment_type['code']] = $retailcrm_payment_type['name'];
}
$wc_payment = new WC_Payment_Gateways(); $wc_payment = new WC_Payment_Gateways();
$wc_payment_list = $wc_payment->get_available_payment_gateways(); $wc_payment_list = $wc_payment->get_available_payment_gateways();
$this->form_fields[] = array( $this->form_fields[] = array(
'title' => __( 'Способы оплаты', 'woocommerce' ), 'title' => __( 'Способы оплаты', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
'description' => '', 'description' => '',
'id' => 'payment_options' 'id' => 'payment_options'
); );
foreach ( $wc_payment_list as $payment ) { foreach ( $wc_payment_list as $payment ) {
if ( isset( $payment->enabled ) && $payment->enabled == 'yes' ) { if ( isset( $payment->enabled ) && $payment->enabled == 'yes' ) {
$key = $payment->id; $key = $payment->id;
$name = $key; $name = $key;
$this->form_fields[$name] = array( $this->form_fields[$name] = array(
'title' => __( $payment->method_title, 'textdomain' ), 'title' => __( $payment->method_title, 'textdomain' ),
'description' => __( $payment->method_description, 'textdomain' ), 'description' => __( $payment->method_description, 'textdomain' ),
'css' => 'min-width:350px;', 'css' => 'min-width:350px;',
'class' => 'select', 'class' => 'select',
'type' => 'select', 'type' => 'select',
'options' => $payment_option_list, 'options' => $payment_option_list,
'desc_tip' => true, 'desc_tip' => true,
); );
}
} }
} }
@ -171,31 +173,36 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
$statuses_option_list = array(); $statuses_option_list = array();
$retailcrm_statuses_list = $retailcrm->statusesList(); $retailcrm_statuses_list = $retailcrm->statusesList();
foreach ($retailcrm_statuses_list['statuses'] as $retailcrm_status) { if ($retailcrm_statuses_list->isSuccessful()) {
$statuses_option_list[$retailcrm_status['code']] = $retailcrm_status['name']; foreach ($retailcrm_statuses_list['statuses'] as $retailcrm_status) {
} $statuses_option_list[$retailcrm_status['code']] = $retailcrm_status['name'];
}
$wc_statuses = wc_get_order_statuses(); $wc_statuses = wc_get_order_statuses();
$this->form_fields[] = array( $this->form_fields[] = array(
'title' => __( 'Статусы', 'woocommerce' ), 'title' => __( 'Статусы', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
'description' => '', '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,
); );
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,
);
}
} }
/**
* Inventories options
*/
$this->form_fields[] = array( $this->form_fields[] = array(
'title' => __( 'Настройки остатков', 'woocommerce' ), 'title' => __( 'Настройки остатков', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
@ -211,6 +218,9 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.' 'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.'
); );
/**
* Uploads options
*/
$options = array_filter(get_option( 'woocommerce_integration-retailcrm_settings' )); $options = array_filter(get_option( 'woocommerce_integration-retailcrm_settings' ));
if (!isset($options['uploads'])) { if (!isset($options['uploads'])) {

View File

@ -335,7 +335,7 @@ register_deactivation_hook( __FILE__, 'retailcrm_deactivation' );
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins')))) { if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins')))) {
load_plugin_textdomain('wc_retailcrm', false, dirname(plugin_basename( __FILE__ )) . '/'); load_plugin_textdomain('wc_retailcrm', false, dirname(plugin_basename( __FILE__ )) . '/');
add_filter('cron_schedules', 'filter_cron_schedules', 10, 1); add_filter('cron_schedules', 'filter_cron_schedules', 10, 1);
add_action('woocommerce_thankyou', 'retailcrm_process_order', 10, 1); add_action('woocommerce_checkout_order_processed', 'retailcrm_process_order', 10, 1);
add_action('retailcrm_history', 'retailcrm_history_get'); add_action('retailcrm_history', 'retailcrm_history_get');
add_action('retailcrm_icml', 'generate_icml'); add_action('retailcrm_icml', 'generate_icml');
add_action('retailcrm_inventories', 'load_stocks'); add_action('retailcrm_inventories', 'load_stocks');