private static function EnsureProduct($externalID, $catalogID, $arFields) { $rsProducts = CCrmProduct::GetList(array(), array('CATALOG_ID' => $catalogID, 'ORIGIN_ID' => $externalID), array('ID')); $arProduct = $rsProducts ? $rsProducts->Fetch() : false; if (is_array($arProduct)) { return intval($arProduct['ID']); } $arFields['CATALOG_ID'] = $catalogID; $arFields['ORIGIN_ID'] = $externalID; return CCrmProduct::Add($arFields); }
public static function PrepareListItems($catalogID = 0) { $catalogID = intval($catalogID); $result = array(); $filter = array('ACTIVE' => 'Y'); if ($catalogID > 0) { $filter['CATALOG_ID'] = $catalogID; } $rs = CCrmProduct::GetList(array('SORT' => 'ASC', 'NAME' => 'ASC'), $filter, array('ID', 'NAME')); while ($ar = $rs->Fetch()) { $result[$ar['ID']] = $ar['NAME']; } return $result; }
unset($arProductId, $arPricesSelect, $arVatsSelect); foreach ($arProducts as $arRes) { $arRes['SID'] = $arResult['PREFIX'] == 'Y'? 'D_'.$arRes['ID']: $arRes['ID']; if (isset($arResult['SELECTED'][$arRes['SID']])) { unset($arResult['SELECTED'][$arRes['SID']]); $sSelected = 'Y'; } else $sSelected = 'N'; $ar[] = array( 'title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array( 'product_id' => $arRes['ID'] ) ), 'type' => 'product', 'selected' => $sSelected ); } unset($arProducts); $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']); } } ?>
$arActions[] = array('ICONCLASS' => 'edit', 'TITLE' => GetMessage('CRM_PRODUCT_EDIT_TITLE'), 'TEXT' => GetMessage('CRM_PRODUCT_EDIT'), 'ONCLICK' => 'jsUtils.Redirect([], \'' . CUtil::JSEscape(CHTTP::urlAddParams($arProduct['PATH_TO_PRODUCT_EDIT'], array('list_section_id' => $arResult['BACK_URL_SECTION_ID']))) . '\');'); } if ($arProduct['DELETE'] && !$arResult['INTERNAL']) { $arActions[] = array('SEPARATOR' => true); $arActions[] = array('ICONCLASS' => 'delete', 'TITLE' => GetMessage('CRM_PRODUCT_DELETE_TITLE'), 'TEXT' => GetMessage('CRM_PRODUCT_DELETE'), 'ONCLICK' => 'crm_product_delete_grid(\'' . CUtil::JSEscape(GetMessage('CRM_PRODUCT_DELETE_TITLE')) . '\', \'' . CUtil::JSEscape(sprintf(GetMessage('CRM_PRODUCT_DELETE_CONFIRM'), htmlspecialcharsbx($arProduct['NAME']))) . '\', \'' . CUtil::JSEscape(GetMessage('CRM_PRODUCT_DELETE')) . '\', \'' . CUtil::JSEscape(CHTTP::urlAddParams($arProduct['PATH_TO_PRODUCT_DELETE'], array('list_section_id' => $arResult['BACK_URL_SECTION_ID']))) . '\')'); } $sectionLink = ''; if (isset($arProduct['SECTION_ID']) && array_key_exists($arProduct['SECTION_ID'], $arResult['SECTION_LIST'])) { $sectionData = $arResult['SECTION_LIST'][$arProduct['SECTION_ID']]; $sectionLink = '<a href="' . htmlspecialcharsbx($sectionData['LIST_URL']) . '">' . htmlspecialcharsbx($sectionData['NAME']) . '</a>'; } $obPreviewPictureFile = null; if (isset($arProduct['~PREVIEW_PICTURE'])) { $obPreviewPictureFile = new CCrmProductFile($arProduct['ID'], 'PREVIEW_PICTURE', $arProduct['~PREVIEW_PICTURE']); } $gridDataRecord = array('id' => $arProduct['TYPE'] . $arProduct['ID'], 'actions' => $arActions, 'data' => $arProduct, 'editable' => $arProduct['EDIT'] ? true : $arColumns, 'columns' => array('NAME' => '<table class="bx-crm-object-name">' . PHP_EOL . "\t" . '<tbody>' . PHP_EOL . "\t" . '<tr>' . "\t\t" . '<td style="width: 45px;">' . "\t\t\t" . '<div class="bx-crm-item-icon-container-small' . (!$obPreviewPictureFile ? ' bx-crm-item-icon icon-img' : '') . '">' . ($obPreviewPictureFile ? $obPreviewPictureFile->GetImgHtml(array('max_width' => 27, 'max_height' => 35)) : '') . '</div>' . "\t\t" . '</td>' . "\t\t" . '<td>' . "\t\t\t" . '<a target="_self" href="' . CHTTP::urlAddParams($arProduct['PATH_TO_PRODUCT_SHOW'], array('list_section_id' => $arResult['BACK_URL_SECTION_ID'])) . '">' . $arProduct['NAME'] . '</a>' . "\t\t" . '</td>' . "\t" . '</tr>' . PHP_EOL . "\t" . '</tbody>' . PHP_EOL . '</table>' . PHP_EOL, 'PRICE' => CCrmProduct::FormatPrice($arProduct), 'MEASURE' => htmlspecialcharsbx(isset($arProduct['MEASURE']) && intval($arProduct['MEASURE']) > 0 ? $arResult['MEASURE_LIST_ITEMS'][$arProduct['MEASURE']] : ''), 'SECTION_ID' => $sectionLink)); if ($bVatMode) { $gridDataRecord['columns']['VAT_ID'] = htmlspecialcharsbx(isset($arProduct['VAT_ID']) ? $arResult['VAT_RATE_LIST_ITEMS'][$arProduct['VAT_ID']] : $arResult['VAT_RATE_LIST_ITEMS']['']); } // Pictures $arFields = array('PREVIEW_PICTURE', 'DETAIL_PICTURE'); $html = ''; $obFileControl = $obFile = null; foreach ($arFields as $fieldID) { if (isset($arProduct['~' . $fieldID])) { if ($fieldID === 'PREVIEW_PICTURE' && $obPreviewPictureFile) { $obFile =& $obPreviewPictureFile; } else { $obFile = new CCrmProductFile($arProduct['ID'], $fieldID, $arProduct['~' . $fieldID]); } $obFileControl = new CCrmProductFileControl($obFile, $fieldID);
private function SaveOrderDataProducts($arOrder, $dealId) { if (!isset($arOrder["ITEMS"]) || !is_array($arOrder["ITEMS"])) { return false; } if (!$this->catalogId) { if ($this->arExternalSale == null) { $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId); } $this->catalogId = CCrmCatalog::GetCatalogId($this->arExternalSale["NAME"], $this->externalSaleId, SITE_ID); if (!$this->catalogId) { if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) { $this->AddError($ex->GetID(), $ex->GetString()); } else { $this->AddError("CCA", "Catalog creation error"); } return false; } } $arProductRows = array(); foreach ($arOrder["ITEMS"] as $arItem) { $productId = 0; $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arItem["ID"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1)); if ($arProduct = $dbProduct->Fetch()) { $productId = $arProduct["ID"]; } $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arItem["ID"]); if ($productId == 0) { $res = CCrmProduct::Add($arFields); if ($res > 0) { $productId = (int) $res; } } else { $res = CCrmProduct::Update($productId, $arFields); } if (!$res) { if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) { $this->AddError($ex->GetID(), $ex->GetString()); } else { $this->AddError("CDA", "Product creation error"); } continue; } $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => $arItem["QUANTITY"]); } if (is_array($arOrder["TAXES"])) { foreach ($arOrder["TAXES"] as $arItem) { if (intval($arItem["IN_PRICE"]) > 0) { continue; } $productId = 0; $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "tax_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1)); if ($arProduct = $dbProduct->Fetch()) { $productId = $arProduct["ID"]; } $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "tax_" . $arItem["NAME"]); if ($productId == 0) { $res = CCrmProduct::Add($arFields); $productId = intval($res); } else { $res = CCrmProduct::Update($productId, $arFields); } if (!$res) { if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) { $this->AddError($ex->GetID(), $ex->GetString()); } else { $this->AddError("CDA", "Product creation error"); } continue; } $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => 1); } } if (is_array($arOrder["DISCOUNTS"])) { foreach ($arOrder["DISCOUNTS"] as $arItem) { if (intval($arItem["IN_PRICE"]) > 0) { continue; } $productId = 0; $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "discount_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1)); if ($arProduct = $dbProduct->Fetch()) { $productId = $arProduct["ID"]; } $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "discount_" . $arItem["NAME"]); if ($productId == 0) { $res = CCrmProduct::Add($arFields); $productId = intval($res); } else { $res = CCrmProduct::Update($productId, $arFields); } if (!$res) { if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) { $this->AddError($ex->GetID(), $ex->GetString()); } else { $this->AddError("CDA", "Product creation error"); } continue; } $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => -$arItem["PRICE"], 'QUANTITY' => 1); } } CCrmProductRow::SaveRows("D", $dealId, $arProductRows, null, false, false); return true; }
$arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID'); $arPricesSelect = $arVatsSelect = array(); $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect); $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['PRODUCT']), $arSelect); $arProducts = $arProductId = array(); while ($arRes = $obRes->Fetch()) { foreach ($arPricesSelect as $fieldName) { $arRes[$fieldName] = null; } foreach ($arVatsSelect as $fieldName) { $arRes[$fieldName] = null; } $arProductId[] = $arRes['ID']; $arProducts[$arRes['ID']] = $arRes; } CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect); unset($arProductId, $arPricesSelect, $arVatsSelect); foreach ($arProducts as $arRes) { $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'D_' . $arRes['ID'] : $arRes['ID']; if (isset($arResult['SELECTED'][$arRes['SID']])) { unset($arResult['SELECTED'][$arRes['SID']]); $sSelected = 'Y'; } else { $sSelected = 'N'; } $ar[] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => $sSelected); } unset($arProducts); $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']); } }
$arPropertyValues[$propID][] = nl2br(htmlspecialcharsex($arProperty["VALUE"])); } } unset($rsProperties, $arProperty, $propID); } $arResult['PROPERTY_VALUES'] = $arPropertyValues; unset($arPropertyValues); $arResult['FIELDS'] = array(); $arResult['FIELDS']['tab_1'][] = array('id' => 'product_info', 'name' => GetMessage('CRM_SECTION_PRODUCT_INFO'), 'type' => 'section', 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'ID', 'name' => 'ID', 'type' => 'label', 'params' => array('size' => 50), 'value' => $product['ID'], 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'NAME', 'name' => GetMessage('CRM_PRODUCT_FIELD_NAME'), 'params' => array('size' => 50), 'type' => 'label', 'value' => isset($product['~NAME']) ? $product['~NAME'] : '', 'isTactile' => true); if (isset($product['~DESCRIPTION']) && strlen($product['~DESCRIPTION']) > 0) { $arResult['FIELDS']['tab_1'][] = array('id' => 'DESCRIPTION', 'name' => GetMessage('CRM_FIELD_DESCRIPTION'), 'params' => array('size' => 50), 'type' => 'label', 'value' => $product['~DESCRIPTION'], 'isTactile' => true); } $arResult['FIELDS']['tab_1'][] = array('id' => 'ACTIVE', 'name' => GetMessage('CRM_FIELD_ACTIVE'), 'type' => 'label', 'params' => array(), 'value' => GetMessage(isset($product['ACTIVE']) && $product['ACTIVE'] == 'Y' ? 'MAIN_YES' : 'MAIN_NO'), 'isTactile' => true); $price = CCrmProduct::FormatPrice($product); if (strlen($price) > 0) { $arResult['FIELDS']['tab_1'][] = array('id' => 'PRICE', 'name' => GetMessage('CRM_FIELD_PRICE'), 'type' => 'label', 'params' => array(), 'value' => $price, 'isTactile' => true); } if ($bVatMode) { $arResult['FIELDS']['tab_1'][] = array('id' => 'VAT_ID', 'name' => GetMessage('CRM_FIELD_VAT_ID'), 'type' => 'label', 'params' => array(), 'value' => htmlspecialcharsbx(isset($product['VAT_ID']) && $product['VAT_ID'] > 0 ? $vatRateListItems[$product['VAT_ID']] : $vatRateListItems['']), 'isTactile' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'VAT_INCLUDED', 'name' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'type' => 'label', 'params' => array(), 'value' => GetMessage(isset($product['VAT_INCLUDED']) && $product['VAT_INCLUDED'] == 'Y' ? 'MAIN_YES' : 'MAIN_NO'), 'isTactile' => true); } $arResult['FIELDS']['tab_1'][] = array('id' => 'MEASURE', 'name' => GetMessage('CRM_FIELD_MEASURE'), 'type' => 'label', 'params' => array(), 'value' => htmlspecialcharsbx(isset($product['MEASURE']) ? $measureListItems[$product['MEASURE']] : $measureListItems['']), 'isTactile' => true); $productSectionID = isset($product['SECTION_ID']) ? $product['SECTION_ID'] : 0; $productSectionName = ''; if ($productSectionID > 0) { $sectionListItems = array(); $rsSection = CIBlockSection::GetByID($productSectionID); if ($arSection = $rsSection->Fetch()) { $productSectionName = $arSection['NAME'];
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } $arInvoices = array(); $dbProduct = CCrmProduct::GetList(array(), array(), array('*'), array('nTopCount' => 1)); if ($arProduct = $dbProduct->Fetch()) { CModule::IncludeModule("sale"); $personTypes = CCrmPaySystem::getPersonTypeIDs(); $arFields = array("ORDER_TOPIC" => GetMessage("CRM_DEMO_INVOCIE_1_SUBJ"), "STATUS_ID" => "P", "DATE_INSERT" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_BILL" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT'), "PAY_VOUCHER_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_PAY_BEFORE" => ConvertTimeStamp(time() + 8000009 + CTimeZone::GetOffset(), 'SHORT'), "RESPONSIBLE_ID" => 1, "UF_CONTACT_ID" => $arContacts["45"]['ID'], "PAY_VOUCHER_NUM" => 456, "DATE_MARKED" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "PRODUCT_ROWS" => array(array("ID" => 0, "PRODUCT_ID" => $arProduct["ID"], "PRODUCT_NAME" => $arProduct["NAME"], "QUANTITY" => 1, "PRICE" => $arProduct["PRICE"])), "PERSON_TYPE_ID" => $personTypes["CONTACT"], "INVOICE_PROPERTIES" => array()); $paySystems = CCrmPaySystem::GetPaySystems($personTypes["CONTACT"]); foreach ($paySystems as $id => $paySystem) { $arFields["PAY_SYSTEM_ID"] = $id; } $arAllProps = CCrmInvoice::GetPropertiesInfo($personTypes["CONTACT"]); foreach ($arAllProps as $arProps) { foreach ($arProps as $key => $prop) { if ($key == "FIO") { $arFields["INVOICE_PROPERTIES"][$prop["ID"]] = $arContacts["45"]["LAST_NAME"]; } } } $arInvoices[] = $arFields; $arFields = array("ORDER_TOPIC" => GetMessage("CRM_DEMO_INVOCIE_2_SUBJ"), "STATUS_ID" => "N", "DATE_INSERT" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_BILL" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT'), "PAY_VOUCHER_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_PAY_BEFORE" => ConvertTimeStamp(time() + 8000009 + CTimeZone::GetOffset(), 'SHORT'), "RESPONSIBLE_ID" => 1, "UF_COMPANY_ID" => $arCompany["38"]['ID'], "PRODUCT_ROWS" => array(array("ID" => 0, "PRODUCT_ID" => $arProduct["ID"], "PRODUCT_NAME" => $arProduct["NAME"], "QUANTITY" => 1, "PRICE" => $arProduct["PRICE"])), "PERSON_TYPE_ID" => $personTypes["COMPANY"], "INVOICE_PROPERTIES" => array()); $paySystems = CCrmPaySystem::GetPaySystems($personTypes["COMPANY"]); foreach ($paySystems as $id => $paySystem) { $arFields["PAY_SYSTEM_ID"] = $id; } $arAllProps = CCrmInvoice::GetPropertiesInfo($personTypes["COMPANY"]); foreach ($arAllProps as $arProps) {
LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_LIST'], array('section_id' => isset($arResult['LIST_SECTION_ID']) ? $arResult['LIST_SECTION_ID'] : 0))); } } } } $productID = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0; if ($productID <= 0) { $productIDParName = isset($arParams['PRODUCT_ID_PAR_NAME']) ? strval($arParams['PRODUCT_ID_PAR_NAME']) : ''; if (strlen($productIDParName) == 0) { $productIDParName = 'product_id'; } $productID = isset($_REQUEST[$productIDParName]) ? intval($_REQUEST[$productIDParName]) : 0; } $product = array(); if ($productID > 0) { if (!($product = CCrmProduct::GetByID($productID, true))) { ShowError(GetMessage('CRM_PRODUCT_NOT_FOUND')); @define('ERROR_404', 'Y'); if ($arParams['SET_STATUS_404'] === 'Y') { CHTTP::SetStatus('404 Not Found'); } return; } } if (isset($productFields['NAME'])) { $product['NAME'] = $productFields['NAME']; } if (isset($productFields['DESCRIPTION'])) { $product['~DESCRIPTION'] = $productFields['DESCRIPTION']; $product['DESCRIPTION'] = htmlspecialcharsbx($productFields['DESCRIPTION']); }
function Fetch() { if (self::$catalogIncluded === false) { if (!CModule::IncludeModule('catalog')) { return false; } else { self::$catalogIncluded = true; } } if ($res = parent::Fetch()) { foreach ($this->arFieldAssoc as $k => $v) { if ($k !== $v && (isset($res[$k]) || array_key_exists($k, $res))) { $res[$v] = $res[$k]; unset($res[$k]); } } if (is_array($this->arAdditionalSelect) && count($this->arAdditionalSelect) > 0) { $priceInfo = null; $CCatalogProduct = new CCatalogProduct(); $catalogValues = false; if (in_array('PRICE', $this->arAdditionalSelect, true) || in_array('VAT_ID', $this->arAdditionalSelect, true) || in_array('VAT_INCLUDED', $this->arAdditionalSelect, true) || in_array('MEASURE', $this->arAdditionalSelect, true)) { $catalogValues = $CCatalogProduct->GetByID($res['ID']); } $bRequirePrice = in_array('PRICE', $this->arAdditionalSelect, true); $bRequireCurrency = in_array('CURRENCY_ID', $this->arAdditionalSelect, true); if ($bRequirePrice || $bRequireCurrency) { $arPrice = CCrmProduct::getPrice($res['ID']); $priceInfo = array('PRICE' => isset($arPrice['PRICE']) ? $arPrice['PRICE'] : null, 'CURRENCY' => isset($arPrice['CURRENCY']) ? $arPrice['CURRENCY'] : null); if ($bRequirePrice) { $res['PRICE'] = $priceInfo['PRICE']; } if ($bRequireCurrency) { $res['CURRENCY_ID'] = $priceInfo['CURRENCY']; } unset($arPrice); // recalculate price if (!$this->bRealPrice && self::$bVatMode && $catalogValues !== false) { if (isset($res['PRICE']) && isset($catalogValues['VAT_ID']) && isset($catalogValues['VAT_INCLUDED'])) { if ($catalogValues['VAT_INCLUDED'] !== 'Y') { if (isset(self::$arVatRates[$catalogValues['VAT_ID']])) { $vatRate = self::$arVatRates[$catalogValues['VAT_ID']]['RATE']; $res['PRICE'] = (doubleval($vatRate) / 100 + 1) * doubleval($res['PRICE']); } } } } } unset($bRequirePrice, $bRequireCurrency); foreach ($this->arAdditionalSelect as $field) { if ($field === 'ORIGINATOR_ID') { if (isset($res['XML_ID']) && !empty($res['XML_ID']) && $res['XML_ID'] !== '#' && isset($res['IBLOCK_ID']) && $res['IBLOCK_ID'] != CCrmProduct::getDefaultCatalogId()) { $delimiterPos = strpos($res['XML_ID'], '#'); if ($delimiterPos !== false) { $res['ORIGINATOR_ID'] = substr($res['XML_ID'], 0, $delimiterPos); } else { $res['ORIGINATOR_ID'] = $res['XML_ID']; } } else { $res['ORIGINATOR_ID'] = ''; } } elseif ($field === 'ORIGIN_ID') { if (isset($res['XML_ID']) && !empty($res['XML_ID']) && $res['XML_ID'] !== '#' && isset($res['IBLOCK_ID']) && $res['IBLOCK_ID'] != CCrmProduct::getDefaultCatalogId()) { $delimiterPos = strpos($res['XML_ID'], '#'); if ($delimiterPos !== false) { $res['ORIGIN_ID'] = substr($res['XML_ID'], $delimiterPos + 1); if ($res['ORIGIN_ID'] === false) { $res['ORIGIN_ID'] = ''; } } else { $res['ORIGIN_ID'] = ''; } } else { $res['ORIGIN_ID'] = ''; } } elseif ($field === 'VAT_ID' || $field === 'VAT_INCLUDED' || $field === 'MEASURE') { if ($field === 'VAT_ID') { $res['VAT_ID'] = $catalogValues !== false && isset($catalogValues['VAT_ID']) ? $catalogValues['VAT_ID'] : null; } if ($field === 'VAT_INCLUDED') { $res['VAT_INCLUDED'] = $catalogValues !== false && isset($catalogValues['VAT_INCLUDED']) ? $catalogValues['VAT_INCLUDED'] : null; } if ($field === 'MEASURE') { $res['MEASURE'] = $catalogValues !== false && isset($catalogValues['MEASURE']) ? $catalogValues['MEASURE'] : null; } } } } if (in_array('XML_ID', $this->arAdditionalSelect, true) && isset($res['XML_ID'])) { unset($res['XML_ID']); } } return $res; }
public static function GetProductName($arRow) { if (isset($arRow['PRODUCT_NAME']) && $arRow['PRODUCT_NAME'] !== '') { return $arRow['PRODUCT_NAME']; } $productID = isset($arRow['PRODUCT_ID']) ? (int) $arRow['PRODUCT_ID'] : 0; if ($productID > 0) { $rs = CCrmProduct::GetList(array(), array('ID' => $productID), array('NAME')); return ($ary = $rs->Fetch()) ? $ary['NAME'] : $productID; } return "[{$productID}]"; }
$uid = isset($arParams['UID']) ? $arParams['UID'] : ''; if (!isset($arParams['UID']) || $arParams['UID'] === '') { $uid = 'mobile_crm_product_row_edit'; } else { $uid = str_replace(array('#CONTEXT_ID#'), array($contextID), $uid); } $arResult['UID'] = $uid; $productID = $arParams['PRODUCT_ID'] = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0; if ($productID <= 0 && isset($_REQUEST['product_id'])) { $productID = intval($_REQUEST['product_id']); } $arResult['PRODUCT_ID'] = $productID; if ($productID <= 0) { $arResult['PRODUCT_NAME'] = ''; } else { $dbProduct = CCrmProduct::GetList(array(), array('=ID' => $productID), array('NAME')); $product = $dbProduct ? $dbProduct->Fetch() : null; $arResult['PRODUCT_NAME'] = is_array($product) && isset($product['NAME']) ? $product['NAME'] : $productID; } $currencyID = $arParams['CURRENCY_ID'] = isset($arParams['CURRENCY_ID']) ? $arParams['CURRENCY_ID'] : ''; if ($currencyID === '' && isset($_REQUEST['currency_id'])) { $currencyID = $_REQUEST['currency_id']; } if ($currencyID === '') { $currencyID = CCrmCurrency::GetBaseCurrencyID(); } $arResult['CURRENCY_ID'] = $currencyID; $price = $arParams['PRICE'] = isset($arParams['PRICE']) ? doubleval($arParams['PRICE']) : 0.0; if ($price <= 0 && isset($_REQUEST['price'])) { $price = doubleval($_REQUEST['price']); }
protected function prepareCrmSelectorItem($ufInfo) { /** @global CUser $USER */ global $USER; $result = false; $selectorItem = array(); if (!CModule::IncludeModule('crm')) { return $result; } $CCrmPerms = new CCrmPerms($USER->GetID()); $nPermittedEntityTypes = 0; if ($ufInfo['SETTINGS']['LEAD'] == 'Y' && !$CCrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'READ')) { $nPermittedEntityTypes++; } if ($ufInfo['SETTINGS']['CONTACT'] == 'Y' && !$CCrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'READ')) { $nPermittedEntityTypes++; } if ($ufInfo['SETTINGS']['COMPANY'] == 'Y' && !$CCrmPerms->HavePerm('COMPANY', BX_CRM_PERM_NONE, 'READ')) { $nPermittedEntityTypes++; } if ($ufInfo['SETTINGS']['DEAL'] == 'Y' && !$CCrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'READ')) { $nPermittedEntityTypes++; } if ($ufInfo['SETTINGS']['QUOTE'] == 'Y' && !$CCrmPerms->HavePerm('QUOTE', BX_CRM_PERM_NONE, 'READ')) { $nPermittedEntityTypes++; } if ($ufInfo['SETTINGS']['PRODUCT'] == 'Y' && $CCrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ')) { $nPermittedEntityTypes++; } $usePrefix = true; /*$nPermittedEntityTypes > 1;*/ // last 50 entity $entityTypes = array(); $elements = array(); $arSettings = $ufInfo['SETTINGS']; if (isset($arSettings['LEAD']) && $arSettings['LEAD'] == 'Y') { $entityTypes[] = 'lead'; $arSelect = array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID'); $obRes = CCrmLead::GetList(array('ID' => 'DESC'), array(), $arSelect, 50); $arFiles = array(); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $usePrefix ? 'L_' . $arRes['ID'] : $arRes['ID']; $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $arRes['FULL_NAME'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])), 'type' => 'lead', 'selected' => 'N'); } } if (isset($arSettings['CONTACT']) && $arSettings['CONTACT'] == 'Y') { $entityTypes[] = 'contact'; $arSelect = array('ID', 'FULL_NAME', 'COMPANY_TITLE', 'PHOTO'); $obRes = CCrmContact::GetList(array('ID' => 'DESC'), array(), $arSelect, 50); while ($arRes = $obRes->Fetch()) { $strImg = ''; if (!empty($arRes['PHOTO']) && !isset($arFiles[$arRes['PHOTO']])) { if ($arFile = CFile::GetFileArray($arRes['PHOTO'])) { $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT); if (is_array($arImg) && isset($arImg['src'])) { $strImg = CHTTP::URN2URI($arImg['src'], '', true); } } } $arRes['SID'] = $usePrefix ? 'C_' . $arRes['ID'] : $arRes['ID']; $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['FULL_NAME']), 'desc' => empty($arRes['COMPANY_TITLE']) ? '' : $arRes['COMPANY_TITLE'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID'])), 'image' => $strImg, 'type' => 'contact', 'selected' => 'N'); } } if (isset($arSettings['COMPANY']) && $arSettings['COMPANY'] == 'Y') { $entityTypes[] = 'company'; $arCompanyTypeList = CCrmStatus::GetStatusListEx('COMPANY_TYPE'); $arCompanyIndustryList = CCrmStatus::GetStatusListEx('INDUSTRY'); $arSelect = array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO'); $obRes = CCrmCompany::GetList(array('ID' => 'DESC'), array(), $arSelect, 50); $arFiles = array(); while ($arRes = $obRes->Fetch()) { $strImg = ''; if (!empty($arRes['LOGO']) && !isset($arFiles[$arRes['LOGO']])) { if ($arFile = CFile::GetFileArray($arRes['LOGO'])) { $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT); if (is_array($arImg) && isset($arImg['src'])) { $strImg = CHTTP::URN2URI($arImg['src'], '', true); } } $arFiles[$arRes['LOGO']] = $strImg; } $arRes['SID'] = $usePrefix ? 'CO_' . $arRes['ID'] : $arRes['ID']; $arDesc = array(); if (isset($arCompanyTypeList[$arRes['COMPANY_TYPE']])) { $arDesc[] = $arCompanyTypeList[$arRes['COMPANY_TYPE']]; } if (isset($arCompanyIndustryList[$arRes['INDUSTRY']])) { $arDesc[] = $arCompanyIndustryList[$arRes['INDUSTRY']]; } $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => implode(', ', $arDesc), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])), 'image' => $strImg, 'type' => 'company', 'selected' => 'N'); } } if (isset($arSettings['DEAL']) && $arSettings['DEAL'] == 'Y') { $entityTypes[] = 'deal'; $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE'); $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'); $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array(), $arSelect, 50); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $usePrefix ? 'D_' . $arRes['ID'] : $arRes['ID']; $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : ''; $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME']; $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => 'N'); } } if (isset($arSettings['QUOTE']) && $arSettings['QUOTE'] == 'Y') { $entityTypes[] = 'quote'; $arSelect = array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'); $obRes = CCrmQuote::GetList(array('ID' => 'DESC'), array(), false, array('nTopCount' => 50), array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME')); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $usePrefix ? 'Q_' . $arRes['ID'] : $arRes['ID']; $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : ''; $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME']; $quoteTitle = empty($arRes['TITLE']) ? $arRes['QUOTE_NUMBER'] : $arRes['QUOTE_NUMBER'] . ' - ' . $arRes['TITLE']; $elements[] = array('title' => empty($quoteTitle) ? '' : str_replace(array(';', ','), ' ', $quoteTitle), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $arRes['ID'])), 'type' => 'quote', 'selected' => 'N'); } } if (isset($arSettings['PRODUCT']) && $arSettings['PRODUCT'] == 'Y') { $entityTypes[] = 'product'; $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID'); $arPricesSelect = $arVatsSelect = array(); $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect); $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ACTIVE' => 'Y'), $arSelect, 50); $arProducts = $arProductId = array(); while ($arRes = $obRes->Fetch()) { foreach ($arPricesSelect as $fieldName) { $arRes[$fieldName] = null; } foreach ($arVatsSelect as $fieldName) { $arRes[$fieldName] = null; } $arProductId[] = $arRes['ID']; $arProducts[$arRes['ID']] = $arRes; } CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect); unset($arProductId, $arPricesSelect, $arVatsSelect); foreach ($arProducts as $arRes) { $arRes['SID'] = $usePrefix ? 'PROD_' . $arRes['ID'] : $arRes['ID']; $elements[] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => 'N'); } unset($arProducts); } $selectorItem['USER_TYPE_ID'] = $ufInfo['USER_TYPE_ID']; $selectorItem['ENTITY_ID'] = $ufInfo['ENTITY_ID']; $selectorItem['FIELD_NAME'] = $ufInfo['FIELD_NAME']; $selectorItem['PREFIX'] = $usePrefix ? 'Y' : 'N'; $selectorItem['MULTIPLE'] = 'Y'; //$ufInfo['MULTIPLE']; $selectorItem['ENTITY_TYPE'] = $entityTypes; $selectorItem['ELEMENT'] = $elements; $result = $selectorItem; return $result; }
protected function innerDelete($ID, &$errors) { if (!CCrmProduct::CheckDeletePermission($ID)) { $errors[] = 'Access denied.'; return false; } $result = CCrmProductSection::Delete($ID); if ($result !== true) { $errors[] = CCrmProductSection::GetLastError(); } return $result; }
$arPropertyValues[$arElement['ID']][$propID][] = call_user_func_array($arPropUserTypeList[$arProperty['USER_TYPE']]["GetPublicViewHTML"], array($arProps[$propID], array("VALUE" => $arProperty["VALUE"]), array())); } else { if ($arProperty["PROPERTY_TYPE"] == "L") { $arPropertyValues[$arElement['ID']][$propID][] = htmlspecialcharsex($arProperty["VALUE_ENUM"]); } else { $arPropertyValues[$arElement['ID']][$propID][] = htmlspecialcharsex($arProperty["VALUE"]); } } } unset($rsProperties, $arProperty, $propID); } } } $arResult['PROPERTY_VALUES'] = $arPropertyValues; unset($arPropertyValues); CCrmProduct::ObtainPricesVats($arResult['PRODUCTS'], $arProductId, $arPricesSelect, $arVatsSelect, isset($arFilter['~REAL_PRICE']) && $arFilter['~REAL_PRICE'] === true); $productMeasureInfos = \Bitrix\Crm\Measure::getProductMeasures($arProductId); if (!is_array($productMeasureInfos)) { $productMeasureInfos = array(); } $arResult['PRODUCT_MEASURE_INFOS'] = $productMeasureInfos; // <-- PRODUCTS $arResult['ROWS_COUNT'] = $obRes->SelectedRowsCount(); $arResult['NAV_OBJECT'] = $obRes; $arResult['BACK_URL_SECTION_ID'] = $bFilterSection ? $sectionID : ''; $this->IncludeComponentTemplate(); include_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/components/bitrix/crm.product/include/nav.php'; $result = array('ROWS_COUNT' => $arResult['ROWS_COUNT']); if ($bFilterSection) { $result['SECTION_ID'] = $sectionID; }
// page count $arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}"; $arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1; $productParams = array('CURRENCY_ID' => $currencyID, 'SECTIONS' => &$arResult['ALL_SECTIONS']); $arProducts = $arProductId = array(); while ($product = $dbProducts->GetNext()) { foreach ($arPricesSelect as $fieldName) { $product['~' . $fieldName] = $product[$fieldName] = null; } foreach ($arVatsSelect as $fieldName) { $product['~' . $fieldName] = $product[$fieldName] = null; } $arProductId[] = $product['ID']; $arProducts[$product['ID']] = $product; } CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect); unset($arProductId, $arPricesSelect, $arVatsSelect); foreach ($arProducts as &$product) { CCrmMobileHelper::PrepareProductItem($product, $productParams); $arResult['PRODUCTS'][] = $product; } unset($arProducts); $arResult['PRODUCT_SECTION_URL_TEMPLATE'] = $APPLICATION->GetCurPageParam("AJAX_CALL=Y&FORMAT=json&SECTION_ID=#section_id#", array('AJAX_CALL', 'FORMAT', 'SECTION_ID', 'SEARCH', 'PAGING', $arResult['PAGER_PARAM'])); $productSectionParams = array('PRODUCT_SECTION_URL_TEMPLATE' => $arResult['PRODUCT_SECTION_URL_TEMPLATE']); foreach ($arResult['SECTIONS'] as $sectionID => &$section) { CCrmMobileHelper::PrepareProductSectionItem($section, $productSectionParams); } unset($section); //NEXT_PAGE_URL, SEARCH_PAGE_URL, SERVICE_URL --> if ($arResult['PAGE_NEXT_NUMBER'] > $arResult['PAGE_NAVCOUNT']) { $arResult['NEXT_PAGE_URL'] = '';
public function Add($arFields, &$arRecalculated = false, $siteId = SITE_ID, $options = array()) { /** @global \CDatabase $DB */ global $DB; if (!CModule::IncludeModule('sale')) { return false; } if (!is_array($options)) { $options = array(); } $bRecalculate = is_array($arRecalculated); $orderID = false; $tmpOrderId = intval($arFields['ID']) <= 0 ? 0 : $arFields['ID']; if (isset($arFields['ID'])) { unset($arFields['ID']); } $arPrevOrder = $tmpOrderId !== 0 ? CCrmInvoice::GetByID($tmpOrderId) : null; $userId = CCrmSecurityHelper::GetCurrentUserID(); if (!isset($arFields['RESPONSIBLE_ID']) || (int) $arFields['RESPONSIBLE_ID'] <= 0) { if (is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) && intval($arPrevOrder['RESPONSIBLE_ID']) > 0) { $arFields['RESPONSIBLE_ID'] = $arPrevOrder['RESPONSIBLE_ID']; } else { $arFields['RESPONSIBLE_ID'] = $userId; } } $orderStatus = ''; if (isset($arFields['STATUS_ID'])) { $orderStatus = $arFields['STATUS_ID']; unset($arFields['STATUS_ID']); } // prepare entity permissions $arAttr = array(); if (!empty($arFields['OPENED'])) { $arAttr['OPENED'] = $arFields['OPENED']; } $sPermission = $tmpOrderId > 0 ? 'WRITE' : 'ADD'; if ($this->bCheckPermission) { $arEntityAttr = self::BuildEntityAttr($userId, $arAttr); $userPerms = $userId == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($userId); $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr); if ($sEntityPerm == BX_CRM_PERM_NONE) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); $GLOBALS['APPLICATION']->ThrowException($this->LAST_ERROR); return false; } $responsibleID = intval($arFields['RESPONSIBLE_ID']); if ($sEntityPerm == BX_CRM_PERM_SELF && $responsibleID != $userId) { $arFields['RESPONSIBLE_ID'] = $userId; } if ($sEntityPerm == BX_CRM_PERM_OPEN && $userId == $responsibleID) { $arFields['OPENED'] = 'Y'; } } $responsibleID = intval($arFields['RESPONSIBLE_ID']); $arEntityAttr = self::BuildEntityAttr($responsibleID, $arAttr); $userPerms = $responsibleID == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($responsibleID); $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr); $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm); // date fields if ($tmpOrderId === 0) { $arFields['~DATE_BILL'] = $DB->CharToDateFunction(isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '' ? $arFields['DATE_BILL'] : ConvertTimeStamp(time(), 'SHORT', SITE_ID), 'SHORT', false); } else { if (isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '') { $arFields['~DATE_BILL'] = $DB->CharToDateFunction($arFields['DATE_BILL'], 'SHORT', false); } } unset($arFields['DATE_BILL']); if (isset($arFields['DATE_PAY_BEFORE']) && $arFields['DATE_PAY_BEFORE'] !== '') { $arFields['~DATE_PAY_BEFORE'] = $DB->CharToDateFunction($arFields['DATE_PAY_BEFORE'], 'SHORT', false); } unset($arFields['DATE_PAY_BEFORE']); if ($tmpOrderId !== 0 && !isset($arFields['PRODUCT_ROWS']) && !isset($arFields['INVOICE_PROPERTIES'])) { if (!is_array($arPrevOrder)) { return false; } $prevResponsibleID = isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0; $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0; $prevStatusID = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; // simple update order fields $CSaleOrder = new CSaleOrder(); $orderID = $CSaleOrder->Update($tmpOrderId, $arFields); CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $tmpOrderId, $arFields); $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true; if (is_int($orderID) && $orderID > 0) { if ($registerSonetEvent) { $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0; $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0; $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0; $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0; $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0; $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0; $parents = array(); $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID; if ($parentsChanged) { if ($newDealID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID); } if ($newCompanyID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } if ($newContactID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID)); } if ($responsibleID !== $prevResponsibleID) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, $registerSonetEvent); } } } else { // check product rows if (!isset($arFields['PRODUCT_ROWS']) || !is_array($arFields['PRODUCT_ROWS']) || count($arFields['PRODUCT_ROWS']) <= 0) { return false; } $arProduct = $arFields['PRODUCT_ROWS']; // prepare shopping cart data // <editor-fold defaultstate="collapsed" desc="prepare shopping cart data ..."> // get xml_id fields $catalogXmlId = CCrmCatalog::GetDefaultCatalogXmlId(); $arNewProducts = array(); $bGetBasketXmlIds = false; foreach ($arProduct as &$productRow) { if (isset($productRow['ID']) && intval($productRow['ID']) === 0 && isset($productRow['PRODUCT_ID'])) { $arNewProducts[] = $productRow['PRODUCT_ID']; } else { $bGetBasketXmlIds = true; } } unset($productRow); $arXmlIds = array(); $oldProductRows = null; if ($bGetBasketXmlIds && intval($tmpOrderId) > 0) { $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId); if (count($oldProductRows) > 0) { foreach ($oldProductRows as $row) { $arXmlIds[intval($row['ID'])][$row['PRODUCT_ID']] = array('CATALOG_XML_ID' => $row['CATALOG_XML_ID'], 'PRODUCT_XML_ID' => $row['PRODUCT_XML_ID']); } unset($row); } } unset($bGetBasketXmlIds); if (count($arNewProducts) > 0) { $dbRes = CCrmProduct::GetList(array(), array('ID' => $arNewProducts), array('ID', 'XML_ID')); while ($row = $dbRes->Fetch()) { $arXmlIds[0][$row['ID']] = array('CATALOG_XML_ID' => $catalogXmlId, 'PRODUCT_XML_ID' => $row['XML_ID']); } unset($dbRes, $row); } unset($arNewProducts, $arOldProducts); // products without measures $productMeasures = array(); $productId = 0; $productIds = array(); foreach ($arProduct as $productRow) { $productId = intval($productRow['PRODUCT_ID']); if ($productId > 0 && (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE']) <= 0)) { $productIds[] = $productId; } } unset($productId, $productRow); if (count($productIds) > 0) { $productMeasures = \Bitrix\Crm\Measure::getProductMeasures($productIds); } unset($productIds); $currencyId = CCrmInvoice::GetCurrencyID($siteId); $i = 0; $defaultMeasure = null; $oldProductRowsById = null; foreach ($arProduct as &$productRow) { $productXmlId = $catalogXmlId = null; $rowIndex = intval($productRow['ID']); $productId = $productRow['PRODUCT_ID']; $isCustomized = isset($productRow['CUSTOMIZED']) && $productRow['CUSTOMIZED'] === 'Y'; $productRow['MODULE'] = $productRow['PRODUCT_PROVIDER_CLASS'] = ''; if ($productId > 0) { if (!$isCustomized) { $productRow['MODULE'] = 'catalog'; $productRow['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider'; } if (is_array($arXmlIds[$rowIndex]) && isset($arXmlIds[$rowIndex][$productId])) { $catalogXmlId = $arXmlIds[$rowIndex][$productId]['CATALOG_XML_ID']; $productXmlId = $arXmlIds[$rowIndex][$productId]['PRODUCT_XML_ID']; } $productRow['CATALOG_XML_ID'] = $catalogXmlId; $productRow['PRODUCT_XML_ID'] = $productXmlId; } else { $productRow["PRODUCT_XML_ID"] = "CRM-" . randString(8); $ri = new \Bitrix\Main\Type\RandomSequence($productRow["PRODUCT_XML_ID"]); $productRow["PRODUCT_ID"] = $ri->rand(1000000, 9999999); $productRow['CATALOG_XML_ID'] = ''; } if ($isCustomized) { $productRow['CUSTOM_PRICE'] = 'Y'; } if (isset($productRow['PRODUCT_NAME'])) { $productRow['NAME'] = $productRow['PRODUCT_NAME']; unset($productRow['PRODUCT_NAME']); } if (isset($productRow['PRICE'])) { $productRow['PRICE_DEFAULT'] = $productRow['PRICE']; } if (!isset($productRow['CURRENCY'])) { $productRow['CURRENCY'] = $currencyId; } // measures $bRefreshMeasureName = false; if (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE'] <= 0)) { if ($oldProductRows === null && $tmpOrderId > 0) { $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId); } if (is_array($oldProductRows) && count($oldProductRows) > 0 && $oldProductRowsById === null) { $oldProductRowsById = array(); foreach ($oldProductRows as $row) { $oldProductRowsById[intval($row['ID'])] = $row; } unset($row); } if (is_array($oldProductRowsById) && isset($oldProductRowsById[$rowIndex])) { $row = $oldProductRowsById[$rowIndex]; if (intval($productId) === intval($row['PRODUCT_ID'])) { if (isset($row['MEASURE_CODE'])) { $productRow['MEASURE_CODE'] = $row['MEASURE_CODE']; } if (isset($row['MEASURE_NAME'])) { $productRow['MEASURE_NAME'] = $row['MEASURE_NAME']; } else { $bRefreshMeasureName = true; } unset($row); } } } if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) { if ($productId > 0 && isset($productMeasures[$productId])) { $measure = is_array($productMeasures[$productId][0]) ? $productMeasures[$productId][0] : null; if (is_array($measure)) { if (isset($measure['CODE'])) { $productRow['MEASURE_CODE'] = $measure['CODE']; } if (isset($measure['SYMBOL'])) { $productRow['MEASURE_NAME'] = $measure['SYMBOL']; } } unset($measure); } } if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) { if ($defaultMeasure === null) { $defaultMeasure = \Bitrix\Crm\Measure::getDefaultMeasure(); } if (is_array($defaultMeasure)) { $productRow['MEASURE_CODE'] = $defaultMeasure['CODE']; $productRow['MEASURE_NAME'] = $defaultMeasure['SYMBOL']; } } if (isset($productRow['MEASURE_CODE']) && intval($productRow['MEASURE_CODE']) > 0 && ($bRefreshMeasureName || !array_key_exists('MEASURE_NAME', $productRow) || empty($productRow['MEASURE_NAME']))) { $measure = \Bitrix\Crm\Measure::getMeasureByCode($productRow['MEASURE_CODE']); if (is_array($measure) && isset($measure['SYMBOL'])) { $productRow['MEASURE_NAME'] = $measure['SYMBOL']; } unset($measure); } $i++; } unset($productRow, $productMeasures, $catalogXmlId, $productXmlId); $arOrderProductPrice = self::__fGetUserShoppingCart($arProduct, $siteId, 'N'); foreach ($arOrderProductPrice as &$arItem) { $arItem["ID_TMP"] = $arItem["ID"]; $arItem["NAME_TMP"] = $arItem["NAME"]; unset($arItem["ID"]); } unset($arItem); // user id for order $saleUserId = intval(CSaleUser::GetAnonymousUserID()); if ($saleUserId <= 0) { return false; } $arErrors = array(); $arShoppingCart = CSaleBasket::DoGetUserShoppingCart($siteId, $saleUserId, $arOrderProductPrice, $arErrors, array(), $tmpOrderId); if (!is_array($arShoppingCart) || count($arShoppingCart) === 0) { $GLOBALS['APPLICATION']->ThrowException(GetMessage('CRM_ERROR_EMPTY_INVOICE_SPEC')); return false; } foreach ($arShoppingCart as $key => &$arItem) { $arItem["ID"] = $arItem["ID_TMP"]; $arItem["NAME"] = $arItem["NAME_TMP"]; unset($arItem["NAME_TMP"], $arItem["ID_TMP"]); //$arShoppingCart[$key]["ID"] = $arItem["ID"]; } unset($key, $arItem); // </editor-fold> // person type $personTypeId = 0; if (!isset($arFields['PERSON_TYPE_ID']) || intval($arFields['PERSON_TYPE_ID']) <= 0) { $arPersonTypes = CCrmPaySystem::getPersonTypeIDs(); if (isset($arPersonTypes['CONTACT'])) { $personTypeId = intval($arPersonTypes['CONTACT']); } } else { $personTypeId = $arFields['PERSON_TYPE_ID']; } if ($personTypeId <= 0) { return false; } // preparing order to save // <editor-fold defaultstate="collapsed" desc="preparing order to save ..."> $arOrderPropsValues = array(); if (isset($arFields['INVOICE_PROPERTIES']) && is_array($arFields['INVOICE_PROPERTIES']) && count($arFields['INVOICE_PROPERTIES']) > 0) { $arOrderPropsValues = $arFields['INVOICE_PROPERTIES']; } if (isset($arFields['INVOICE_PROPERTIES'])) { unset($arFields['INVOICE_PROPERTIES']); } if (count($arOrderPropsValues) <= 0) { return false; } $deliveryId = null; $paySystemId = $arFields['PAY_SYSTEM_ID']; $arOptions = array('LOCATION_IN_CODES' => true); // let DoCalculateOrder know we send location in CODEs $arErrors = $arWarnings = array(); $CSaleOrder = new CSaleOrder(); $arOrder = $CSaleOrder->DoCalculateOrder($siteId, $saleUserId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, $arErrors, $arWarnings); if (count($arOrder) <= 0) { return false; } // </editor-fold> if ($bRecalculate) { foreach ($arOrder as $k => $v) { $arRecalculated[$k] = $v; } return true; } // merge order fields $arAdditionalFields = array(); foreach ($arFields as $k => $v) { if ($k === 'PRODUCT_ROWS') { continue; } $arAdditionalFields[$k] = $v; } $arOrder['LOCATION_IN_CODES'] = true; // let DoSaveOrder know we send location in IDs // saving order $arErrors = array(); $orderID = $CSaleOrder->DoSaveOrder($arOrder, $arAdditionalFields, $tmpOrderId, $arErrors); if (is_int($orderID) && $orderID > 0) { CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => $tmpOrderId === 0)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $orderID, $arFields); } if (is_int($orderID) && $orderID > 0 && isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true) { $prevResponsibleID = is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0; $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0; if ($tmpOrderId <= 0) { self::RegisterLiveFeedEvent($arFields, $orderID, $userId); if ($responsibleID > 0) { CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID); } } else { $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0; $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0; $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0; $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0; $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0; $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0; $parents = array(); $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID; if ($parentsChanged) { if ($newDealID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID); } if ($newCompanyID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } if ($newContactID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID)); if ($responsibleID !== $prevResponsibleID) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, true); } } } } if (intval($orderID) > 0 && !empty($orderStatus)) { // set status $this->SetStatus($orderID, $orderStatus); // update entity permissions CCrmPerms::UpdateEntityAttr('INVOICE', $orderID, $arEntityAttr); $newDealID = isset($arFields['UF_DEAL_ID']) ? (int) $arFields['UF_DEAL_ID'] : 0; $oldDealID = is_array($arPrevOrder) && isset($arPrevOrder['UF_DEAL_ID']) ? (int) $arPrevOrder['UF_DEAL_ID'] : 0; if ($newDealID) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($newDealID); } if ($oldDealID > 0 && $oldDealID !== $newDealID) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($oldDealID); } if (isset($options['UPDATE_SEARCH']) && $options['UPDATE_SEARCH'] === true) { $arFilterTmp = array('ID' => $orderID); if (!$this->bCheckPermission) { $arFilterTmp["CHECK_PERMISSIONS"] = "N"; } CCrmSearch::UpdateSearch($arFilterTmp, 'INVOICE', true); } } return $orderID; }
public static function OnIBlockElementDelete($ID) { return CCrmProduct::Delete($ID); }
$strLevel = substr($key, 11); if ($strLevel !== false && strlen($strLevel) > 0) { $sectionLevel = intval($strLevel); if ($sectionLevel > 0) { $sectionLevel--; $sectionName = $value; $arProductSections[$sectionLevel] = $sectionName; } unset($sectionName, $sectionLevel); } unset($strLevel, $arProduct[$key]); } } $arProduct['SECTION_ID'] = $sectionHelper->ImportSectionArray($arProductSections); if (!CCrmProduct::Add($arProduct)) { $err = CCrmProduct::GetLastError(); if (!isset($err[0])) { $err = GetMessage('CRM_PRODUCT_ADD_UNKNOWN_ERROR'); } $arResult['error']++; $arResult['error_data'][] = array('message' => $err, 'data' => $arProduct['__CSV_DATA__']); unset($err); } else { if (!empty($arProduct)) { $arResult['import']++; } } } $_SESSION['CRM_IMPORT_FILE_POS'] = $filePos; $_SESSION['CRM_IMPORT_FILE_FIRST_HEADER'] = false; Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
public static function Delete($ID) { if (!CModule::IncludeModule('catalog')) { return false; } self::$LAST_ERROR = ''; global $DB; $tableName = CCrmCatalog::TABLE_NAME; $ID = intval($ID); if (!is_array(self::GetByID($ID))) { // Is no exists return true; } $events = GetModuleEvents('crm', 'OnBeforeCrmCatalogDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { return false; } } $dbRes = CCrmProduct::GetList(array(), array('CATALOG_ID' => $ID), array('ID')); while ($arRes = $dbRes->Fetch()) { $productID = $arRes['ID']; if (!CCrmProduct::Delete($productID)) { self::RegisterError(sprintf('Deletion of CrmCatalog(ID=%d) is canceled. Could not delete CrmProduct(ID = %d).', $ID, $productID)); return false; } } if (!$DB->Query('DELETE FROM ' . $tableName . ' WHERE ID = ' . $ID, true)) { return false; } // -------------- remove from catalog module --------------> $CCatalog = new CCatalog(); if (!$CCatalog->Delete($ID)) { return false; } // <-------------- remove from catalog module -------------- CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID); $events = GetModuleEvents('crm', 'OnCrmCatalogDelete'); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } return true; }
if (strlen($dstCurrencyID) > 0 && strlen($srcCurrencyID) > 0 && $dstCurrencyID != $srcCurrencyID) { $arRes['PRICE'] = CCrmCurrency::ConvertMoney($arRes['PRICE'], $srcCurrencyID, $dstCurrencyID); $arRes['CURRENCY_ID'] = $dstCurrencyID; } $productID = $arRes['ID']; $customData = array('price' => $arRes['PRICE']); if (isset($measureInfos[$productID]) && !empty($measureInfos[$productID])) { $measureIfo = $measureInfos[$productID][0]; $customData['measure'] = array('code' => $measureIfo['CODE'], 'name' => $measureIfo['SYMBOL']); } elseif ($defaultMeasureInfo !== null) { $customData['measure'] = array('code' => $defaultMeasureInfo['CODE'], 'name' => $defaultMeasureInfo['SYMBOL']); } if (isset($productVatInfos[$productID])) { $productVatInfo = $productVatInfos[$productID]; $customData['tax'] = array('id' => $productVatInfo['TAX_ID'], 'included' => $enableRawPrices && $productVatInfo['TAX_INCLUDED']); } $arData[] = array('id' => $multi ? 'PROD_' . $arRes['ID'] : $arRes['ID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'type' => 'product', 'customData' => &$customData); unset($customData); if ($limit > 0 && ++$i === $limit) { break; } } unset($arProducts); Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); if ($bResultWithValue) { $arResponse = array('searchValue' => $_REQUEST['VALUE'], 'data' => $arData); echo CUtil::PhpToJsObject($arResponse); } else { echo CUtil::PhpToJsObject($arData); } die;
$arLead[$currentKey] = $result !== false ? $result : $data; } } elseif ($currentKey == 'CURRENCY_ID') { $currency = CCrmCurrency::GetByName($data); if (!$currency) { $currency = CCrmCurrency::GetByID($data); } $arLead[$currentKey] = $currency ? $currency['CURRENCY'] : CCrmCurrency::GetBaseCurrencyID(); } elseif ($currentKey == 'PRODUCT_ID') { // For compatibility $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $data); if (is_array($arProduct)) { $arProductRow = array('PRODUCT_ID' => $arProduct['ID'], 'QUANTITY' => 1); // PRICE equals to OPPORTUNITY. We will set PRICE latter } else { $arProduct = CCrmProduct::GetByName($data); if ($arProduct) { $arProductRow['PRODUCT_ID'] = $arProduct['ID']; } else { $arProductRow['PRODUCT_ID'] = 0; } $arProductRow['PRODUCT_NAME'] = $data; } } elseif ($currentKey == 'PRODUCT_PRICE') { // Process price only if product has been resolved if (isset($arProductRow['PRODUCT_ID'])) { $arProductRow['PRICE'] = doubleval($data); } } elseif ($currentKey == 'PRODUCT_QUANTITY') { // Process quntity only if product has been resolved if (isset($arProductRow['PRODUCT_ID'])) {
if (!$currency) { ShowError(GetMessage('CRM_CURRENCY_IS_NOT_FOUND', array('#CURRENCY_ID#' => $currencyID))); return; } $arResult['CURRENCY_FORMAT'] = CCrmCurrency::GetCurrencyFormatString($currencyID); //$exchRate = $arResult['EXCH_RATE'] = isset($arParams['EXCH_RATE']) ? (double)$arParams['EXCH_RATE'] : 1.0; //$arResult['CURRENCY_DISPLAY_NAME'] = $currency['ID']; //ID is ISO 4217 // Prepare source data if (isset($arParams['PRODUCT_ROWS']) && is_array($arParams['PRODUCT_ROWS'])) { $arResult['PRODUCT_ROWS'] = $arParams['PRODUCT_ROWS']; foreach ($arResult['PRODUCT_ROWS'] as &$arProdRow) { $productID = intval($arProdRow['PRODUCT_ID']); if (isset($arProdRow['PRODUCT_NAME'])) { continue; } $dbRes = CCrmProduct::GetList(array(), array('ID' => $productID), array('NAME')); $arProdRow['PRODUCT_NAME'] = is_array($arRes = $dbRes->Fetch()) ? $arRes['NAME'] : '[' . strval($productID) . ']'; } unset($arProdRow); } else { if ($arResult['INVOICE_MODE']) { $arResult['PRODUCT_ROWS'] = CCrmInvoice::GetProductRows($ownerID); } else { $arResult['PRODUCT_ROWS'] = $ownerID > 0 ? CCrmProductRow::LoadRows($ownerType, $ownerID) : array(); } } if ($bCopy) { foreach ($arResult['PRODUCT_ROWS'] as &$row) { if (isset($row['ID'])) { $row['ID'] = 0; }
} } $rsLeads = CCrmLead::GetListEx(array('ID' => 'ASC'), array("CHECK_PERMISSIONS" => "N"), false, false, array('ID', 'PRODUCT_ID', 'OPPORTUNITY', 'CURRENCY_ID')); while ($arLead = $rsLeads->Fetch()) { $ID = isset($arLead['ID']) ? intval($arLead['ID']) : 0; if ($ID <= 0) { continue; } $productID = isset($arLead['PRODUCT_ID']) ? $arLead['PRODUCT_ID'] : ''; if (isset($productID[0])) { $arProductRows = CCrmLead::LoadProductRows($ID); if (count($arProductRows) > 0) { // already converted continue; } $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $productID); if (!is_array($arProduct)) { continue; } $productID = isset($arProduct['ID']) ? $arProduct['ID'] : 0; if ($productID <= 0) { continue; } $arProductRows = array(array('PRODUCT_ID' => $productID, 'PRICE' => isset($arLead['OPPORTUNITY']) ? doubleval($arLead['OPPORTUNITY']) : 0.0, 'QUANTITY' => 1)); CCrmLead::SaveProductRows($ID, $arProductRows); } } COption::SetOptionString('crm', '~crm_11_0_6_convertion', 'Y'); } // <-- Convert LEAD CURRENCY and PRODUCT // Convert DEAL EVENTS -->
$arResult['LIST_SECTION_ID'] = isset($_REQUEST['list_section_id']) ? intval($_REQUEST['list_section_id']) : (isset($arParams['SECTION_ID']) ? intval($arParams['SECTION_ID']) : 0); $arParams['PATH_TO_PRODUCT_LIST'] = CrmCheckPath('PATH_TO_PRODUCT_LIST', $arParams['PATH_TO_PRODUCT_LIST'], '?#section_id#'); $arParams['PATH_TO_PRODUCT_SHOW'] = CrmCheckPath('PATH_TO_PRODUCT_SHOW', $arParams['PATH_TO_PRODUCT_SHOW'], '?product_id=#product_id#&show'); $arParams['PATH_TO_PRODUCT_EDIT'] = CrmCheckPath('PATH_TO_PRODUCT_EDIT', $arParams['PATH_TO_PRODUCT_EDIT'], '?product_id=#product_id#&edit'); $arParams['PATH_TO_PRODUCT_IMPORT'] = CrmCheckPath('PATH_TO_PRODUCT_IMPORT', $arParams['PATH_TO_PRODUCT_IMPORT'], $APPLICATION->GetCurPage() . '?import'); $arParams['PATH_TO_SECTION_LIST'] = CrmCheckPath('PATH_TO_SECTION_LIST', $arParams['PATH_TO_SECTION_LIST'], '?#section_id#§ions'); if (!isset($arParams['TYPE'])) { $arParams['TYPE'] = 'list'; } $arResult['BUTTONS'] = array(); $sectionID = isset($arParams['SECTION_ID']) ? intval($arParams['SECTION_ID']) : 0; $productID = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0; $CrmPerms = new CCrmPerms($USER->GetID()); $productAdd = $sectionAdd = $productEdit = $productDelete = $bImport = $CrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE'); $productShow = $sectionShow = $CrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ'); $exists = $productID > 0 && CCrmProduct::Exists($productID); if ($arParams['TYPE'] === 'sections') { $arSection = false; if ($sectionShow && $sectionID > 0) { $rsSection = CIBlockSection::GetList(array(), array('ID' => $sectionID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('ID', 'IBLOCK_SECTION_ID')); $arSection = $rsSection->Fetch(); } if ($arSection) { $parentSectionID = isset($arSection['IBLOCK_SECTION_ID']) ? intval($arSection['IBLOCK_SECTION_ID']) : 0; $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_MOVE_UP'), 'TITLE' => GetMessage('CRM_MOVE_UP_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_SECTION_LIST'], array('section_id' => $parentSectionID)), 'ICON' => 'btn-parent-section'); } if ($sectionAdd) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_ADD_PRODUCT_SECTION'), 'TITLE' => GetMessage('CRM_ADD_PRODUCT_SECTION_TITLE'), 'LINK' => "javascript:BX.CrmProductSectionManager.getDefault().addSection();", 'ICON' => 'btn-add-section'); } if ($productShow) { $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_PRODUCT_LIST'), 'TITLE' => GetMessage('CRM_PRODUCT_LIST_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_LIST'], array('section_id' => isset($arResult['LIST_SECTION_ID']) ? intval($arResult['LIST_SECTION_ID']) : 0)), 'ICON' => 'btn-list');
// Add Deal require_once "deal.demo.php"; $CCrmDeal = new CCrmDeal(); foreach ($arDeals as $ID => &$arParams) { $arProductRows = null; if (isset($arParams['PRODUCT_ROWS'])) { $arProductRows = $arParams['PRODUCT_ROWS']; unset($arParams['PRODUCT_ROWS']); } $arParams['CURRENCY_ID'] = $currencyID; $dealID = $CCrmDeal->Add($arParams); $arDeals[$ID]['ID'] = $dealID; if (is_array($arProductRows)) { foreach ($arProductRows as &$arProductRow) { $originID = $arProductRow['ORIGIN_ID']; $arProduct = CCrmProduct::GetByOriginID($originID, $catalogID); if (!is_array($arProduct)) { continue; } CCrmDeal::SaveProductRows($dealID, array(array('PRODUCT_ID' => intval($arProduct['ID']), 'PRICE' => doubleval($arProduct['PRICE']), 'QUANTITY' => 1))); } } } // Add event require_once "event.demo.php"; $CCrmEvent = new CCrmEvent(); foreach ($arEvents as $ID => $arParams) { $arEvents[$ID]['ID'] = $CCrmEvent->Add($arParams); } // Add relation $arParams = array('COMPANY_ID' => $arCompany['39']['ID'], 'CONTACT_ID' => $arContacts['51']['ID']);
<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } /** @var array $arParams */ /** @var array $arResult */ IncludeModuleLangFile(__FILE__); $priceTypeId = intval(CCrmProduct::getSelectedPriceTypeId()); $props = array(); if (is_array($arResult['PROPS'])) { foreach ($arResult['PROPS'] as $propIndex => $prop) { if ((!isset($prop['USER_TYPE']) || empty($prop['USER_TYPE']) || is_array($prop['PROPERTY_USER_TYPE']) && array_key_exists('GetPublicViewHTML', $prop['PROPERTY_USER_TYPE'])) && $prop['PROPERTY_TYPE'] !== 'G') { $props[intval($prop['~ID'])] =& $arResult['PROPS'][$propIndex]; } } } $arResult['PUBLIC_PROPS'] =& $props; function isPublicHeaderItem($headerId, $priceTypeId, &$propsInfo) { $headerId = trim(strval($headerId)); $priceTypeId = intval($priceTypeId); if ($headerId === '') { return false; } if (in_array($headerId, array('BALANCE', 'CODE', 'EXTERNAL_ID', 'SHOW_COUNTER', 'SHOW_COUNTER_START', 'EXPAND', 'PREVIEW_TEXT', 'QUANTITY', 'ACTION'), true)) { return false; } $matches = array(); if (preg_match('/^PRICE(\\d+)$/', $headerId, $matches)) { if ($priceTypeId !== intval($matches[1])) {