From 400e8c4958f77de86fce536fb7b1cd4e15d154b6 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Fri, 20 Jun 2014 16:03:46 +0400 Subject: [PATCH] +orderAgent(); +reserveOrderEvents; +basePrice selection on export; +event intarocrm_before_order_send; +fix issues with incorrect order status changing. --- .../classes/general/ICMLLoader.php | 12 ++- .../classes/general/ICrmOrderActions.php | 83 ++++++++++++------- .../classes/general/events/ICrmOrderEvent.php | 21 +++++ intaro.intarocrm/export/export_setup.php | 29 ++++++- intaro.intarocrm/install/index.php | 35 +++++--- intaro.intarocrm/install/step5.php | 12 +++ intaro.intarocrm/install/version.php | 2 +- .../lang/ru/icml_export_setup.php | 3 +- intaro.intarocrm/lang/ru/install/step5.php | 3 +- 9 files changed, 152 insertions(+), 48 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICMLLoader.php b/intaro.intarocrm/classes/general/ICMLLoader.php index db1ce1f5..db0b587e 100644 --- a/intaro.intarocrm/classes/general/ICMLLoader.php +++ b/intaro.intarocrm/classes/general/ICMLLoader.php @@ -25,6 +25,8 @@ class ICMLLoader { protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt'; protected $fpLog; + protected $MODULE_ID = 'intaro.intarocrm'; + protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; protected $measurement = array ( 'mm' => 1, // 1 mm = 1 mm @@ -218,6 +220,10 @@ class ICMLLoader { protected function BuildOffers(&$allCategories) { + + $basePriceId = COption::GetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, 1); + + foreach ($this->iblocks as $key => $id) { // Get Info by infoblocks @@ -238,7 +244,7 @@ class ICMLLoader { "DETAIL_PICTURE", "LANG_DIR", "DETAIL_PAGE_URL", - "CATALOG_GROUP_1" + "CATALOG_GROUP_" . $basePriceId ); // Set selected properties foreach ($this->propertiesProduct[$id] as $key => $propProduct) { @@ -256,7 +262,7 @@ class ICMLLoader { "DETAIL_PAGE_URL", "DETAIL_PICTURE", 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'], - "CATALOG_GROUP_1" + "CATALOG_GROUP_" . $basePriceId ); // Set selected properties foreach ($this->propertiesSKU[$id] as $key => $propSKU) { @@ -394,7 +400,7 @@ class ICMLLoader { $offer['PICTURE'] = $product["PICTURE"]; $offer['PRODUCT_NAME'] = $product["NAME"]; $offer['PRODUCT_ACTIVE'] = $product["ACTIVE"]; - $offer['PRICE'] = $offer['CATALOG_PRICE_1']; + $offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId]; $offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE']; $offer['QUANTITY'] = $offer["CATALOG_QUANTITY"]; diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 95f5cc6e..f869d588 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -600,7 +600,7 @@ class ICrmOrderActions if(isset($order['externalId']) && $order['externalId']) { - // custom orderType functunion + // custom orderType function if(function_exists('intarocrm_set_order_type')) { $orderType = intarocrm_set_order_type($order); if($orderType) @@ -969,22 +969,23 @@ class ICrmOrderActions 'COMMENTS' => self::fromJSON($order['managerComment']) )); - CSaleOrder::Update($order['externalId'], $arFields); + if(!empty($arFields)) + CSaleOrder::Update($order['externalId'], $arFields); // set STATUS_ID - if($order['status'] && $optionsPayStatuses[$order['status']]) + if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']]) CSaleOrder::StatusOrder($order['externalId'], $optionsPayStatuses[$order['status']]); // uncancel order - if($wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY')) + if(isset($order['status']) && $order['status'] && $wasCanaceled && ($optionsPayStatuses[$order['status']] != 'YY')) CSaleOrder::CancelOrder($order['externalId'], "N", $order['statusComment']); // cancel order - if($optionsPayStatuses[$order['status']] == 'YY') + if(isset($order['status']) && $order['status'] && $optionsPayStatuses[$order['status']] == 'YY') CSaleOrder::CancelOrder($order['externalId'], "Y", $order['statusComment']); // set PAYED - if($optionsPayment[$order['paymentStatus']]) + if(isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']]) CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]); } } @@ -1044,6 +1045,19 @@ class ICrmOrderActions return 'ICrmOrderActions::orderHistoryAgent();'; } + /** + * + * Agent function + * + * @return self name + */ + + public static function orderAgent() { + self::uploadOrdersAgent(); + self::orderHistory(); + return 'ICrmOrderActions::orderAgent();'; + } + /** * * creates order or returns array of order and customer for mass upload @@ -1110,26 +1124,6 @@ class ICrmOrderActions 'createdAt' => $createdAt )); - if($send) { - try { - $customer = $api->customerEdit($customer); - } catch (\IntaroCrm\Exception\ApiException $e) { - self::eventLog( - 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', - $e->getCode() . ': ' . $e->getMessage() - ); - - return false; - } catch (\IntaroCrm\Exception\CurlException $e) { - self::eventLog( - 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException', - $e->getCode() . ': ' . $e->getMessage() - ); - - return false; - } - } - // delivery types $arId = array(); if (strpos($arFields['DELIVERY_ID'], ":") !== false) @@ -1275,6 +1269,7 @@ class ICrmOrderActions $createdAt = $createdAt->format('Y-m-d H:i:s'); $resOrder = array( + 'customer' => $customer, 'number' => $arFields['ACCOUNT_NUMBER'], 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], @@ -1298,7 +1293,6 @@ class ICrmOrderActions 'items' => $items ); - if(isset($arParams['optionsSites']) && is_array($arParams['optionsSites']) && in_array($arFields['LID'], $arParams['optionsSites'])) $resOrder['site'] = $arFields['LID']; @@ -1312,7 +1306,7 @@ class ICrmOrderActions $resOrder['patronymic'] = $contactNameArr[2]; } - // custom orderType functunion + // custom orderType function if(function_exists('intarocrm_get_order_type')) { $orderType = intarocrm_get_order_type($arFields); if($orderType) @@ -1321,9 +1315,42 @@ class ICrmOrderActions $orderType['orderType'] = 'new'; } + // custom order & customer fields function + if(function_exists('intarocrm_before_order_send')) { + $newResOrder = intarocrm_before_order_send($resOrder); + + if(is_array($newResOrder) && !empty($newResOrder)) + $resOrder = $newResOrder; + + } + $resOrder = self::clearArr($resOrder); + if(isset($resOrder['customer']) && is_array($resOrder['customer']) && !empty($resOrder['customer'])) { + $customer = $resOrder['customer']; + unset($resOrder['customer']); + } + if($send) { + + try { + $customer = $api->customerEdit($customer); + } catch (\IntaroCrm\Exception\ApiException $e) { + self::eventLog( + 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit', + $e->getCode() . ': ' . $e->getMessage() + ); + + return false; + } catch (\IntaroCrm\Exception\CurlException $e) { + self::eventLog( + 'ICrmOrderActions::orderCreate', 'IntaroCrm\RestApi::customerEdit::CurlException', + $e->getCode() . ': ' . $e->getMessage() + ); + + return false; + } + try { return $api->orderEdit($resOrder); } catch (\IntaroCrm\Exception\ApiException $e) { diff --git a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php index d33238dc..9367cff2 100644 --- a/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php +++ b/intaro.intarocrm/classes/general/events/ICrmOrderEvent.php @@ -25,6 +25,27 @@ class ICrmOrderEvent { $GLOBALS['INTARO_CRM_ORDER_ADD'] = true; return; } + + /** + * OnSaleBeforeReserveOrder + * + * @param mixed $arFields - Order arFields + */ + function OnSaleBeforeReserveOrder($arFields = array()) { + $GLOBALS['INTARO_CRM_ORDER_RESERVE'] = true; + return; + } + + /** + * OnSaleReserveOrder + * + * @param mixed $arFields - Order arFields + */ + function OnSaleReserveOrder($arFields = array()) { + if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE']) + unset($GLOBALS['INTARO_CRM_ORDER_RESERVE']); + return; + } /** * onUpdateOrder diff --git a/intaro.intarocrm/export/export_setup.php b/intaro.intarocrm/export/export_setup.php index f4c666a5..ac2390b9 100644 --- a/intaro.intarocrm/export/export_setup.php +++ b/intaro.intarocrm/export/export_setup.php @@ -15,6 +15,19 @@ if(!check_bitrix_sessid()) return; __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php")); +$MODULE_ID = 'intaro.intarocrm'; +$CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; +$basePriceId = COption::GetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE, 1); + +$arResult['PRICE_TYPES'] = array(); +$dbPriceType = CCatalogGroup::GetList( + array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE") +); + +while ($arPriceType = $dbPriceType->Fetch()) { + $arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType; +} + if (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) { @@ -550,6 +563,20 @@ if ($STEP==1)

+   + + +
+
+


@@ -563,7 +590,6 @@ if ($STEP==1)
-