From 0d8d174980adebd56715c45ac7e3e21f38f97e07 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Wed, 2 Oct 2013 17:42:20 +0400 Subject: [PATCH] v0.4.1 --- .../classes/general/ICrmOrderActions.php | 97 +++++++++++++++---- intaro.intarocrm/export/export_run.php | 25 +++++ intaro.intarocrm/export/export_setup.php | 58 ++++++++--- intaro.intarocrm/install/index.php | 33 ++++--- intaro.intarocrm/install/step5.php | 20 ++-- intaro.intarocrm/install/version.php | 4 +- .../lang/ru/icml_export_setup.php | 9 +- 7 files changed, 188 insertions(+), 58 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index 07d36601..5b5353cd 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -249,7 +249,7 @@ class ICrmOrderActions /** * - * History update; doesnt work; always returns true, but writes log of errors + * History update * @global CUser $USER * @return boolean */ @@ -289,6 +289,7 @@ class ICrmOrderActions $optionsPayStatuses = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0))); // --statuses $optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0))); $optionsSites = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_SITES, 0)); + $optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0)); $api = new IntaroCrm\RestApi($api_host, $api_key); @@ -348,13 +349,10 @@ class ICrmOrderActions while ($ar = $rsOrderProps->Fetch()) { if (isset($order['deliveryAddress']) && $order['deliveryAddress']) { switch ($ar['CODE']) { - case 'ZIP': if (isset($order['deliveryAddress']['index'])) - CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['index']))); - break; case 'CITY': if (isset($order['deliveryAddress']['city'])) CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['city']))); break; - case 'ADDRESS': if (isset($order['deliveryAddress']['text'])) + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text']: if (isset($order['deliveryAddress']['text'])) CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['text']))); break; case 'LOCATION': if (isset($order['deliveryAddress']['city'])) { @@ -365,10 +363,42 @@ class ICrmOrderActions } break; } + + if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']] > 4)) { + switch ($ar['CODE']) { + /* case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['region']: $resOrderDeliveryAddress['region'] = self::toJSON($ar['VALUE']); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']); + break; */ + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street']: if (isset($order['deliveryAddress']['street'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['street']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['building']: if (isset($order['deliveryAddress']['building'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['building']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['flat']: if (isset($order['deliveryAddress']['flat'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['flat']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['intercomcode']: if (isset($order['deliveryAddress']['intercomcode'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['intercomcode']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['floor']: if (isset($order['deliveryAddress']['floor'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['floor']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['block']: if (isset($order['deliveryAddress']['block'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['block']))); + break; + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['house']: if (isset($order['deliveryAddress']['house'])) + CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['house']))); + break; + } + } } switch ($ar['CODE']) { - case 'FIO': + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['fio']: if (isset($order['firstName'])) $contactName['firstName'] = self::fromJSON($order['firstName']); if (isset($order['lastName'])) @@ -381,32 +411,62 @@ class ICrmOrderActions CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => implode(" ", $contactName))); break; - case 'PHONE': if (isset($order['phone'])) + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['phone']: if (isset($order['phone'])) CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['phone']))); break; - case 'EMAIL': if (isset($order['email'])) + case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['email']: if (isset($order['email'])) CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['email']))); break; } + } // here check if smth wasnt added or new propetties if (isset($order['deliveryAddress']) && $order['deliveryAddress']) { - if (isset($order['deliveryAddress']['index'])) - self::addOrderProperty('ZIP', self::fromJSON($order['deliveryAddress']['index']), $order['externalId']); - if (isset($order['deliveryAddress']['city'])) - self::addOrderProperty('CITY', self::fromJSON($order['deliveryAddress']['city']), $order['externalId']); + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['city'], self::fromJSON($order['deliveryAddress']['city']), $order['externalId']); if (isset($order['deliveryAddress']['text'])) - self::addOrderProperty('ADDRESS', self::fromJSON($order['deliveryAddress']['text']), $order['externalId']); + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text'], self::fromJSON($order['deliveryAddress']['text']), $order['externalId']); + + if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']] > 4)) { + if (isset($order['deliveryAddress']['street'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street'], + self::fromJSON($order['deliveryAddress']['street']), $order['externalId']); + + if (isset($order['deliveryAddress']['building'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['building'], + self::fromJSON($order['deliveryAddress']['bulding']), $order['externalId']); + + if (isset($order['deliveryAddress']['flat'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['flat'], + self::fromJSON($order['deliveryAddress']['flat']), $order['externalId']); + + if (isset($order['deliveryAddress']['intercomcode'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['intercomcode'], + self::fromJSON($order['deliveryAddress']['intercomcode']), $order['externalId']); + + if (isset($order['deliveryAddress']['floor'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['floor'], + self::fromJSON($order['deliveryAddress']['floor']), $order['externalId']); + + if (isset($order['deliveryAddress']['block'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['block'], + self::fromJSON($order['deliveryAddress']['block']), $order['externalId']); + + if (isset($order['deliveryAddress']['house'])) + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['house'], + self::fromJSON($order['deliveryAddress']['house']), $order['externalId']); + } } if (isset($order['phone'])) - self::addOrderProperty('PHONE', self::fromJSON($order['phone']), $order['externalId']); + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['phone'], + self::fromJSON($order['phone']), $order['externalId']); if (isset($order['email'])) - self::addOrderProperty('EMAIL', self::fromJSON($order['email']), $order['externalId']); + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['email'], + self::fromJSON($order['email']), $order['externalId']); if (isset($order['firstName'])) $contactName['firstName'] = self::fromJSON($order['firstName']); @@ -416,7 +476,8 @@ class ICrmOrderActions $contactName['patronymic'] = self::fromJSON($order['patronymic']); if (isset($contactName) && !empty($contactName)) - self::addOrderProperty('FIO', implode(" ", $contactName), $order['externalId']); + self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['fio'], + implode(" ", $contactName), $order['externalId']); /*foreach($order['items'] as $item) { $p = CSaleBasket::GetList( @@ -670,7 +731,7 @@ class ICrmOrderActions break; } - if (count($arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']] > 5)) { + if (count($arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']] > 4)) { switch ($ar['CODE']) { /*case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['country']: $resOrderDeliveryAddress['country'] = self::toJSON($ar['VALUE']); break; @@ -684,7 +745,7 @@ class ICrmOrderActions break; case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['flat']: $resOrderDeliveryAddress['flat'] = self::toJSON($ar['VALUE']); break; - case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['inercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); + case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['intercomcode']: $resOrderDeliveryAddress['intercomcode'] = self::toJSON($ar['VALUE']); break; case $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']]['floor']: $resOrderDeliveryAddress['floor'] = self::toJSON($ar['VALUE']); break; diff --git a/intaro.intarocrm/export/export_run.php b/intaro.intarocrm/export/export_run.php index b0ddb912..34b4f19b 100644 --- a/intaro.intarocrm/export/export_run.php +++ b/intaro.intarocrm/export/export_run.php @@ -10,6 +10,31 @@ if (!CModule::IncludeModule("catalog")) if (!CModule::IncludeModule("intaro.intarocrm")) return; +$iblockProperties = Array( + "article" => "article", + "manufacturer" => "manufacturer", + "color" =>"color", + "weight" => "weight", + "size" => "size", + ); +$IBLOCK_PROPERTY_SKU = array(); +foreach ($iblockProperties as $prop) { + $skuProps = ('IBLOCK_PROPERTY_SKU' . "_" . $prop); + $skuProps = $$skuProps; + foreach ($skuProps as $iblock => $val) { + $IBLOCK_PROPERTY_SKU[$iblock][$prop] = $val; + } +} +$IBLOCK_PROPERTY_PRODUCT = array(); +foreach ($iblockProperties as $prop) { + $skuProps = "IBLOCK_PROPERTY_PRODUCT" . "_" . $prop; + $skuProps = $$skuProps; + foreach ($skuProps as $iblock => $val) { + $IBLOCK_PROPERTY_PRODUCT[$iblock][$prop] = $val; + } +} + + $loader = new ICMLLoader(); $loader->iblocks = $IBLOCK_EXPORT; $loader->propertiesSKU = $IBLOCK_PROPERTY_SKU; diff --git a/intaro.intarocrm/export/export_setup.php b/intaro.intarocrm/export/export_setup.php index 008ddf9a..8c4e8176 100644 --- a/intaro.intarocrm/export/export_setup.php +++ b/intaro.intarocrm/export/export_setup.php @@ -1,6 +1,12 @@ "article", + "manufacturer" => "manufacturer", + "color" =>"color", + "weight" => "weight", + "size" => "size", + ); if(!check_bitrix_sessid()) return; @@ -8,19 +14,31 @@ __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro. if (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) { + + if (isset($arOldSetupVars['SETUP_FILE_NAME'])) $SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME']; if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; if (isset($arOldSetupVars['IBLOCK_EXPORT'])) $IBLOCK_EXPORT = $arOldSetupVars['IBLOCK_EXPORT']; - if (isset($arOldSetupVars['IBLOCK_PROPERTY_SKU'])) - $IBLOCK_PROPERTY_SKU = $arOldSetupVars['IBLOCK_PROPERTY_SKU']; - if (isset($arOldSetupVars['IBLOCK_PROPERTY_PRODUCT'])) - $IBLOCK_PROPERTY_PRODUCT = $arOldSetupVars['IBLOCK_PROPERTY_PRODUCT']; + + $IBLOCK_PROPERTY_SKU = array(); + foreach ($iblockProperties as $prop) { + foreach ($arOldSetupVars['IBLOCK_PROPERTY_SKU'. '_' . $prop] as $iblock => $val) { + $IBLOCK_PROPERTY_SKU[$iblock][$prop] = $val; + } + } + $IBLOCK_PROPERTY_PRODUCT = array(); + foreach ($iblockProperties as $prop) { + foreach ($arOldSetupVars['IBLOCK_PROPERTY_PRODUCT'. '_' . $prop] as $iblock => $val) { + $IBLOCK_PROPERTY_PRODUCT[$iblock][$prop] = $val; + } + } } + if ($STEP>1) { @@ -76,11 +94,11 @@ if ($STEP==1) } $iblockPropertiesName = Array( - "article" => "Артикул", - "manufacturer" => "Производитель", - "color" => "Цвет", - "weight" => "Вес", - "size" => "Размер", + "article" => GetMessage("PROPERTY_ARTICLE_HEADER_NAME"), + "manufacturer" => GetMessage("PROPERTY_MANUFACTURER_HEADER_NAME"), + "color" => GetMessage("PROPERTY_COLOR_HEADER_NAME"), + "weight" => GetMessage("PROPERTY_WEIGHT_HEADER_NAME"), + "size" => GetMessage("PROPERTY_SIZE_HEADER_NAME"), ); $iblockPropertiesHint = Array( @@ -209,14 +227,14 @@ if ($STEP==1) -
Выгружаемое свойство
+
-
Свойство товара
+
-
Свойство торгового предложения
+
@@ -233,7 +251,7 @@ if ($STEP==1) " - name="IBLOCK_PROPERTY_SKU[][]" + name="IBLOCK_PROPERTY_SKU_[]" class="property-export" onchange="propertyChange(this);"> @@ -422,11 +440,19 @@ if ($STEP==1) + "> - + "> diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 2a8e5cec..b587945a 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -823,15 +823,27 @@ class intaro_intarocrm extends CModule { else $iblocks = $_POST['IBLOCK_EXPORT']; - if(!isset($_POST['IBLOCK_PROPERTY_SKU'])) - $arResult['errCode'] = 'ERR_FIELDS_SKU'; - else - $propertiesSKU = $_POST['IBLOCK_PROPERTY_SKU']; + $iblockProperties = Array( + "article" => "article", + "manufacturer" => "manufacturer", + "color" =>"color", + "weight" => "weight", + "size" => "size", + ); - if(!isset($_POST['IBLOCK_PROPERTY_PRODUCT'])) - $arResult['errCode'] = 'ERR_FIELDS_PRODUCT'; - else - $propertiesProduct = $_POST['IBLOCK_PROPERTY_PRODUCT']; + $propertiesSKU = array(); + foreach ($iblockProperties as $prop) { + foreach ($_POST['IBLOCK_PROPERTY_SKU'. '_' . $prop] as $iblock => $val) { + $propertiesSKU[$iblock][$prop] = $val; + } + } + + $propertiesProduct = array(); + foreach ($iblockProperties as $prop) { + foreach ($_POST['IBLOCK_PROPERTY_PRODUCT'. '_' . $prop] as $iblock => $val) { + $propertiesProduct[$iblock][$prop] = $val; + } + } if (!isset($_POST['SETUP_FILE_NAME'])) $arResult['errCode'] = 'ERR_FIELDS_FILE'; @@ -1091,14 +1103,13 @@ class intaro_intarocrm extends CModule { $strVars .= 'IBLOCK_EXPORT[' . $key . ']=' . $val . '&'; foreach ($propertiesSKU as $iblock => $arr) foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_SKU[' . $iblock . '][' . $id . ']=' . $val . '&'; + $strVars .= 'IBLOCK_PROPERTY_SKU_' . $id . '[' . $iblock . ']=' . $val . '&'; foreach ($propertiesProduct as $iblock => $arr) foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_PRODUCT[' . $iblock . '][' . $id . ']=' . $val . '&'; + $strVars .= 'IBLOCK_PROPERTY_PRODUCT_' . $id . '[' . $iblock . ']=' . $val . '&'; $strVars .= 'SETUP_FILE_NAME=' . urlencode($filename); return $strVars; } - } \ No newline at end of file diff --git a/intaro.intarocrm/install/step5.php b/intaro.intarocrm/install/step5.php index a3389bcb..9378847a 100644 --- a/intaro.intarocrm/install/step5.php +++ b/intaro.intarocrm/install/step5.php @@ -35,11 +35,11 @@ if (!empty($oldValues)) { } $iblockPropertiesName = Array( - "article" => "Артикул", - "manufacturer" => "Производитель", - "color" => "Цвет", - "weight" => "Вес", - "size" => "Размер", + "article" => GetMessage("PROPERTY_ARTICLE_HEADER_NAME"), + "manufacturer" => GetMessage("PROPERTY_MANUFACTURER_HEADER_NAME"), + "color" => GetMessage("PROPERTY_COLOR_HEADER_NAME"), + "weight" => GetMessage("PROPERTY_WEIGHT_HEADER_NAME"), + "size" => GetMessage("PROPERTY_SIZE_HEADER_NAME"), ); $iblockPropertiesHint = Array( @@ -165,14 +165,14 @@ if (!empty($oldValues)) { -
Выгружаемое свойство
+
-
Свойство товара
+
-
Свойство торгового предложения
+
@@ -189,7 +189,7 @@ if (!empty($oldValues)) { " - name="IBLOCK_PROPERTY_SKU[][]" + name="IBLOCK_PROPERTY_SKU_[]" class="property-export" onchange="propertyChange(this);"> diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 2d43932f..3ef4e8e3 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,6 +1,6 @@ "0.4.0", - "VERSION_DATE" => "2013-09-12 17:00:00", + "VERSION" => "0.4.1", + "VERSION_DATE" => "2013-09-24 18:52:00", ); diff --git a/intaro.intarocrm/lang/ru/icml_export_setup.php b/intaro.intarocrm/lang/ru/icml_export_setup.php index ee440a48..7dc07010 100644 --- a/intaro.intarocrm/lang/ru/icml_export_setup.php +++ b/intaro.intarocrm/lang/ru/icml_export_setup.php @@ -17,5 +17,12 @@ $MESS["PROFILE_NAME"] = "Имя профиля"; $MESS["SETTINGS_INFOBLOCK"] = "Настройки инфоблоков"; $MESS["SETTINGS_EXPORT"] = "Настройки экспорта"; $MESS["CHECK_ALL_INFOBLOCKS"] = "Выбрать все инфоблоки "; - +$MESS["LOADED_PROPERTY"] = "Выгружаемое свойство"; +$MESS["PROPERTY_PRODUCT_HEADER_NAME"] = "Свойство товара"; +$MESS["PROPERTY_OFFER_HEADER_NAME"] = "Свойство торгового предложения"; +$MESS["PROPERTY_ARTICLE_HEADER_NAME"] = "Артикул"; +$MESS["PROPERTY_MANUFACTURER_HEADER_NAME"] = "Производитель"; +$MESS["PROPERTY_COLOR_HEADER_NAME"] = "Цвет"; +$MESS["PROPERTY_WEIGHT_HEADER_NAME"] = "Вес"; +$MESS["PROPERTY_SIZE_HEADER_NAME"] = "Размер"; ?> \ No newline at end of file