diff --git a/retailcrm/job/export.php b/retailcrm/job/export.php index cb23a96..15372df 100644 --- a/retailcrm/job/export.php +++ b/retailcrm/job/export.php @@ -3,7 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL - * @version 2.1.1 + * @version 2.1.3 * @link https://retailcrm.ru * */ diff --git a/retailcrm/job/icml.php b/retailcrm/job/icml.php index 65cf296..014e60d 100644 --- a/retailcrm/job/icml.php +++ b/retailcrm/job/icml.php @@ -3,7 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL - * @version 2.1.1 + * @version 2.1.3 * @link https://retailcrm.ru * */ diff --git a/retailcrm/job/missing.php b/retailcrm/job/missing.php index 5638dc2..675209f 100644 --- a/retailcrm/job/missing.php +++ b/retailcrm/job/missing.php @@ -3,7 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL - * @version 2.1.1 + * @version 2.1.3 * @link https://retailcrm.ru * */ diff --git a/retailcrm/job/sync.php b/retailcrm/job/sync.php index 1ca4a84..9751d09 100644 --- a/retailcrm/job/sync.php +++ b/retailcrm/job/sync.php @@ -3,7 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL - * @version 2.1.1 + * @version 2.1.3 * @link https://retailcrm.ru * */ @@ -103,6 +103,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { if (!isset($paymentId) || !$paymentId) { $paymentId = $paymentDefault; } + if (!$paymentType) { if ($paymentDefault) { if (Module::getInstanceByName($paymentDefault)) { @@ -116,6 +117,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { 3, _PS_ROOT_DIR_ . '/retailcrm.log' ); + continue; } } @@ -135,7 +137,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { $customer = new Customer(); if (!empty($order['customer']['email'])) { - $customer->getByEmail($order['customer']['email']); + $customer->getByEmail($order['customer']['email'], null, false); } if (!array_key_exists('externalId', $order['customer'])) { @@ -408,6 +410,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { /* * check payment type */ + if (!empty($order['paymentType']) && $apiVersion != 5) { $ptype = $order['paymentType']; @@ -445,6 +448,36 @@ if ($history->isSuccessful() && count($history->history) > 0) { WHERE `id_order` = ' . (int)$order['externalId']); + Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'order_payment` + (`payment_method`, `order_reference` , `amount`, `date_add`) + VALUES + (\'' . $payType . '\', + \'' . $orderToUpdate->reference . '\', + \'' . $payment['amount'] . '\', + \'' . $payment['paidAt'] . '\')'); + } + } + } + } + } elseif (!empty($order['payments']) && $apiVersion == 5) { + if ($order['payments']) { + foreach ($order['payments'] as $payment) { + if (!isset($payment['externalId']) && $payment['status'] == 'paid') { + $ptype = $payment['type']; + $ptypes = $references->getSystemPaymentModules(); + if ($payments[$ptype] != null) { + foreach ($ptypes as $pay) { + if ($pay['code'] == $payments[$ptype]) { + $payType = $pay['name']; + } + } + $paymentType = Module::getModuleName($payments[$ptype]); + Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'orders` + SET + `payment` = \'' . ($paymentType != null ? $paymentType : $payments[$ptype]). '\' + WHERE + `id_order` = ' . (int)$order['externalId']); + Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'order_payment` (`payment_method`, `order_reference` , `amount`, `date_add`) VALUES @@ -503,6 +536,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { if (isset($item['discount']) || isset($item['discountPercent']) || isset($item['discountTotal'])) { + $product = new Product((int) $product_id, false, $default_lang); $tax = new TaxCore($product->id_tax_rules_group); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 7f90b92..05203e4 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -25,7 +25,7 @@ class RetailCRM extends Module { $this->name = 'retailcrm'; $this->tab = 'export'; - $this->version = '2.1.2'; + $this->version = '2.1.3'; $this->author = 'Retail Driver LCC'; $this->displayName = $this->l('RetailCRM'); $this->description = $this->l('Integration module for RetailCRM'); @@ -40,7 +40,7 @@ class RetailCRM extends Module $this->psVersion = Tools::substr(_PS_VERSION_, 0, 3); $this->log = _PS_ROOT_DIR_ . '/retailcrm.log'; $this->module_key = '149c765c6cddcf35e1f13ea6c71e9fa5'; - + if ($this->psVersion == '1.6') { $this->bootstrap = true; $this->use_new_hooks = false; @@ -129,7 +129,7 @@ class RetailCRM extends Module $this->api = new RetailcrmProxy($address, $token, $this->log, $version); $this->reference = new RetailcrmReferences($this->api); } - + $output .= $this->displayConfirmation( $this->l('Timezone settings must be identical to both of your crm and shop') . " $address/admin/settings#t-main" @@ -156,7 +156,9 @@ class RetailCRM extends Module 'name' => 'v5' ) ); + $fields_form = array(); + /* * Network connection form */ @@ -290,7 +292,7 @@ class RetailCRM extends Module $helper->fields_value['RETAILCRM_API_TOKEN'] = Configuration::get('RETAILCRM_API_TOKEN'); $helper->fields_value['RETAILCRM_API_VERSION'] = Configuration::get('RETAILCRM_API_VERSION'); $helper->fields_value['RETAILCRM_STATUS_EXPORT'] = Configuration::get('RETAILCRM_STATUS_EXPORT'); - + $deliverySettings = Configuration::get('RETAILCRM_API_DELIVERY'); if (isset($deliverySettings) && $deliverySettings != '') { $deliveryTypes = json_decode($deliverySettings); @@ -503,6 +505,7 @@ class RetailCRM extends Module $arProp = array(); $count = 0; $arAttr = explode(",", $item['attributes']); + foreach ($arAttr as $valAttr) { $arItem = explode(":", $valAttr); $arProp[$count]['name'] = trim($arItem[0]); @@ -645,6 +648,7 @@ class RetailCRM extends Module private function validateCrmAddress($address) { if (preg_match("/https:\/\/(.*).retailcrm.ru/", $address) === 1) { + return true; } diff --git a/retailcrm/translations/ru.php b/retailcrm/translations/ru.php index d3e5602..4bb08b2 100644 --- a/retailcrm/translations/ru.php +++ b/retailcrm/translations/ru.php @@ -52,4 +52,4 @@ $_MODULE['<{retailcrm}prestashop>retailcrm_f0e1fc6f97d36cb80f29196e2662ffde'] = $_MODULE['<{retailcrm}prestashop>retailcrm_7a1920d61156abc05a60135aefe8bc67'] = 'По умолчанию'; $_MODULE['<{retailcrm}prestashop>retailcrm_cc18dd262eff97c4dd4b56f750896adb'] = 'Статус по умолчанию'; $_MODULE['<{retailcrm}prestashop>retailcrm_a33b96f0ce0f1227132f1cb3cf1c9e88'] = 'Статус заказа при пакетной выгрузке '; -$_MODULE['<{retailcrm}prestashop>retailcrm_1bd340aeb42a5ee0318784c2cffed8a9'] = 'Выбранная версия API недоступна'; \ No newline at end of file +$_MODULE['<{retailcrm}prestashop>retailcrm_1bd340aeb42a5ee0318784c2cffed8a9'] = 'Выбранная версия API недоступна';