Fix bug with changing order status by history
This commit is contained in:
parent
54992c9904
commit
554a3f420f
@ -368,7 +368,7 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($options[$order['status']])) {
|
||||
if (isset($order['status']) && isset($options[$order['status']])) {
|
||||
$wcOrder->update_status($options[$order['status']]);
|
||||
}
|
||||
|
||||
|
@ -48,10 +48,23 @@ class WC_Retailcrm_History_Assembler
|
||||
unset($change['order']['contragent']);
|
||||
}
|
||||
|
||||
$orderMainInfo = WC_Retailcrm_Plugin::clearArray(
|
||||
[
|
||||
'id' => $change['order']['id'] ?? '',
|
||||
'externalId' => $change['order']['externalId'] ?? '',
|
||||
'managerId' => $change['order']['managerId'] ?? '',
|
||||
'site' => $change['order']['site'] ?? '',
|
||||
]
|
||||
);
|
||||
|
||||
if (!empty($orders) && isset($orders[$change['order']['id']])) {
|
||||
$orders[$change['order']['id']] = array_merge($orders[$change['order']['id']], $change['order']);
|
||||
$orders[$change['order']['id']] = array_merge($orders[$change['order']['id']], $orderMainInfo);
|
||||
} else {
|
||||
$orders[$change['order']['id']] = $change['order'];
|
||||
$orders[$change['order']['id']] = !empty($change['created']) ? $change['order'] : $orderMainInfo;
|
||||
}
|
||||
|
||||
if ($change['field'] === 'status') {
|
||||
$orders[$change['order']['id']]['status'] = $change['order']['status'];
|
||||
}
|
||||
|
||||
if (isset($change['item']) && $change['item']) {
|
||||
@ -74,16 +87,14 @@ class WC_Retailcrm_History_Assembler
|
||||
}
|
||||
}
|
||||
|
||||
if ($change['field'] == 'payments' && isset($change['payment'])) {
|
||||
if (isset($change['payment']) && $change['field'] == 'payments') {
|
||||
if ($change['newValue'] !== null) {
|
||||
$orders[$change['order']['id']]['payments'][] = self::newValue($change['payment']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($change['field'] == 'payments.status') {
|
||||
if ($change['newValue'] !== null) {
|
||||
if ($change['field'] == 'payments.status' && $change['newValue'] !== null) {
|
||||
$orders[$change['order']['id']]['payments']['id']['status'] = self::newValue($change['newValue']);
|
||||
}
|
||||
} else {
|
||||
if (isset($fields['delivery'][$change['field']]) && $fields['delivery'][$change['field']] == 'service') {
|
||||
$orders[$change['order']['id']]['delivery']['service']['code'] = self::newValue($change['newValue']);
|
||||
|
@ -460,14 +460,14 @@ class DataHistoryRetailCrm
|
||||
'offer' => [
|
||||
'id' => 2,
|
||||
'externalId' => $product_add_id,
|
||||
'xmlId' => 'xmlId'
|
||||
]
|
||||
],
|
||||
'order' => [
|
||||
'id' => 2,
|
||||
'externalId' => $order_id,
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status1'
|
||||
'status' => 'status4',
|
||||
],
|
||||
'item' => [
|
||||
'id' => 2,
|
||||
@ -484,7 +484,6 @@ class DataHistoryRetailCrm
|
||||
'offer' => [
|
||||
'id' => 2,
|
||||
'externalId' => $product_add_id,
|
||||
'xmlId' => 'xmlId',
|
||||
'name' => 'Test name 2'
|
||||
],
|
||||
'properties' => [],
|
||||
@ -535,20 +534,17 @@ class DataHistoryRetailCrm
|
||||
'user' => [
|
||||
'id' => 1
|
||||
],
|
||||
'field' => 'managerComment',
|
||||
'oldValue' => [
|
||||
'code' => ''
|
||||
],
|
||||
'newValue' => [
|
||||
'code' => 'managerComment'
|
||||
],
|
||||
'field' => 'manager_comment',
|
||||
'oldValue' => '',
|
||||
'newValue' => 'managerCommentTest'
|
||||
,
|
||||
'order' => [
|
||||
'id' => 2,
|
||||
'externalId' => $order_id,
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status4',
|
||||
'managerComment' => 'managerComment'
|
||||
'managerComment' => 'managerCommentTest'
|
||||
]
|
||||
],
|
||||
[
|
||||
@ -558,21 +554,17 @@ class DataHistoryRetailCrm
|
||||
'user' => [
|
||||
'id' => 1
|
||||
],
|
||||
'field' => 'customerComment',
|
||||
'oldValue' => [
|
||||
'code' => ''
|
||||
],
|
||||
'newValue' => [
|
||||
'code' => 'customerComment'
|
||||
],
|
||||
'field' => 'customer_comment',
|
||||
'oldValue' => '',
|
||||
'newValue' => 'customerCommentTest',
|
||||
'order' => [
|
||||
'id' => 2,
|
||||
'externalId' => $order_id,
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status4',
|
||||
'managerComment' => 'managerComment',
|
||||
'customerComment' => 'customerComment'
|
||||
'managerComment' => 'managerCommentTest',
|
||||
'customerComment' => 'customerCommentTest'
|
||||
]
|
||||
],
|
||||
[
|
||||
@ -595,8 +587,8 @@ class DataHistoryRetailCrm
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status4',
|
||||
'managerComment' => 'managerComment',
|
||||
'customerComment' => 'customerComment',
|
||||
'managerComment' => 'managerCommentTest',
|
||||
'customerComment' => 'customerCommentTest',
|
||||
'phone' => '12345678'
|
||||
]
|
||||
],
|
||||
@ -620,8 +612,8 @@ class DataHistoryRetailCrm
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status4',
|
||||
'managerComment' => 'managerComment',
|
||||
'customerComment' => 'customerComment',
|
||||
'managerComment' => 'managerCommentTest',
|
||||
'customerComment' => 'customerCommentTest',
|
||||
'phone' => '12345678',
|
||||
'email' => 'tester001@example.com'
|
||||
]
|
||||
@ -635,31 +627,31 @@ class DataHistoryRetailCrm
|
||||
]
|
||||
];
|
||||
|
||||
$payment_v5 = array(
|
||||
$payment_v5 = [
|
||||
'id' => 4,
|
||||
'createdAt' => '2018-01-01 00:03:00',
|
||||
'source' => 'user',
|
||||
'user' => array(
|
||||
'user' => [
|
||||
'id' => 1
|
||||
),
|
||||
],
|
||||
'field' => 'payments',
|
||||
'oldValue' => null,
|
||||
'newValue' => array(
|
||||
'newValue' => [
|
||||
'code' => 'payment2'
|
||||
),
|
||||
'order' => array(
|
||||
],
|
||||
'order' => [
|
||||
'id' => 2,
|
||||
'externalId' => $order_id,
|
||||
'managerId' => 6,
|
||||
'site' => 'test-com',
|
||||
'status' => 'status4'
|
||||
),
|
||||
'payment' => array(
|
||||
],
|
||||
'payment' => [
|
||||
'id' => 1,
|
||||
'type' => 'payment2',
|
||||
'amount' => 100
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
array_push($history['history'], $payment_v5);
|
||||
|
||||
|
@ -103,8 +103,10 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$wcOrder = end($orders);
|
||||
$options = get_option(\WC_Retailcrm_Base::$option_key);
|
||||
|
||||
if ($wcOrder instanceof WC_Order) {
|
||||
$this->assertEquals('status1', $options[$wcOrder->get_status()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_history_order_create_deleted_items()
|
||||
{
|
||||
@ -216,7 +218,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
|
||||
$this->assertEquals('status4', $options[$order_updated->get_status()]);
|
||||
$this->assertEquals('payment2', $options[$order_updated->get_payment_method()]);
|
||||
$this->assertEquals('customerComment', $order_updated->get_customer_note());
|
||||
$this->assertEquals('customerCommentTest', $order_updated->get_customer_note());
|
||||
$this->assertEquals(12345678, $order_updated->get_billing_phone());
|
||||
$this->assertEquals('tester001@example.com', $order_updated->get_billing_email());
|
||||
|
||||
@ -225,11 +227,9 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
|
||||
foreach ($notes as $note) {
|
||||
if ($note->content === 'managerComment') {
|
||||
$managerComment = $note->content;
|
||||
$this->assertEquals('managerCommentTest', $note->content);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals('managerComment', $managerComment);
|
||||
}
|
||||
|
||||
public function test_history_order_update_empty_order()
|
||||
@ -328,7 +328,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
$orders = wc_get_orders(array('numberposts' => -1));
|
||||
$orders = wc_get_orders(['numberposts' => -1]);
|
||||
$order_added = end($orders);
|
||||
|
||||
if (!$order_added) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user