Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edavydova/e50405a834fbb680cd32ab66fd2d4970 to your computer and use it in GitHub Desktop.
Save edavydova/e50405a834fbb680cd32ab66fd2d4970 to your computer and use it in GitHub Desktop.
diff --git a/app/addons/rus_exim_1c/Tygh/Commerceml/RusEximCommerceml.php b/app/addons/rus_exim_1c/Tygh/Commerceml/RusEximCommerceml.php
index d099e05..43df60f 100644
--- a/app/addons/rus_exim_1c/Tygh/Commerceml/RusEximCommerceml.php
+++ b/app/addons/rus_exim_1c/Tygh/Commerceml/RusEximCommerceml.php
@@ -3130,7 +3130,7 @@ class RusEximCommerceml
return $xml;
}
- public function importFileOrders($xml, $lang_code)
+ public function importFileOrders($xml)
{
$cml = $this->cml;
if (isset($xml->{$cml['document']})) {
@@ -3148,23 +3148,33 @@ class RusEximCommerceml
}
foreach ($orders_data as $order_data) {
- $import_id = strval($order_data->{$cml['id']});
- $order_id = strval($order_data->{$cml['number']});
+ $external_order_id = strval($order_data->{$cml['id']});
+ $external_order_number = strval($order_data->{$cml['number']});
//Check the database for an order with the specified ID exported from the accounting system
- if ($import_id && $import_id === (string) (int) $import_id) {
- $_order_id = $this->db->getField("SELECT order_id FROM ?:orders WHERE order_id = ?i", $import_id);
+ if ($external_order_id && $external_order_id === (string) (int) $external_order_id) {
+ $old_order_data = fn_get_order_info($external_order_id);
}
- if (isset($_order_id) && !empty($_order_id)) {
- $order_id = $_order_id;
- unset($_order_id);
+
+ //If order was not found by external_id try to find it by external order number
+ if (empty($old_order_data['order_id'])) {
+ $old_order_data = fn_get_order_info($external_order_number);
+ }
+
+ if (empty($old_order_data['order_id'])) {
+ continue;
}
foreach ($order_data->{$cml['value_fields']}->{$cml['value_field']} as $data_field) {
- if (!empty($order_id) && ($data_field->{$cml['name']} == $cml['status_order']) && (!empty($statuses[strval($data_field->{$cml['value']})]))) {
- $this->db->query("UPDATE ?:orders SET status = ?s WHERE order_id = ?i", $statuses[strval($data_field->{$cml['value']})]['status'], $order_id);
+ if ($data_field->{$cml['name']} == $cml['status_order'] && !empty($statuses[strval($data_field->{$cml['value']})])) {
+ $status_to = strval($data_field->{$cml['value']});
}
}
+
+ if (!empty($status_to) && $old_order_data['status'] != $statuses[$status_to]['status']) {
+ fn_change_order_status($old_order_data['order_id'], $statuses[$status_to]['status']);
+ }
+ unset($status_to);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment