Update version (#37)
Dimensions in imcl, button genarate icml, advanced search for delivery methods Dimensions in imcl, button genarate icml, advanced search for delivery methods
This commit is contained in:
parent
ca69523a13
commit
a06a7d5fba
@ -33,33 +33,27 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-client-v5.php' );
|
||||
}
|
||||
|
||||
if ($api_url && $api_key) {
|
||||
switch ($api_vers) {
|
||||
case 'v3':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case 'v4':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V4($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case 'v5':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V5($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case null:
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
}
|
||||
switch ($api_vers) {
|
||||
case 'v3':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case 'v4':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V4($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case 'v5':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V5($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case null:
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if (!$this->retailcrm) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = call_user_func_array(array($this->retailcrm, $method), $arguments);
|
||||
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$result = ' Ok';
|
||||
} else {
|
||||
|
@ -120,8 +120,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
$shipping_option_list[$retailcrm_shipping_type['code']] = $retailcrm_shipping_type['name'];
|
||||
}
|
||||
|
||||
$wc_shipping = new WC_Shipping();
|
||||
$wc_shipping_list = $wc_shipping->get_shipping_methods();
|
||||
$wc_shipping_list = get_wc_shipping_methods();
|
||||
|
||||
$this->form_fields[] = array(
|
||||
'title' => __( 'Способы доставки', 'woocommerce' ),
|
||||
@ -130,13 +129,11 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
'id' => 'shipping_options'
|
||||
);
|
||||
|
||||
foreach ( $wc_shipping_list as $shipping ) {
|
||||
if ( isset( $shipping->enabled ) && $shipping->enabled == 'yes' ) {
|
||||
$key = $shipping->id;
|
||||
$name = $key;
|
||||
$this->form_fields[$name] = array(
|
||||
'title' => __( $shipping->method_title, 'textdomain' ),
|
||||
'description' => __( $shipping->method_description, 'textdomain' ),
|
||||
foreach ( $wc_shipping_list as $shipping_code => $shipping ) {
|
||||
if ( isset( $shipping['enabled'] ) && $shipping['enabled'] == 'yes' ) {
|
||||
$this->form_fields[$shipping_code] = array(
|
||||
'title' => __( $shipping['title'], 'textdomain' ),
|
||||
'description' => __( $shipping['description'], 'textdomain' ),
|
||||
'css' => 'min-width:350px;',
|
||||
'class' => 'select',
|
||||
'type' => 'select',
|
||||
@ -221,7 +218,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
* Inventories options
|
||||
*/
|
||||
$this->form_fields[] = array(
|
||||
'title' => __( 'Настройки остатков', 'woocommerce' ),
|
||||
'title' => __( 'Настройки выгрузки остатков', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'description' => '',
|
||||
'id' => 'invent_options'
|
||||
@ -229,7 +226,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
|
||||
$this->form_fields['sync'] = array(
|
||||
'label' => __( 'Выгружать остатки из CRM', 'textdomain' ),
|
||||
'title' => 'Inventories',
|
||||
'title' => 'Остатки',
|
||||
'class' => 'checkbox',
|
||||
'type' => 'checkbox',
|
||||
'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.'
|
||||
@ -257,6 +254,25 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
'id' => 'uploads-retailcrm'
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate icml file
|
||||
*/
|
||||
$this->form_fields[] = array(
|
||||
'title' => __( 'Генерация каталога товаров', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'description' => '',
|
||||
'id' => 'icml_options'
|
||||
);
|
||||
|
||||
$this->form_fields[] = array(
|
||||
'label' => 'Сгенерировать',
|
||||
'title' => __( 'Генерация icml', 'woocommerce-integration-retailcrm' ),
|
||||
'type' => 'button',
|
||||
'description' => __( 'Данный функционал позволяет сгенерировать каталог товаров для выгрузки в CRM.', 'woocommerce-integration-retailcrm' ),
|
||||
'desc_tip' => true,
|
||||
'id' => 'icml-retailcrm'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -294,6 +310,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
}
|
||||
|
||||
public function validate_api_version_field( $key, $value ) {
|
||||
$post = $this->get_post_data();
|
||||
$versionMap = array(
|
||||
'v3' => '3.0',
|
||||
'v4' => '4.0',
|
||||
@ -301,8 +318,8 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
);
|
||||
|
||||
$api = new WC_Retailcrm_Proxy(
|
||||
$_POST['woocommerce_integration-retailcrm_api_url'],
|
||||
$_POST['woocommerce_integration-retailcrm_api_key']
|
||||
$post[$this->plugin_id . $this->id . '_api_url'],
|
||||
$post[$this->plugin_id . $this->id . '_api_key']
|
||||
);
|
||||
|
||||
$response = $api->apiVersions();
|
||||
@ -310,25 +327,49 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
if ($response && $response->isSuccessful()) {
|
||||
if (!in_array($versionMap[$value], $response['versions'])) {
|
||||
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-retailcrm' ) );
|
||||
} else {
|
||||
return $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function validate_api_url_field( $key, $value ) {
|
||||
$post = $this->get_post_data();
|
||||
$api = new WC_Retailcrm_Proxy(
|
||||
$value,
|
||||
$_POST['woocommerce_integration-retailcrm_api_key']
|
||||
$post[$this->plugin_id . $this->id . '_api_key']
|
||||
);
|
||||
|
||||
$response = $api->apiVersions();
|
||||
|
||||
if ($response == NULL) {
|
||||
WC_Admin_Settings::add_error( esc_html__( '"Введите корректный адрес CRM"', 'woocommerce-integration-retailcrm' ) );
|
||||
} else {
|
||||
return $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function validate_api_key_field( $key, $value ) {
|
||||
$post = $this->get_post_data();
|
||||
$api = new WC_Retailcrm_Proxy(
|
||||
$post[$this->plugin_id . $this->id . '_api_url'],
|
||||
$value
|
||||
);
|
||||
|
||||
$response = $api->apiVersions();
|
||||
|
||||
if (!is_object($response)) {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
WC_Admin_Settings::add_error( esc_html__( '"Введитe правильный API ключ"', 'woocommerce-integration-retailcrm' ) );
|
||||
$value = '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
|
||||
if ($user->roles[0] != 'customer') continue;
|
||||
|
||||
$customer = new WC_Customer($user->ID);
|
||||
|
||||
$firstName = $customer->get_first_name();
|
||||
$data_customer = array(
|
||||
'createdAt' => $user->data->user_registered,
|
||||
'externalId' => $user->ID,
|
||||
'firstName' => !empty($customer->get_first_name()) ? $customer->get_first_name() : $customer->get_username(),
|
||||
'firstName' => $firstName ? $firstName : $customer->get_username(),
|
||||
'lastName' => $customer->get_last_name(),
|
||||
'email' => $user->data->user_email,
|
||||
'phones' => array(
|
||||
@ -96,10 +96,11 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
|
||||
protected function processCustomer($customer)
|
||||
{
|
||||
$createdAt = $customer->get_date_created();
|
||||
$firstName = $customer->get_first_name();
|
||||
$data_customer = array(
|
||||
'createdAt' => $createdAt->date('Y-m-d H:i:s '),
|
||||
'externalId' => $customer_id,
|
||||
'firstName' => !empty($customer->get_first_name()) ? $customer->get_first_name() : $customer->get_username(),
|
||||
'firstName' => $firstName ? $firstName : $customer->get_username(),
|
||||
'lastName' => $customer->get_last_name(),
|
||||
'email' => $customer->get_email(),
|
||||
'phones' => array(
|
||||
|
@ -38,7 +38,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
}
|
||||
|
||||
public function getHistory()
|
||||
{
|
||||
{
|
||||
if (isset($this->retailcrm_settings['history_orders'])) {
|
||||
$this->startDateOrders = new DateTime($this->retailcrm_settings['history_orders']);
|
||||
}
|
||||
@ -50,7 +50,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
$this->ordersHistory($this->startDateOrders->format('Y-m-d H:i:s'));
|
||||
|
||||
$this->customersHistory($this->startDateCustomers->format('Y-m-d H:i:s'));
|
||||
|
||||
}
|
||||
|
||||
protected function customersHistory($date)
|
||||
@ -64,7 +63,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
if ($record['source'] == 'api' && $record['apiKey']['current'] == true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$this->removeFuncsHook();
|
||||
|
||||
if ($record['field'] == 'first_name' && $record['customer']['externalId']) {
|
||||
@ -117,7 +116,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
$this->addFuncsHook();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (empty($response)) {
|
||||
@ -131,18 +129,17 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
protected function ordersHistory($date)
|
||||
{
|
||||
$options = array_flip(array_filter($this->retailcrm_settings));
|
||||
|
||||
|
||||
$response = $this->retailcrm->ordersHistory(array('startDate' => $date));
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
|
||||
$generatedAt = $response->generatedAt;
|
||||
|
||||
foreach ($response['history'] as $record) {
|
||||
if ($record['source'] == 'api' && $record['apiKey']['current'] == true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$this->removeFuncsHook();
|
||||
|
||||
if ($record['field'] == 'status' && !empty($record['newValue']) && !empty($record['oldValue'])) {
|
||||
@ -160,13 +157,13 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
$this->update_total($order);
|
||||
}
|
||||
|
||||
|
||||
elseif($record['field'] == 'order_product.quantity' && $record['newValue']) {
|
||||
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$product = wc_get_product($record['item']['offer']['externalId']);
|
||||
$items = $order->get_items();
|
||||
|
||||
|
||||
foreach ($items as $order_item_id => $item) {
|
||||
if ($item['variation_id'] != 0 ) {
|
||||
$offer_id = $item['variation_id'];
|
||||
@ -180,11 +177,11 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
elseif ($record['field'] == 'order_product' && !$record['newValue']) {
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$items = $order->get_items();
|
||||
|
||||
|
||||
foreach ($items as $order_item_id => $item) {
|
||||
if ($item['variation_id'] != 0 ) {
|
||||
$offer_id = $item['variation_id'];
|
||||
@ -200,26 +197,43 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
elseif ($record['field'] == 'delivery_type') {
|
||||
$newValue = $record['newValue']['code'];
|
||||
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$items = $order->get_items('shipping');
|
||||
$wc_shipping = new WC_Shipping();
|
||||
$wc_shipping_list = $wc_shipping->get_shipping_methods();
|
||||
|
||||
foreach ($wc_shipping_list as $method) {
|
||||
if ($method->id == $options[$newValue]) {
|
||||
$deliveryCost = $method->cost;
|
||||
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
||||
if (isset($options[$newValue])) {
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$items = $order->get_items('shipping');
|
||||
$item_id = $this->getShippingItemId($items);
|
||||
$crmOrder = $this->retailcrm->ordersGet($record['order']['externalId']);
|
||||
$shipping_methods = get_wc_shipping_methods(true);
|
||||
|
||||
if (isset($shipping_methods[$options[$newValue]])) {
|
||||
$method_id = $options[$newValue];
|
||||
} else {
|
||||
$method_id = explode(':', $options[$newValue]);
|
||||
$method_id = $method_id[0];
|
||||
$shipping_method = $shipping_methods[$method_id]['shipping_methods'][$options[$newValue]];
|
||||
}
|
||||
|
||||
if ( is_object($crmOrder)) {
|
||||
if ($crmOrder->isSuccessful()) {
|
||||
$deliveryCost = isset($crmOrder['order']['delivery']['cost']) ? $crmOrder['order']['delivery']['cost'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'method_id' => $options[$newValue],
|
||||
'method_title' => isset($shipping_method) ? $shipping_method['title'] : $shipping_methods[$options[$newValue]]['name'],
|
||||
'total' => $deliveryCost
|
||||
);
|
||||
|
||||
$item = $order->get_item((int)$item_id);
|
||||
$item->set_order_id((int)$order->get_id());
|
||||
$item->set_props($args);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$item_id = $this->getShippingItemId($items);
|
||||
$args = array(
|
||||
'method_id' => $options[$newValue],
|
||||
'cost' => $deliveryCost ? $deliveryCost : 0
|
||||
);
|
||||
$order->update_shipping( $item_id, $args );
|
||||
|
||||
$this->update_total($order);
|
||||
$updateOrder = new WC_Order((int)$order->get_id());
|
||||
$this->update_total($updateOrder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,7 +256,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$order->set_shipping_address_2($record['newValue']);
|
||||
}
|
||||
|
||||
|
||||
elseif ($record['field'] == 'payment_type') {
|
||||
$order = new WC_Order($record['order']['externalId']);
|
||||
$newValue = $record['newValue']['code'];
|
||||
@ -305,27 +319,27 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
$address_shipping = array(
|
||||
'first_name' => $order_record['firstName'],
|
||||
'last_name' => $order_record['lastName'],
|
||||
'last_name' => isset($order_record['lastName']) ? $order_record['lastName'] : '',
|
||||
'company' => '',
|
||||
'email' => $order_record['email'],
|
||||
'phone' => $order_record['phone'],
|
||||
'address_1' => $order_record['delivery']['address']['text'],
|
||||
'email' => isset($order_record['email']) ? $order_record['email'] : '',
|
||||
'phone' => isset($order_record['phone']) ? $order_record['phone'] : '',
|
||||
'address_1' => isset($order_record['delivery']['address']['text']) ? $order_record['delivery']['address']['text'] : '',
|
||||
'address_2' => '',
|
||||
'city' => $order_record['delivery']['address']['city'],
|
||||
'state' => $order_record['delivery']['address']['region'],
|
||||
'city' => isset($order_record['delivery']['address']['city']) ? $order_record['delivery']['address']['city'] : '',
|
||||
'state' => isset($order_record['delivery']['address']['region']) ? $order_record['delivery']['address']['region'] : '',
|
||||
'postcode' => isset($order_record['delivery']['address']['postcode']) ? $order_record['delivery']['address']['postcode'] : '',
|
||||
'country' => $order_record['delivery']['address']['countryIso']
|
||||
);
|
||||
$address_billing = array(
|
||||
'first_name' => $order_record['customer']['firstName'],
|
||||
'last_name' => $order_record['customer']['lastName'],
|
||||
'last_name' => isset($order_record['customer']['lastName']) ? $order_record['customer']['lastName'] : '',
|
||||
'company' => '',
|
||||
'email' => $order_record['customer']['email'],
|
||||
'phone' => $order_record['customer'][0]['number'],
|
||||
'address_1' => $order_record['customer']['address']['text'],
|
||||
'email' => isset($order_record['customer']['email']) ? $order_record['customer']['email'] : '',
|
||||
'phone' => isset($order_record['customer'][0]['number']) ? $order_record['customer'][0]['number'] : '',
|
||||
'address_1' => isset($order_record['customer']['address']['text']) ? $order_record['customer']['address']['text'] : '',
|
||||
'address_2' => '',
|
||||
'city' => $order_record['customer']['address']['city'],
|
||||
'state' => $order_record['customer']['address']['region'],
|
||||
'city' => isset($order_record['customer']['address']['city']) ? $order_record['customer']['address']['city'] : '',
|
||||
'state' => isset($order_record['customer']['address']['region']) ? $order_record['customer']['address']['region'] : '',
|
||||
'postcode' => isset($order_record['customer']['address']['postcode']) ? $order_record['customer']['address']['postcode'] : '',
|
||||
'country' => $order_record['customer']['address']['countryIso']
|
||||
);
|
||||
@ -355,50 +369,70 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
$order->set_address($address_billing, 'billing');
|
||||
$order->set_address($address_shipping, 'shipping');
|
||||
$product_data = $order_record['items'];
|
||||
$product_data = isset($order_record['items']) ? $order_record['items'] : array();
|
||||
|
||||
foreach ($product_data as $product) {
|
||||
$order->add_product(wc_get_product($product['offer']['externalId']), $product['quantity']);
|
||||
}
|
||||
|
||||
$wc_shipping = new WC_Shipping();
|
||||
$wc_shipping_types = $wc_shipping->get_shipping_methods();
|
||||
|
||||
foreach ($wc_shipping_types as $shipping_type) {
|
||||
if ($shipping_type->id == $options[$order_record['delivery']['code']]) {
|
||||
$shipping_method_id = $shipping_type->id;
|
||||
$shipping_method_title = $shipping_type->title;
|
||||
$shipping_total = $shipping_type->cost;
|
||||
if ($product_data) {
|
||||
foreach ($product_data as $product) {
|
||||
$order->add_product(wc_get_product($product['offer']['externalId']), $product['quantity']);
|
||||
}
|
||||
}
|
||||
|
||||
if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) {
|
||||
$shipping_rate = new WC_Shipping_Rate($shipping_method_id, isset($shipping_method_title) ? $shipping_method_title : '', isset($shipping_total) ? floatval($shipping_total) : 0, array(), $shipping_method_id);
|
||||
$order->add_shipping($shipping_rate);
|
||||
} else {
|
||||
$shipping = new WC_Order_Item_Shipping();
|
||||
$shipping->set_props( array(
|
||||
'method_title' => $shipping_method_title,
|
||||
'method_id' => $shipping_method_id,
|
||||
'total' => wc_format_decimal($shipping_total),
|
||||
'order_id' => $order->id
|
||||
) );
|
||||
$shipping->save();
|
||||
$order->add_item( $shipping );
|
||||
if (array_key_exists('delivery', $order_record)) {
|
||||
$deliveryCode = isset($order_record['delivery']['code']) ? $order_record['delivery']['code'] : false;
|
||||
|
||||
if ($deliveryCode && isset($options[$deliveryCode])) {
|
||||
$delivery = explode(':', $options[$deliveryCode]);
|
||||
|
||||
if (isset($delivery[1])) {
|
||||
$instance_id = $delivery[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($instance_id)) {
|
||||
$wc_shipping = WC_Shipping_Zones::get_shipping_method($instance_id);
|
||||
$shipping_method_title = $wc_shipping->method_title;
|
||||
$shipping_method_id = $options[$deliveryCode];
|
||||
$shipping_total = $order_record['delivery']['cost'];
|
||||
} else {
|
||||
$wc_shipping = new WC_Shipping();
|
||||
$wc_shipping_types = $wc_shipping->get_shipping_methods();
|
||||
|
||||
foreach ($wc_shipping_types as $shipping_type) {
|
||||
if ($shipping_type->id == $options[$deliveryCode]) {
|
||||
$shipping_method_id = $shipping_type->id;
|
||||
$shipping_method_title = $shipping_type->method_title;
|
||||
$shipping_total = $order_record['delivery']['cost'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) {
|
||||
$shipping_rate = new WC_Shipping_Rate($shipping_method_id, isset($shipping_method_title) ? $shipping_method_title : '', isset($shipping_total) ? floatval($shipping_total) : 0, array(), $shipping_method_id);
|
||||
$order->add_shipping($shipping_rate);
|
||||
} else {
|
||||
$shipping = new WC_Order_Item_Shipping();
|
||||
$shipping->set_props( array(
|
||||
'method_title' => $shipping_method_title,
|
||||
'method_id' => $shipping_method_id,
|
||||
'total' => wc_format_decimal($shipping_total),
|
||||
'order_id' => $order->id
|
||||
) );
|
||||
$shipping->save();
|
||||
$order->add_item( $shipping );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->update_total($order);
|
||||
|
||||
$ids[] = array(
|
||||
'id' => (int)$order_record['id'],
|
||||
'externalId' => (int)$order_data->id
|
||||
);
|
||||
|
||||
|
||||
$this->retailcrm->ordersFixExternalIds($ids);
|
||||
}
|
||||
$this->addFuncsHook();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (empty($response)) {
|
||||
|
@ -240,6 +240,10 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
||||
array_walk($offer['params'], array($this, 'setOffersParams'), $e);
|
||||
}
|
||||
|
||||
if ($offer['dimension']) {
|
||||
$e->addChild('dimension', $offer['dimension']);
|
||||
}
|
||||
|
||||
unset($offers[$key]);
|
||||
}
|
||||
}
|
||||
@ -316,6 +320,14 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
||||
$status_args = array('publish');
|
||||
}
|
||||
|
||||
$attribute_taxonomies = wc_get_attribute_taxonomies();
|
||||
$product_attributes = array();
|
||||
|
||||
foreach ($attribute_taxonomies as $product_attribute) {
|
||||
$attribute_id = wc_attribute_taxonomy_name_by_id($product_attribute->attribute_id);
|
||||
$product_attributes[$attribute_id] = $product_attribute->attribute_label;
|
||||
}
|
||||
|
||||
$full_product_list = array();
|
||||
$offset = 0;
|
||||
$limit = 100;
|
||||
@ -373,25 +385,16 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
||||
|
||||
$attributes = (isset($attributes[0])) ? $attributes[0] : $attributes;
|
||||
|
||||
$params = array();
|
||||
|
||||
$weight = $product->get_weight();
|
||||
|
||||
if (!empty($weight)) {
|
||||
$params[] = array('code' => 'weight', 'name' => 'Weight', 'value' => $weight);
|
||||
}
|
||||
|
||||
$attrName = '';
|
||||
$params = array();
|
||||
|
||||
if (!empty($attributes)) {
|
||||
foreach ($attributes as $attribute_name => $attribute) {
|
||||
$id_product = $product->get_id();
|
||||
$arrAttributeValue = get_post_meta($id_product, 'attribute_'.$attribute_name);
|
||||
$attributeValue = end($arrAttributeValue);
|
||||
if ($attribute['is_visible'] == 1 && !empty($attribute['value'])) {
|
||||
$attributeValue = $product->get_attribute($attribute_name);
|
||||
if ($attribute['is_visible'] == 1 && !empty($attributeValue)) {
|
||||
$params[] = array(
|
||||
'code' => $attribute_name,
|
||||
'name' => $attribute['name'],
|
||||
'code' => $attribute_name,
|
||||
'name' => $product_attributes[$attribute_name],
|
||||
'value' => $attributeValue
|
||||
);
|
||||
$attrName .= (!empty($attributeValue)) ? ' - ' . $attributeValue : '';
|
||||
@ -399,25 +402,44 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
||||
}
|
||||
}
|
||||
|
||||
if ($product->get_sku() != '') {
|
||||
$params[] = array('code' => 'article', 'name' => 'Артикул', 'value' => $product->get_sku());
|
||||
}
|
||||
|
||||
$name = ($post->post_title == $product->get_title()) ?
|
||||
$post->post_title . $attrName :
|
||||
$post->post_title;
|
||||
|
||||
if ($product->get_weight() != '') {
|
||||
$params[] = array('code' => 'weight', 'name' => 'Вес', 'value' => $product->get_weight());
|
||||
}
|
||||
|
||||
if ($product->get_sku() != '') {
|
||||
$params[] = array('code' => 'article', 'name' => 'Артикул', 'value' => $product->get_sku());
|
||||
}
|
||||
|
||||
$dimension = '';
|
||||
|
||||
if ($product->get_length() != '') {
|
||||
$dimension = $product->get_length();
|
||||
}
|
||||
|
||||
if ($product->get_width() != '') {
|
||||
$dimension .= '/' . $product->get_width();
|
||||
}
|
||||
|
||||
if ($product->get_height() != '') {
|
||||
$dimension .= '/' . $product->get_height();
|
||||
}
|
||||
|
||||
$product_data = array(
|
||||
'id' => $product->get_id(),
|
||||
'productId' => ($this->get_parent_product($product) > 0) ? $parent->get_id() : $product->get_id(),
|
||||
'name' => $name,
|
||||
'productName' => ($this->get_parent_product($product) > 0) ? $parent->get_title() : $product->get_title(),
|
||||
'price' => $this->get_price_with_tax($product),
|
||||
'picture' => $image[0],
|
||||
'url' => ($this->get_parent_product($product) > 0) ? $parent->get_permalink() : $product->get_permalink(),
|
||||
'quantity' => is_null($product->get_stock_quantity()) ? 0 : $product->get_stock_quantity(),
|
||||
'categoryId' => $term_list
|
||||
);
|
||||
'id' => $product->get_id(),
|
||||
'productId' => ($this->get_parent_product($product) > 0) ? $parent->get_id() : $product->get_id(),
|
||||
'name' => $name,
|
||||
'productName' => ($this->get_parent_product($product) > 0) ? $parent->get_title() : $product->get_title(),
|
||||
'price' => $this->get_price_with_tax($product),
|
||||
'picture' => $image[0],
|
||||
'url' => ($this->get_parent_product($product) > 0) ? $parent->get_permalink() : $product->get_permalink(),
|
||||
'quantity' => is_null($product->get_stock_quantity()) ? 0 : $product->get_stock_quantity(),
|
||||
'categoryId' => $term_list,
|
||||
'dimension' => $dimension
|
||||
);
|
||||
|
||||
if (!empty($params)) {
|
||||
$product_data['params'] = $params;
|
||||
|
@ -289,7 +289,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
|
||||
$order_data['externalId'] = $order_data_info['id'];
|
||||
$order_data['number'] = $order->get_order_number();
|
||||
$order_data['createdAt'] = $order_data_info['date'];
|
||||
$order_data['createdAt'] = trim($order_data_info['date']);
|
||||
$order_data['customerComment'] = $order_data_info['customer_comment'];
|
||||
|
||||
if ( $order_data_info['discount_total'] ) {
|
||||
@ -309,7 +309,13 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
if ($order->get_items( 'shipping' )) {
|
||||
$shipping = end($order->get_items( 'shipping' ));
|
||||
$shipping_code = explode(':', $shipping['method_id']);
|
||||
$shipping_method = $shipping_code[0];
|
||||
|
||||
if (isset($this->retailcrm_settings[$shipping])) {
|
||||
$shipping_method = $shipping;
|
||||
} else {
|
||||
$shipping_method = $shipping_code[0];
|
||||
}
|
||||
|
||||
$shipping_cost = $shipping['cost'];
|
||||
|
||||
if (!empty($shipping_method) && !empty($this->retailcrm_settings[$shipping_method])) {
|
||||
@ -418,7 +424,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
|
||||
if ($order->get_date_paid()) {
|
||||
$pay_date = $order->get_date_paid();
|
||||
$payment['paidAt'] = $pay_date->date('Y-m-d H:i:s');
|
||||
$payment['paidAt'] = trim($pay_date->date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$order_data['payments'][] = $payment;
|
||||
@ -448,7 +454,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
|
||||
if ($order->get_date_paid()) {
|
||||
$pay_date = $order->get_date_paid();
|
||||
$payment['paidAt'] = $pay_date->date('Y-m-d H:i:s');
|
||||
$payment['paidAt'] = trim($pay_date->date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$this->retailcrm->ordersPaymentCreate($payment);
|
||||
|
44
woo-retailcrm/include/functions.php
Normal file
44
woo-retailcrm/include/functions.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
function get_wc_shipping_methods($enhanced = false) {
|
||||
$result = array();
|
||||
|
||||
$shippingZonesObj = new WC_Shipping_Zones();
|
||||
$shippingZones = $shippingZonesObj->get_zones();
|
||||
|
||||
foreach ($shippingZones as $code => $shippingZone) {
|
||||
foreach ($shippingZone['shipping_methods'] as $key => $shipping_method) {
|
||||
$shipping_methods = array(
|
||||
'id' => $shipping_method->id,
|
||||
'instance_id' => $shipping_method->instance_id,
|
||||
'title' => $shipping_method->title
|
||||
);
|
||||
|
||||
if ($enhanced) {
|
||||
$shipping_code = $shipping_method->id;
|
||||
} else {
|
||||
$shipping_code = $shipping_method->id . ':' . $shipping_method->instance_id;
|
||||
}
|
||||
|
||||
if (!isset($result[$shipping_code])) {
|
||||
$result[$shipping_code] = array(
|
||||
'name' => $shipping_method->method_title,
|
||||
'enabled' => $shipping_method->enabled,
|
||||
'description' => $shipping_method->method_description,
|
||||
'title' => $shipping_method->title
|
||||
);
|
||||
}
|
||||
|
||||
if ($enhanced) {
|
||||
$result[$shipping_method->id]['shipping_methods'][$shipping_method->id . ':' . $shipping_method->instance_id] = $shipping_methods;
|
||||
unset($shipping_methods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Version: 1.2.3
|
||||
* Version: 2.0.0
|
||||
* Plugin Name: WooCommerce RetailCRM
|
||||
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
|
||||
* Description: Integration plugin for WooCommerce & RetailCRM
|
||||
@ -32,6 +32,7 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
|
||||
public function init() {
|
||||
if ( class_exists( 'WC_Integration' ) ) {
|
||||
include_once 'include/class-wc-retailcrm-base.php';
|
||||
include_once 'include/functions.php';
|
||||
add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) );
|
||||
} else {
|
||||
// throw an admin error if you like
|
||||
@ -366,6 +367,24 @@ function ajax_upload() {
|
||||
<?php
|
||||
}
|
||||
|
||||
function ajax_generate_icml() {
|
||||
$ajax_url = admin_url('admin-ajax.php');
|
||||
?>
|
||||
<script type="text/javascript" >
|
||||
jQuery('#icml-retailcrm').bind('click', function() {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: '<?php echo $ajax_url; ?>?action=generate_icml',
|
||||
success: function (response) {
|
||||
alert('Каталог товаров сформирован');
|
||||
console.log('AJAX response : ',response);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
function update_order($order_id) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) {
|
||||
include_once( check_custom_orders() );
|
||||
@ -389,7 +408,9 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_
|
||||
add_action( 'init', 'register_icml_generation');
|
||||
add_action( 'init', 'register_retailcrm_history');
|
||||
add_action( 'wp_ajax_do_upload', 'upload_to_crm' );
|
||||
add_action( 'wp_ajax_generate_icml', 'generate_icml' );
|
||||
add_action('admin_print_footer_scripts', 'ajax_upload', 99);
|
||||
add_action('admin_print_footer_scripts', 'ajax_generate_icml', 99);
|
||||
add_action( 'woocommerce_created_customer', 'create_customer', 10, 1 );
|
||||
add_action( 'woocommerce_checkout_update_user_meta', 10, 2 );
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
* @since 1.2.1
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user