1
0
mirror of synced 2025-01-19 01:11:42 +03:00

Fix bug with changing order status by history

This commit is contained in:
Dima Uryvskiy 2022-04-12 15:55:09 +03:00 committed by GitHub
parent 54992c9904
commit 554a3f420f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 61 deletions

View File

@ -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']]);
}

View File

@ -44,14 +44,27 @@ class WC_Retailcrm_History_Assembler
if (isset($change['order']['contragent']['contragentType']) && $change['order']['contragent']['contragentType']) {
$change['order']['contragentType'] = $change['order']['contragent']['contragentType'];
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) {
$orders[$change['order']['id']]['payments']['id']['status'] = self::newValue($change['newValue']);
}
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']);
@ -155,9 +166,9 @@ class WC_Retailcrm_History_Assembler
&& $fields['customer'][$change['field']]
) {
$customers[
$change['customer']['id']
$change['customer']['id']
][
$fields['customer'][$change['field']]
$fields['customer'][$change['field']]
] = self::newValue($change['newValue']);
}
@ -170,11 +181,11 @@ class WC_Retailcrm_History_Assembler
}
$customers[
$change['customer']['id']
$change['customer']['id']
][
'address'
'address'
][
$fieldsAddress['customerAddress'][$change['field']]
$fieldsAddress['customerAddress'][$change['field']]
] = self::newValue($change['newValue']);
}
@ -241,9 +252,9 @@ class WC_Retailcrm_History_Assembler
&& $fields['customerCorporate'][$change['field']]
) {
$customersCorporate[
$change['customer']['id']
$change['customer']['id']
][
$fields['customerCorporate'][$change['field']]
$fields['customerCorporate'][$change['field']]
] = self::newValue($change['newValue']);
}
@ -253,17 +264,17 @@ class WC_Retailcrm_History_Assembler
}
$customersCorporate[
$change['customer']['id']
$change['customer']['id']
][
'address'
'address'
][
$fields['customerAddress'][$change['field']]
$fields['customerAddress'][$change['field']]
] = self::newValue($change['newValue']);
}
if ($change['field'] == 'address') {
$customersCorporate[
$change['customer']['id']
$change['customer']['id']
]['address'] = array_merge($change['address'], self::newValue($change['newValue']));
}
}
@ -415,4 +426,4 @@ class WC_Retailcrm_History_Assembler
return $history;
}
}
}

View File

@ -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);

View File

@ -103,7 +103,9 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$wcOrder = end($orders);
$options = get_option(\WC_Retailcrm_Base::$option_key);
$this->assertEquals('status1', $options[$wcOrder->get_status()]);
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) {