diff --git a/CHANGELOG.md b/CHANGELOG.md
index b79db623..3e9ebf64 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
+## 2018-12-26 v.2.4.2
+* Добавлена конвертация закупочной цены при выгрузке заказа
+* Исправлен файл переводов для выгрузки каталога
+* В настройку экспорта каталога добавлена настройка максимального количества торговых предложений у товара
+* Исправлен вызов обработчика сохранения оплаты при создании заказа
+
## 2018-11-02 v.2.4.1
-* исправлены ошибки в файле optoins.php
+* Исправлены ошибки в файле options.php
## 2018-11-02 v.2.4.0
* Изменена привязка на событие сохранения заказа. Используется привязка к событию "OnSaleOrderSaved"
diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php
index b89af713..32f8d6a6 100644
--- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php
+++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php
@@ -3,8 +3,9 @@
* RCrmEvent
*/
use \Bitrix\Main\Event;
+
class RetailCrmEvent
-{
+{
protected static $MODULE_ID = 'intaro.retailcrm';
protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key';
@@ -20,28 +21,30 @@ class RetailCrmEvent
protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_SITES_LIST = 'sites_list';
-
+
/**
* OnAfterUserUpdate
*
* @param mixed $arFields - User arFields
+ *
+ * @return mixed
*/
function OnAfterUserUpdate($arFields)
{
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
return;
}
-
+
if (!$arFields['RESULT']) {
return;
}
-
+
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key);
-
+
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
-
+
$resultOrder = RetailCrmUser::customerEdit($arFields, $api, $optionsSitesList);
if (!$resultOrder) {
RCrmActions::eventLog('RetailCrmEvent::OnAfterUserUpdate', 'RetailCrmUser::customerEdit', 'error update customer');
@@ -62,12 +65,12 @@ class RetailCrmEvent
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
return;
}
-
+
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
return;
}
-
+
/**
* orderDelete
*
@@ -79,13 +82,14 @@ class RetailCrmEvent
return;
}
-
+
/**
* orderSave
- *
+ *
* @param object $event - Order object
+ *
+ * @return bool
*/
-
function orderSave($event)
{
if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] !== false && $GLOBALS['RETAIL_CRM_HISTORY'] !== true && $GLOBALS['RETAILCRM_ORDER_DELETE'] !== true) {
@@ -199,13 +203,19 @@ class RetailCrmEvent
/**
* paymentSave
*
- * @param object $event - Payment object
+ * @param \Bitrix\Sale\Payment $event - Payment object
*/
function paymentSave($event)
{
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
- if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) || $apiVersion != 'v5') {
+ /** @var \Bitrix\Sale\Order $order */
+ $order = $event->getCollection()->getOrder();
+
+ if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
+ || $apiVersion != 'v5'
+ || $order->isNew()
+ ) {
return;
}
@@ -219,18 +229,10 @@ class RetailCrmEvent
'PAID' => $event->getField('PAID'),
'PAY_SYSTEM_ID' => $event->getField('PAY_SYSTEM_ID'),
'SUM' => $event->getField('SUM'),
- 'LID' => $event->getField('LID'),
+ 'LID' => $order->getSiteId(),
'DATE_PAID' => $event->getField('DATE_PAID'),
);
- try {
- $newOrder = Bitrix\Sale\Order::load($arPayment['ORDER_ID']);
- $arPayment['LID'] = $newOrder->getField('LID');
- } catch (Bitrix\Main\ArgumentNullException $e) {
- RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'Bitrix\Sale\Order::load', $e->getMessage() . ': ' . $arPayment['ORDER_ID']);
- return;
- }
-
if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arPayment['LID']];
@@ -304,12 +306,14 @@ class RetailCrmEvent
*
* @param object $event - Payment object
*/
-
function paymentDelete($event)
{
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
- if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) || $apiVersion != 'v5' || !$event->getId()) {
+ if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
+ || $apiVersion != 'v5'
+ || !$event->getId()
+ ) {
return;
}
@@ -317,17 +321,10 @@ class RetailCrmEvent
$arPayment = array(
'ID' => $event->getId(),
- 'ORDER_ID' => $event->getField('ORDER_ID')
+ 'ORDER_ID' => $event->getField('ORDER_ID'),
+ 'LID' => $event->getCollection()->getOrder()->getSiteId()
);
- try {
- $newOrder = Bitrix\Sale\Order::load($arPayment['ORDER_ID']);
- $arPayment['LID'] = $newOrder->getField('LID');
- } catch (Bitrix\Main\ArgumentNullException $e) {
- RCrmActions::eventLog('RetailCrmEvent::paymentDelete', 'Bitrix\Sale\Order::load', $e->getMessage() . ': ' . $arPayment['ORDER_ID']);
- return;
- }
-
if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arPayment['LID']];
diff --git a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php
index 98425ac4..cd726c87 100644
--- a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php
+++ b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php
@@ -23,11 +23,11 @@ class RetailCrmICML
public $loadPurchasePrice = false;
public $productPictures;
public $skuPictures;
+ public $offerPageSize = 50;
protected $fp;
protected $mainSection = 1000000;
protected $pageSize = 500;
- protected $offerPageSize = 50;
protected $protocol;
protected $isLogged = false;
@@ -111,6 +111,17 @@ class RetailCrmICML
}
+ private function setSiteAddress($block_id)
+ {
+ $site = CAllIBlock::GetSite($block_id)->Fetch();
+
+ if ($site['SERVER_NAME']) {
+ $this->serverName = $site['SERVER_NAME'];
+ } else {
+ $this->serverName = $this->defaultServerName;
+ }
+ }
+
protected function PrepareSettings()
{
foreach ($this->propertiesSKU as $iblock => $arr) {
@@ -118,6 +129,7 @@ class RetailCrmICML
$this->propertiesSKU[$iblock][$id] = strtoupper($sku);
}
}
+
foreach ($this->propertiesProduct as $iblock => $arr) {
foreach ($arr as $id => $prod) {
$this->propertiesProduct[$iblock][$id] = strtoupper($prod);
@@ -202,22 +214,27 @@ class RetailCrmICML
{
$categories = array();
foreach ($this->iblocks as $id) {
+ $this->setSiteAddress($id);
$filter = array("IBLOCK_ID" => $id);
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
$hasCategories = false;
+
while ($arRes = $dbRes->Fetch()) {
$categories[$arRes['ID']] = $arRes;
+ $categories[$arRes['ID']]['SITE'] = $this->protocol . $this->serverName;
$hasCategories = true;
}
+
if (!$hasCategories) {
$iblock = CIBlock::GetByID($id)->Fetch();
- $arRes = Array();
+ $arRes = array();
$arRes['ID'] = $this->mainSection + $id;
$arRes['IBLOCK_SECTION_ID'] = 0;
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
$categories[$arRes['ID']] = $arRes;
+ $categories[$arRes['ID']]['SITE'] = $this->protocol . $this->serverName;
}
}
@@ -226,15 +243,25 @@ class RetailCrmICML
protected function BuildCategory($arCategory)
{
- return "
-
+
+ =GetMessage("OFFERS_VALUE");?>
+
+
+
+
+
+
=GetMessage("PROFILE_NAME");?>
- $vals = "LOAD_PURCHASE_PRICE,SETUP_FILE_NAME,IBLOCK_EXPORT";
+ $vals = "LOAD_PURCHASE_PRICE,SETUP_FILE_NAME,IBLOCK_EXPORT,MAX_OFFERS_VALUE";
foreach ($iblockProperties as $val) {
$vals .= ",IBLOCK_PROPERTY_SKU_" . $val;
$vals .= ",IBLOCK_PROPERTY_UNIT_SKU_" . $val;
@@ -820,7 +830,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
}
- elseif ($STEP==2)
+ elseif ($STEP == 2)
{
COption::SetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE . '_' . $_REQUEST['PROFILE_ID'], htmlspecialchars(trim($_POST['price-types'])));
$FINITE = true;
diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php
index 929a7712..f791c99f 100644
--- a/intaro.retailcrm/install/index.php
+++ b/intaro.retailcrm/install/index.php
@@ -864,6 +864,12 @@ class intaro_retailcrm extends CModule
$typeLoading = $_POST['TYPE_LOADING'];
}
+ if (!isset($_POST['MAX_OFFERS_VALUE'])) {
+ $maxOffers = "";
+ } else {
+ $maxOffers = $_POST['MAX_OFFERS_VALUE'];
+ }
+
if (!isset($_POST['SETUP_PROFILE_NAME'])) {
$profileName = "";
} else {
@@ -886,7 +892,8 @@ class intaro_retailcrm extends CModule
'IBLOCK_PROPERTY_PRODUCT' => $propertiesProduct,
'IBLOCK_PROPERTY_UNIT_PRODUCT' => $propertiesUnitProduct,
'SETUP_FILE_NAME' => $filename,
- 'SETUP_PROFILE_NAME' => $profileName
+ 'SETUP_PROFILE_NAME' => $profileName,
+ 'MAX_OFFERS_VALUE' => $maxOffers
);
global $oldValues;
$oldValues = $arOldValues;
@@ -938,6 +945,10 @@ class intaro_retailcrm extends CModule
$loader->highloadblockProductProperties = $propertiesHbProduct;
}
+ if ($maxOffers) {
+ $loader->offerPageSize = $maxOffers;
+ }
+
$loader->filename = $filename;
$loader->serverName = \Bitrix\Main\Context::getCurrent()->getServer()->getHttpHost();
$loader->application = $APPLICATION;
@@ -964,7 +975,8 @@ class intaro_retailcrm extends CModule
$propertiesUnitSKU,
$propertiesHbSKU,
$propertiesHbProduct,
- $filename
+ $filename,
+ $maxOffers
);
$PROFILE_ID = CCatalogExport::Add(array(
"LAST_USE" => false,
@@ -1213,7 +1225,8 @@ class intaro_retailcrm extends CModule
$propertiesUnitSKU,
$propertiesHbSKU,
$propertiesHbProduct,
- $filename
+ $filename,
+ $maxOffers
) {
$strVars = "";
foreach ($iblocks as $key => $val)
@@ -1244,6 +1257,7 @@ class intaro_retailcrm extends CModule
}
$strVars .= 'SETUP_FILE_NAME=' . urlencode($filename);
+ $strVars .= '&MAX_OFFERS_VALUE=' . urlencode($maxOffers);
return $strVars;
}
diff --git a/intaro.retailcrm/install/step5.php b/intaro.retailcrm/install/step5.php
index 57894d48..6fa29689 100644
--- a/intaro.retailcrm/install/step5.php
+++ b/intaro.retailcrm/install/step5.php
@@ -17,6 +17,7 @@ if (!empty($oldValues)) {
$IBLOCK_PROPERTY_UNIT_PRODUCT = $oldValues['IBLOCK_PROPERTY_UNIT_PRODUCT'];
$SETUP_FILE_NAME = $oldValues['SETUP_FILE_NAME'];
$SETUP_PROFILE_NAME = $oldValues['SETUP_PROFILE_NAME'];
+ $MAX_OFFERS_VALUE = $oldValues['MAX_OFFERS_VALUE'];
}
?>
@@ -475,6 +476,18 @@ if (!empty($oldValues)) {
+