Weight and dimensions in icml (#41)
This commit is contained in:
parent
a06a7d5fba
commit
2aed9a81eb
@ -142,295 +142,303 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
|||||||
|
|
||||||
$this->removeFuncsHook();
|
$this->removeFuncsHook();
|
||||||
|
|
||||||
if ($record['field'] == 'status' && !empty($record['newValue']) && !empty($record['oldValue'])) {
|
try {
|
||||||
$newStatus = $record['newValue']['code'];
|
if ($record['field'] == 'status' && !empty($record['newValue']) && !empty($record['oldValue'])) {
|
||||||
if (!empty($options[$newStatus]) && !empty($record['order']['externalId'])) {
|
$newStatus = $record['newValue']['code'];
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
if (!empty($options[$newStatus]) && !empty($record['order']['externalId'])) {
|
||||||
$order->update_status($options[$newStatus]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif($record['field'] == 'order_product' && $record['newValue']) {
|
|
||||||
$product = wc_get_product($record['item']['offer']['externalId']);
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
|
||||||
$order->add_product($product, $record['item']['quantity']);
|
|
||||||
|
|
||||||
$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'];
|
|
||||||
} else {
|
|
||||||
$offer_id = $item['product_id'];
|
|
||||||
}
|
|
||||||
if ($offer_id == $record['item']['offer']['externalId']) {
|
|
||||||
wc_delete_order_item($order_item_id);
|
|
||||||
$order->add_product($product, $record['newValue']);
|
|
||||||
$this->update_total($order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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'];
|
|
||||||
} else {
|
|
||||||
$offer_id = $item['product_id'];
|
|
||||||
}
|
|
||||||
if ($offer_id == $record['item']['offer']['externalId']) {
|
|
||||||
wc_delete_order_item($order_item_id);
|
|
||||||
$this->update_total($order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'delivery_type') {
|
|
||||||
$newValue = $record['newValue']['code'];
|
|
||||||
|
|
||||||
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
|
||||||
if (isset($options[$newValue])) {
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
$items = $order->get_items('shipping');
|
$order->update_status($options[$newStatus]);
|
||||||
$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();
|
|
||||||
}
|
|
||||||
|
|
||||||
$updateOrder = new WC_Order((int)$order->get_id());
|
|
||||||
$this->update_total($updateOrder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'delivery_address.region') {
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
|
||||||
$order->set_shipping_state($record['newValue']);
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'delivery_address.city') {
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
|
||||||
$order->set_shipping_city($record['newValue']);
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'delivery_address.street') {
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
|
||||||
$order->set_shipping_address_1($record['newValue']);
|
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'delivery_address.building') {
|
|
||||||
$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'];
|
|
||||||
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
|
||||||
$payment = new WC_Payment_Gateways();
|
|
||||||
$payment_types = $payment->get_available_payment_gateways();
|
|
||||||
if (isset($payment_types[$options[$newValue]])) {
|
|
||||||
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
elseif ($record['field'] == 'payments') {
|
elseif($record['field'] == 'order_product' && $record['newValue']) {
|
||||||
$response = $this->retailcrm->ordersGet($record['order']['externalId']);
|
$product = wc_get_product($record['item']['offer']['externalId']);
|
||||||
|
|
||||||
if ($response->isSuccessful()) {
|
|
||||||
$order_data = $response['order'];
|
|
||||||
$order = new WC_Order($record['order']['externalId']);
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
$payment = new WC_Payment_Gateways();
|
$order->add_product($product, $record['item']['quantity']);
|
||||||
$payment_types = $payment->get_available_payment_gateways();
|
|
||||||
|
|
||||||
if (count($order_data['payments']) == 1) {
|
$this->update_total($order);
|
||||||
$paymentType = end($order_data['payments']);
|
}
|
||||||
if (isset($payment_types[$options[$paymentType['type']]])) {
|
|
||||||
$payment = $payment_types[$options[$paymentType['type']]];
|
|
||||||
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($order_data['payments'] as $payment_data) {
|
|
||||||
if (isset($payment_data['externalId'])) {
|
|
||||||
$paymentType = $payment_data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($paymentType)) {
|
elseif($record['field'] == 'order_product.quantity' && $record['newValue']) {
|
||||||
$paymentType = $order_data['payments'][0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($payment_types[$options[$paymentType['type']]])) {
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
$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'];
|
||||||
|
} else {
|
||||||
|
$offer_id = $item['product_id'];
|
||||||
|
}
|
||||||
|
if ($offer_id == $record['item']['offer']['externalId']) {
|
||||||
|
wc_delete_order_item($order_item_id);
|
||||||
|
$order->add_product($product, $record['newValue']);
|
||||||
|
$this->update_total($order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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'];
|
||||||
|
} else {
|
||||||
|
$offer_id = $item['product_id'];
|
||||||
|
}
|
||||||
|
if ($offer_id == $record['item']['offer']['externalId']) {
|
||||||
|
wc_delete_order_item($order_item_id);
|
||||||
|
$this->update_total($order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
elseif (isset($record['created']) &&
|
elseif ($record['field'] == 'delivery_type') {
|
||||||
$record['created'] == 1 &&
|
$newValue = $record['newValue']['code'];
|
||||||
!isset($record['order']['externalId'])) {
|
|
||||||
|
|
||||||
$args = array(
|
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
||||||
'status' => $options[$record['order']['status']],
|
if (isset($options[$newValue])) {
|
||||||
'customer_id' => isset($record['order']['customer']['externalId']) ?
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
$record['order']['customer']['externalId'] :
|
$items = $order->get_items('shipping');
|
||||||
null
|
$item_id = $this->getShippingItemId($items);
|
||||||
);
|
$crmOrder = $this->retailcrm->ordersGet($record['order']['externalId']);
|
||||||
|
$shipping_methods = get_wc_shipping_methods(true);
|
||||||
|
|
||||||
$order_record = $record['order'];
|
if (isset($shipping_methods[$options[$newValue]])) {
|
||||||
$order_data = wc_create_order($args);
|
$method_id = $options[$newValue];
|
||||||
$order = new WC_Order($order_data->id);
|
} else {
|
||||||
|
$method_id = explode(':', $options[$newValue]);
|
||||||
$address_shipping = array(
|
$method_id = $method_id[0];
|
||||||
'first_name' => $order_record['firstName'],
|
$shipping_method = $shipping_methods[$method_id]['shipping_methods'][$options[$newValue]];
|
||||||
'last_name' => isset($order_record['lastName']) ? $order_record['lastName'] : '',
|
|
||||||
'company' => '',
|
|
||||||
'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' => 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' => isset($order_record['customer']['lastName']) ? $order_record['customer']['lastName'] : '',
|
|
||||||
'company' => '',
|
|
||||||
'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' => 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']
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($this->retailcrm_settings['api_version'] == 'v5') {
|
|
||||||
if ($order_record['payments']) {
|
|
||||||
$payment = new WC_Payment_Gateways();
|
|
||||||
|
|
||||||
if (count($order_record['payments']) == 1) {
|
|
||||||
$payment_types = $payment->get_available_payment_gateways();
|
|
||||||
$paymentType = end($order_record['payments']);
|
|
||||||
|
|
||||||
if (isset($payment_types[$options[$paymentType['type']]])) {
|
|
||||||
$order->set_payment_method($payment_types[$options[$paymentType['type']]]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$updateOrder = new WC_Order((int)$order->get_id());
|
||||||
|
$this->update_total($updateOrder);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if ($order_record['paymentType']) {
|
|
||||||
|
elseif ($record['field'] == 'delivery_address.region') {
|
||||||
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
|
$order->set_shipping_state($record['newValue']);
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($record['field'] == 'delivery_address.city') {
|
||||||
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
|
$order->set_shipping_city($record['newValue']);
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($record['field'] == 'delivery_address.street') {
|
||||||
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
|
$order->set_shipping_address_1($record['newValue']);
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($record['field'] == 'delivery_address.building') {
|
||||||
|
$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'];
|
||||||
|
if (!empty($options[$newValue]) && !empty($record['order']['externalId'])) {
|
||||||
$payment = new WC_Payment_Gateways();
|
$payment = new WC_Payment_Gateways();
|
||||||
$payment_types = $payment->get_available_payment_gateways();
|
$payment_types = $payment->get_available_payment_gateways();
|
||||||
if (isset($payment_types[$options[$order_record['paymentType']]])) {
|
if (isset($payment_types[$options[$newValue]])) {
|
||||||
$order->set_payment_method($payment_types[$options[$order_record['paymentType']]]);
|
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$order->set_address($address_billing, 'billing');
|
elseif ($record['field'] == 'payments') {
|
||||||
$order->set_address($address_shipping, 'shipping');
|
$response = $this->retailcrm->ordersGet($record['order']['externalId']);
|
||||||
$product_data = isset($order_record['items']) ? $order_record['items'] : array();
|
|
||||||
|
|
||||||
if ($product_data) {
|
if ($response->isSuccessful()) {
|
||||||
foreach ($product_data as $product) {
|
$order_data = $response['order'];
|
||||||
$order->add_product(wc_get_product($product['offer']['externalId']), $product['quantity']);
|
$order = new WC_Order($record['order']['externalId']);
|
||||||
|
$payment = new WC_Payment_Gateways();
|
||||||
|
$payment_types = $payment->get_available_payment_gateways();
|
||||||
|
|
||||||
|
if (count($order_data['payments']) == 1) {
|
||||||
|
$paymentType = end($order_data['payments']);
|
||||||
|
if (isset($payment_types[$options[$paymentType['type']]])) {
|
||||||
|
$payment = $payment_types[$options[$paymentType['type']]];
|
||||||
|
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($order_data['payments'] as $payment_data) {
|
||||||
|
if (isset($payment_data['externalId'])) {
|
||||||
|
$paymentType = $payment_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($paymentType)) {
|
||||||
|
$paymentType = $order_data['payments'][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($payment_types[$options[$paymentType['type']]])) {
|
||||||
|
update_post_meta($order->get_id(), '_payment_method', $payment->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('delivery', $order_record)) {
|
elseif (isset($record['created']) &&
|
||||||
$deliveryCode = isset($order_record['delivery']['code']) ? $order_record['delivery']['code'] : false;
|
$record['created'] == 1 &&
|
||||||
|
!isset($record['order']['externalId'])) {
|
||||||
|
|
||||||
if ($deliveryCode && isset($options[$deliveryCode])) {
|
$args = array(
|
||||||
$delivery = explode(':', $options[$deliveryCode]);
|
'status' => $options[$record['order']['status']],
|
||||||
|
'customer_id' => isset($record['order']['customer']['externalId']) ?
|
||||||
|
$record['order']['customer']['externalId'] :
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
if (isset($delivery[1])) {
|
$order_record = $record['order'];
|
||||||
$instance_id = $delivery[1];
|
$order_data = wc_create_order($args);
|
||||||
|
$order = new WC_Order($order_data->id);
|
||||||
|
|
||||||
|
$address_shipping = array(
|
||||||
|
'first_name' => $order_record['firstName'],
|
||||||
|
'last_name' => isset($order_record['lastName']) ? $order_record['lastName'] : '',
|
||||||
|
'company' => '',
|
||||||
|
'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' => 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' => isset($order_record['customer']['lastName']) ? $order_record['customer']['lastName'] : '',
|
||||||
|
'company' => '',
|
||||||
|
'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' => 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']
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->retailcrm_settings['api_version'] == 'v5') {
|
||||||
|
if ($order_record['payments']) {
|
||||||
|
$payment = new WC_Payment_Gateways();
|
||||||
|
|
||||||
|
if (count($order_record['payments']) == 1) {
|
||||||
|
$payment_types = $payment->get_available_payment_gateways();
|
||||||
|
$paymentType = end($order_record['payments']);
|
||||||
|
|
||||||
|
if (isset($payment_types[$options[$paymentType['type']]])) {
|
||||||
|
$order->set_payment_method($payment_types[$options[$paymentType['type']]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
$wc_shipping = new WC_Shipping();
|
if ($order_record['paymentType']) {
|
||||||
$wc_shipping_types = $wc_shipping->get_shipping_methods();
|
$payment = new WC_Payment_Gateways();
|
||||||
|
$payment_types = $payment->get_available_payment_gateways();
|
||||||
foreach ($wc_shipping_types as $shipping_type) {
|
if (isset($payment_types[$options[$order_record['paymentType']]])) {
|
||||||
if ($shipping_type->id == $options[$deliveryCode]) {
|
$order->set_payment_method($payment_types[$options[$order_record['paymentType']]]);
|
||||||
$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', '<' )) {
|
$order->set_address($address_billing, 'billing');
|
||||||
$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->set_address($address_shipping, 'shipping');
|
||||||
$order->add_shipping($shipping_rate);
|
$product_data = isset($order_record['items']) ? $order_record['items'] : array();
|
||||||
} else {
|
|
||||||
$shipping = new WC_Order_Item_Shipping();
|
if ($product_data) {
|
||||||
$shipping->set_props( array(
|
foreach ($product_data as $product) {
|
||||||
'method_title' => $shipping_method_title,
|
$order->add_product(wc_get_product($product['offer']['externalId']), $product['quantity']);
|
||||||
'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);
|
||||||
}
|
}
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$logger = new WC_Logger();
|
||||||
|
$logger->add('retailcrm', sprintf("[%s] - %s", $exception->getMessage(), 'Exception in file - ' . $exception->getFile() . ' on line ' . $exception->getLine()));
|
||||||
|
|
||||||
$this->update_total($order);
|
continue;
|
||||||
|
|
||||||
$ids[] = array(
|
|
||||||
'id' => (int)$order_record['id'],
|
|
||||||
'externalId' => (int)$order_data->id
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->retailcrm->ordersFixExternalIds($ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addFuncsHook();
|
$this->addFuncsHook();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,10 +240,14 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
array_walk($offer['params'], array($this, 'setOffersParams'), $e);
|
array_walk($offer['params'], array($this, 'setOffersParams'), $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($offer['dimension']) {
|
if (array_key_exists('dimension', $offer)) {
|
||||||
$e->addChild('dimension', $offer['dimension']);
|
$e->addChild('dimension', $offer['dimension']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('weight', $offer)) {
|
||||||
|
$e->addChild('weight', $offer['weight']);
|
||||||
|
}
|
||||||
|
|
||||||
unset($offers[$key]);
|
unset($offers[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -365,7 +369,9 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($product->get_type() == 'variable') continue;
|
if ($product->get_type() == 'variable') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($product->get_type() == 'simple' || $parent && $parent->get_type() == 'variable') {
|
if ($product->get_type() == 'simple' || $parent && $parent->get_type() == 'variable') {
|
||||||
if ($this->get_parent_product($product) > 0) {
|
if ($this->get_parent_product($product) > 0) {
|
||||||
@ -406,10 +412,6 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
$post->post_title . $attrName :
|
$post->post_title . $attrName :
|
||||||
$post->post_title;
|
$post->post_title;
|
||||||
|
|
||||||
if ($product->get_weight() != '') {
|
|
||||||
$params[] = array('code' => 'weight', 'name' => 'Вес', 'value' => $product->get_weight());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($product->get_sku() != '') {
|
if ($product->get_sku() != '') {
|
||||||
$params[] = array('code' => 'article', 'name' => 'Артикул', 'value' => $product->get_sku());
|
$params[] = array('code' => 'article', 'name' => 'Артикул', 'value' => $product->get_sku());
|
||||||
}
|
}
|
||||||
@ -417,15 +419,21 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
$dimension = '';
|
$dimension = '';
|
||||||
|
|
||||||
if ($product->get_length() != '') {
|
if ($product->get_length() != '') {
|
||||||
$dimension = $product->get_length();
|
$dimension = wc_get_dimension($product->get_length(), 'cm');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($product->get_width() != '') {
|
if ($product->get_width() != '') {
|
||||||
$dimension .= '/' . $product->get_width();
|
$dimension .= '/' . wc_get_dimension($product->get_width(), 'cm');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($product->get_height() != '') {
|
if ($product->get_height() != '') {
|
||||||
$dimension .= '/' . $product->get_height();
|
$dimension .= '/' . wc_get_dimension($product->get_height(), 'cm');
|
||||||
|
}
|
||||||
|
|
||||||
|
$weight = '';
|
||||||
|
|
||||||
|
if ($product->get_weight() != '') {
|
||||||
|
$weight = wc_get_weight($product->get_weight(), 'kg');
|
||||||
}
|
}
|
||||||
|
|
||||||
$product_data = array(
|
$product_data = array(
|
||||||
@ -438,7 +446,8 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
'url' => ($this->get_parent_product($product) > 0) ? $parent->get_permalink() : $product->get_permalink(),
|
'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(),
|
'quantity' => is_null($product->get_stock_quantity()) ? 0 : $product->get_stock_quantity(),
|
||||||
'categoryId' => $term_list,
|
'categoryId' => $term_list,
|
||||||
'dimension' => $dimension
|
'dimension' => $dimension,
|
||||||
|
'weight' => $weight
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($params)) {
|
if (!empty($params)) {
|
||||||
@ -501,6 +510,15 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
return $categories;
|
return $categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get product id
|
||||||
|
*
|
||||||
|
* @global object $woocommerce
|
||||||
|
*
|
||||||
|
* @param object $product
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
private function get_parent_product($product) {
|
private function get_parent_product($product) {
|
||||||
global $woocommerce;
|
global $woocommerce;
|
||||||
if ( version_compare( $woocommerce->version, '3.0', '<' ) ) {
|
if ( version_compare( $woocommerce->version, '3.0', '<' ) ) {
|
||||||
@ -510,6 +528,15 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get product price
|
||||||
|
*
|
||||||
|
* @global object $woocommerce
|
||||||
|
*
|
||||||
|
* @param object $product
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
private function get_price_with_tax($product) {
|
private function get_price_with_tax($product) {
|
||||||
global $woocommerce;
|
global $woocommerce;
|
||||||
if ( version_compare( $woocommerce->version, '3.0', '<' ) ) {
|
if ( version_compare( $woocommerce->version, '3.0', '<' ) ) {
|
||||||
@ -519,6 +546,11 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get product statuses
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function checkPostStatuses() {
|
private function checkPostStatuses() {
|
||||||
$options = get_option( 'woocommerce_integration-retailcrm_settings' );
|
$options = get_option( 'woocommerce_integration-retailcrm_settings' );
|
||||||
$status_args = array();
|
$status_args = array();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Version: 2.0.0
|
* Version: 2.0.1
|
||||||
* Plugin Name: WooCommerce RetailCRM
|
* Plugin Name: WooCommerce RetailCRM
|
||||||
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
|
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
|
||||||
* Description: Integration plugin for WooCommerce & RetailCRM
|
* Description: Integration plugin for WooCommerce & RetailCRM
|
||||||
|
@ -15,18 +15,18 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||||
* @since 2.0.0
|
* @since 2.0.1
|
||||||
*
|
*
|
||||||
* @package RetailCRM
|
* @package RetailCRM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit; // Exit if accessed directly
|
exit; // Exit if accessed directly
|
||||||
}
|
}
|
||||||
|
|
||||||
// If uninstall not called from WordPress, then exit.
|
// If uninstall not called from WordPress, then exit.
|
||||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user