From e0c23b08521ac5a704b951277df3a2bbc3a841e2 Mon Sep 17 00:00:00 2001 From: Vitaly Artemev Date: Mon, 23 Jan 2017 02:08:20 +0300 Subject: [PATCH] fixes (#4) * add delivery price * Update events.php * fix cron task * fix cron task * fix customer * fix order number --- README.md | 2 +- README.ru.md | 2 +- .../classes/retailcrm/RCrmActions.php | 6 +++--- .../classes/retailcrm/RCrmHistory.php | 10 ++++++++- classes/modules/RetailCRM/events.php | 21 +++++++++++-------- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ad59ceb..18cedf5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Module allows integrate UMI.CMS with [RetailCRM](http://www.retailcrm.pro) Add to cron: ``` -* */4 * * * /usr/bin/php /path_to_site/public_html/cron.php RetailCRM icml +0 */4 * * * /usr/bin/php /path_to_site/public_html/cron.php RetailCRM icml ``` #### Getting changes in orders diff --git a/README.ru.md b/README.ru.md index be9232b..189af3d 100644 --- a/README.ru.md +++ b/README.ru.md @@ -20,7 +20,7 @@ UMI.CMS module Добавьте в крон запись вида ``` -* */4 * * * /usr/bin/php /path_to_site/public_html/cron.php RetailCRM icml +0 */4 * * * /usr/bin/php /path_to_site/public_html/cron.php RetailCRM icml ``` #### Получение изменение из RetailCRM diff --git a/classes/modules/RetailCRM/classes/retailcrm/RCrmActions.php b/classes/modules/RetailCRM/classes/retailcrm/RCrmActions.php index adad6b8..f98996c 100644 --- a/classes/modules/RetailCRM/classes/retailcrm/RCrmActions.php +++ b/classes/modules/RetailCRM/classes/retailcrm/RCrmActions.php @@ -43,7 +43,7 @@ class RCrmActions $relationOrderDeliveryTypesMap = $retailcrm->getRelationMap($config->get('retailcrm', 'orderDeliveryTypeMap')); $crmOrderDeliveryType = $retailcrm->getRelationByMap($relationOrderDeliveryTypesMap, $umiOrderDeliveryId); - $customer = customer::get($order->getCustomerId()); + $customer = new umiObject($order->getCustomerId()); $orderItems = $order->getItems(); $orderItemsToCrm = array(); @@ -98,7 +98,7 @@ class RCrmActions $oneClickObj = new umiObject($order->getObject()->getValue('purchaser_one_click')); $orderToCrm = array( - 'number' => $order->getObject()->getName(), + 'number' => $order->getObject()->getValue('number'), 'externalId' => $order->getId(), 'phone' => $oneClickObj->getValue('phone'), 'customer' => array( @@ -169,7 +169,7 @@ class RCrmActions } $orderToCrm = array( - 'number' => $order->getObject()->getName(), + 'number' => $order->getObject()->getValue('number'), 'externalId' => $order->getId(), 'lastName' => $customer->getValue('lname'), 'firstName' => $customer->getValue('fname'), diff --git a/classes/modules/RetailCRM/classes/retailcrm/RCrmHistory.php b/classes/modules/RetailCRM/classes/retailcrm/RCrmHistory.php index 23bcdce..e236c32 100644 --- a/classes/modules/RetailCRM/classes/retailcrm/RCrmHistory.php +++ b/classes/modules/RetailCRM/classes/retailcrm/RCrmHistory.php @@ -225,6 +225,10 @@ class RCrmHistory $order->getObject()->getPropByName('payment_status_id')->setValue($umiOrderPaymentStatus); } + if (isset($crmOrder['delivery']['cost'])) { + $order->getObject()->getPropByName('delivery_price')->setValue($crmOrder['delivery']['cost']); + } + if (isset($crmOrder['delivery']['code'])) { $relationOrderDeliveryTypesMap = $retailcrm->getRelationMap($config->get('retailcrm', 'orderDeliveryTypeMap')); $umiOrderDeliveryType = $retailcrm->getRelationByMap($relationOrderDeliveryTypesMap, $crmOrder['delivery']['code'], true); @@ -379,6 +383,10 @@ class RCrmHistory $order->getObject()->getPropByName('payment_status_id')->setValue($umiOrderPaymentStatus); } + if (isset($crmOrder['delivery']['cost'])) { + $order->getObject()->getPropByName('delivery_price')->setValue($crmOrder['delivery']['cost']); + } + if (isset($crmOrder['delivery']['code'])) { $relationOrderDeliveryTypesMap = $retailcrm->getRelationMap($config->get('retailcrm', 'orderDeliveryTypeMap')); $umiOrderDeliveryType = $retailcrm->getRelationByMap($relationOrderDeliveryTypesMap, $crmOrder['delivery']['code'], true); @@ -467,4 +475,4 @@ class RCrmHistory { } -} \ No newline at end of file +} diff --git a/classes/modules/RetailCRM/events.php b/classes/modules/RetailCRM/events.php index 43a9abd..02be534 100644 --- a/classes/modules/RetailCRM/events.php +++ b/classes/modules/RetailCRM/events.php @@ -1,15 +1,18 @@ 'onCronGenerateICML', + 'history' => 'onCronSyncHistory', + ); + + if (isset($_SERVER['argv'][2]) || isset($eventHandlers[$_SERVER['argv'][2]])) { + new umiEventListener('cron', 'RetailCRM', $eventHandlers[$_SERVER['argv'][2]]); } - - if ((!isset($argv[2]) || $argv[2] == 'history') && !isset($_GET['module']) || (isset($_GET['action']) && $_GET['action'] == 'history')) { - new umiEventListener('cron', 'RetailCRM', 'onCronSyncHistory'); + + if (isset($_GET['action']) && isset($eventHandlers[$_GET['action']])) { + new umiEventListener('cron', 'RetailCRM', $eventHandlers[$_GET['action']]); } - + new umiEventListener('systemModifyPropertyValue', 'RetailCRM', 'onModifyProperty'); new umiEventListener('systemModifyObject', 'RetailCRM', 'onModifyObject'); new umiEventListener('order-status-changed', 'RetailCRM', 'onOrderStatusChanged'); -?> \ No newline at end of file +?>