1
0
mirror of synced 2025-02-22 18:03:14 +03:00

Поддержка передачи одинаковых товаров в заказе как разных товарных позиций

This commit is contained in:
gorokh 2019-10-07 17:36:31 +03:00
parent af86ba2821
commit 606de96a91
6 changed files with 100 additions and 7 deletions

View File

@ -1,3 +1,6 @@
## 2019-10-07 3.5.4
* Добавлена возможность обработки одинаковых товарных позиций
## 2019-04-22 3.5.2 ## 2019-04-22 3.5.2
* Исправлен баг с выгрузкой заказов в retailCRM * Исправлен баг с выгрузкой заказов в retailCRM
* Исправлена ошибка переводов * Исправлена ошибка переводов

View File

@ -1 +1 @@
3.5.3 3.5.4

View File

@ -22,6 +22,9 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
protected $order_methods = array(); protected $order_methods = array();
protected $bind_field = 'externalId'; protected $bind_field = 'externalId';
/** @var WC_Retailcrm_Order_Item */
protected $order_item;
/** /**
* WC_Retailcrm_History constructor. * WC_Retailcrm_History constructor.
* @param $retailcrm (default = false) * @param $retailcrm (default = false)
@ -329,6 +332,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
if (array_key_exists('items', $order)) { if (array_key_exists('items', $order)) {
foreach ($order['items'] as $item) { foreach ($order['items'] as $item) {
if (!isset($item['offer'][$this->bind_field])) { if (!isset($item['offer'][$this->bind_field])) {
continue; continue;
} }
@ -348,10 +352,23 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$offer_id = $order_item['product_id']; $offer_id = $order_item['product_id'];
} }
if ($offer_id == $item['offer'][$this->bind_field]) { if (isset($item['externalIds'])) {
$this->deleteOrUpdateOrderItem($item, $order_item, $order_item_id); foreach ($item['externalIds'] as $externalId) {
if ($externalId['code'] == 'woocomerce') {
$itemExternalId = explode('_', $externalId['value']);
} }
} }
} else {
$itemExternalId = explode('_', $item['externalId']);
}
if ($offer_id == $item['offer'][$this->bind_field]
&& $itemExternalId[1] == $order_item->get_id()
) {
$this->deleteOrUpdateOrderItem($item, $order_item, $itemExternalId[1]);
}
}
} }
} }
} }
@ -424,6 +441,19 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$wc_order->save(); $wc_order->save();
$checkNewItem = false;
foreach ($order['items'] as $item) {
if (!empty($item['externalIds'])) {
continue;
} else {
$checkNewItem = true;
}
}
if ($checkNewItem == true) {
$this->editOrder($this->retailcrm_settings, $wc_order, $order);
}
return $wc_order->get_id(); return $wc_order->get_id();
} }
@ -440,11 +470,16 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
if (isset($item['quantity']) && $item['quantity']) { if (isset($item['quantity']) && $item['quantity']) {
$order_item->set_quantity($item['quantity']); $order_item->set_quantity($item['quantity']);
$product = retailcrm_get_wc_product($item['offer'][$this->bind_field], $this->retailcrm_settings); $product = retailcrm_get_wc_product($item['offer'][$this->bind_field], $this->retailcrm_settings);
$order_item->set_total($product->get_price() * $item['quantity']);
$order_item->set_subtotal($product->get_price()); $order_item->set_subtotal($product->get_price());
$data_store = $order_item->get_data_store(); $data_store = $order_item->get_data_store();
$data_store->update($order_item); $data_store->update($order_item);
} }
if (isset($item['summ']) && $item['summ']) {
$order_item->set_total($item['summ']);
$data_store = $order_item->get_data_store();
$data_store->update($order_item);
}
} }
} }
@ -537,8 +572,13 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
if ($product_data) { if ($product_data) {
foreach ($product_data as $product) { foreach ($product_data as $product) {
$item = retailcrm_get_wc_product($product['offer'][$this->bind_field], $this->retailcrm_settings);
if ($product['discountTotal'] > 0) {
$item->set_price($product['initialPrice'] - $product['discountTotal']);
}
$wc_order->add_product( $wc_order->add_product(
retailcrm_get_wc_product($product['offer'][$this->bind_field], $this->retailcrm_settings), $item,
$product['quantity'] $product['quantity']
); );
} }
@ -584,11 +624,53 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$wc_order->save(); $wc_order->save();
$this->editOrder($this->retailcrm_settings, $wc_order, $order, 'update');
$this->retailcrm->ordersFixExternalIds($ids); $this->retailcrm->ordersFixExternalIds($ids);
return $wc_order->get_id(); return $wc_order->get_id();
} }
/**
* @param $settings
* @param $wc_order
* @param $order
* @param string $event
*/
protected function editOrder($settings, $wc_order, $order, $event = 'create')
{
$order_items = [];
$retailcrmOrderItem = new WC_Retailcrm_Order_Item($settings);
foreach ($wc_order->get_items() as $key => $item) {
$order_items[$key] = $retailcrmOrderItem->build($item)->get_data();
$retailcrmOrderItem->reset_data();
if ($event == 'update') {
foreach ($order['items'] as $itemCrm) {
if (isset($itemCrm['externalIds']) && !empty($itemCrm['externalIds'])) {
foreach ($itemCrm['externalIds'] as $externalId) {
if ($externalId['code'] == 'woocomerce') {
$test = explode('_', $externalId['value']);
}
}
if ($order_items[$test[1]]) {
unset($order_items[$test[1]]);
}
}
}
}
}
if (!empty($order_items)) {
$orderEdit = [
'id' => $order['id'],
'items' => $order_items,
];
$this->retailcrm->ordersEdit($orderEdit, 'id');
}
}
/** /**
* @param array $orderHistory * @param array $orderHistory
* *

View File

@ -55,6 +55,14 @@ class WC_Retailcrm_Order_Item extends WC_Retailcrm_Abstracts_Data
$data['initialPrice'] = (float)$price; $data['initialPrice'] = (float)$price;
$data['quantity'] = (double)$item['qty']; $data['quantity'] = (double)$item['qty'];
$itemId = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'];
$data['externalIds'] = array(
array(
'code' =>'woocomerce',
'value' => $itemId . '_' . $item->get_id(),
)
);
$this->set_data_fields($data); $this->set_data_fields($data);
$this->set_offer($item); $this->set_offer($item);

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Version: 3.5.2 * Version: 3.5.4
* WC requires at least: 3.0 * WC requires at least: 3.0
* WC tested up to: 3.5.5 * WC tested up to: 3.5.5
* Plugin Name: WooCommerce RetailCRM * Plugin Name: WooCommerce RetailCRM

View File

@ -15,7 +15,7 @@
* *
* *
* @link https://wordpress.org/plugins/woo-retailcrm/ * @link https://wordpress.org/plugins/woo-retailcrm/
* @version 3.5.2 * @version 3.5.4
* *
* @package RetailCRM * @package RetailCRM
*/ */