$arResult['FIELDS'] = array(); $arResult['FIELDS']['tab_1'][] = array('id' => 'product_info', 'name' => GetMessage('CRM_SECTION_PRODUCT_INFO'), 'type' => 'section'); if ($isEditMode) { $arResult['FIELDS']['tab_1'][] = array('id' => 'ID', 'name' => 'ID', 'params' => array('size' => 50), 'value' => $product['ID'], 'type' => 'label'); } $arResult['FIELDS']['tab_1'][] = array('id' => 'NAME', 'name' => GetMessage('CRM_FIELD_PRODUCT_NAME'), 'params' => array('size' => 50), 'type' => 'text', 'value' => isset($product['~NAME']) ? $product['~NAME'] : '', 'required' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'DESCRIPTION', 'name' => GetMessage('CRM_FIELD_PRODUCT_DESCRIPTION'), 'params' => array('size' => 50), 'type' => 'textarea', 'value' => isset($product['~DESCRIPTION']) ? $product['~DESCRIPTION'] : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'ACTIVE', 'name' => GetMessage('CRM_FIELD_ACTIVE'), 'type' => 'checkbox', 'params' => array(), 'value' => isset($product['ACTIVE']) ? $product['ACTIVE'] : ($isEditMode ? 'N' : 'Y')); $arResult['FIELDS']['tab_1'][] = array('id' => 'CURRENCY', 'name' => GetMessage('CRM_FIELD_CURRENCY'), 'type' => 'list', 'items' => CCrmCurrencyHelper::PrepareListItems(), 'value' => isset($product['CURRENCY_ID']) ? $product['CURRENCY_ID'] : $baseCurrencyID); $arResult['FIELDS']['tab_1'][] = array('id' => 'PRICE', 'name' => GetMessage('CRM_FIELD_PRICE'), 'type' => 'text', 'params' => array(), 'value' => isset($product['PRICE']) ? strval(round(doubleval($product['PRICE']), 2)) : ''); if ($bVatMode) { $arResult['FIELDS']['tab_1'][] = array('id' => 'VAT_ID', 'name' => GetMessage('CRM_FIELD_VAT_ID'), 'type' => 'list', 'items' => $arVatRatesListItems, 'value' => isset($product['VAT_ID']) ? $product['VAT_ID'] : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'VAT_INCLUDED', 'name' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'type' => 'checkbox', 'value' => isset($product['VAT_INCLUDED']) ? $product['VAT_INCLUDED'] : ''); } $arResult['FIELDS']['tab_1'][] = array('id' => 'MEASURE', 'name' => GetMessage('CRM_FIELD_MEASURE'), 'type' => 'list', 'items' => $arResult['MEASURE_LIST_ITEMS'], 'value' => isset($product['MEASURE']) ? $product['MEASURE'] : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'SECTION', 'name' => GetMessage('CRM_FIELD_SECTION'), 'type' => 'list', 'items' => CCrmProductHelper::PrepareSectionListItems($catalogID, true), 'value' => isset($product['SECTION_ID']) ? $product['SECTION_ID'] : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'SORT', 'name' => GetMessage('CRM_FIELD_SORT'), 'type' => 'text', 'params' => array(), 'value' => isset($product['SORT']) ? $product['SORT'] : '100'); $arFields = array('PREVIEW_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_PREVIEW_PICTURE'), 'DETAIL_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_DETAIL_PICTURE')); $html = ''; $obFileControl = $obFile = null; foreach ($arFields as $fieldID => $fieldName) { $obFile = new CCrmProductFile($arResult['PRODUCT_ID'], $fieldID, $product['~' . $fieldID]); $obFileControl = new CCrmProductFileControl($obFile, $fieldID); $html = $obFileControl->GetHTML(array('max_size' => 102400, 'max_width' => 150, 'max_height' => 150, 'url_template' => $arParams['PATH_TO_PRODUCT_FILE'], 'a_title' => GetMessage('CRM_PRODUCT_PROP_ENLARGE'), 'download_text' => GetMessage('CRM_PRODUCT_PROP_DOWNLOAD'))); $arResult['FIELDS']['tab_1'][] = array('id' => $fieldID, 'name' => $fieldName, 'type' => 'custom', 'value' => $html); } unset($arFields, $fieldID, $fieldName, $obFile, $obFileControl, $html); // Product properties $propsFormData = array(); foreach ($arProps as $propID => $arProp) { if (isset($arProp['USER_TYPE']) && !empty($arProp['USER_TYPE'])) {
// Prepare tax list if (!$arResult['VAT_MODE']) { $arResult['TAX_LIST'] = CCrmInvoice::getTaxList($ownerID); $arResult['TAX_LIST_PERCENT_PRECISION'] = SALE_VALUE_PRECISION; } // Prepare sum total $sumTotal = 0.0; foreach ($arResult['PRODUCT_ROWS'] as $row) { if (!isset($row['PRICE']) || !isset($row['QUANTITY'])) { continue; } $sumTotal += doubleval($row['PRICE']) * intval($row['QUANTITY']); } $arResult['TAX_VALUE'] = isset($arParams['TAX_VALUE']) ? $arParams['TAX_VALUE'] : 0.0; $arResult['SUM_TOTAL'] = isset($arParams['SUM_TOTAL']) ? $arParams['SUM_TOTAL'] : round($sumTotal, 2); $arResult['TAX_VALUE_WT'] = round(doubleval($arParams['SUM_TOTAL'] - doubleval($arParams['TAX_VALUE'])), 2); //SAVING MODE. ONSUBMIT: SAVE ALL PRODUCT ROWS ON SUBMIT, ONCHANGE: SAVE PRODUCT ROWS AFTER EVERY CHANGE (AJAX) $arResult['SAVING_MODE'] = isset($arParams['SAVING_MODE']) ? strtoupper($arParams['SAVING_MODE']) : 'ONSUBMIT'; if ($arResult['SAVING_MODE'] != 'ONSUBMIT' && $arResult['SAVING_MODE'] != 'ONCHANGE') { $arResult['SAVING_MODE'] = 'ONSUBMIT'; } $arResult['FORM_ID'] = isset($arParams['FORM_ID']) ? $arParams['FORM_ID'] : ''; $arResult['PREFIX'] = htmlspecialcharsbx($ownerID > 0 ? strtolower($ownerName) . '_' . strval($ownerID) : 'new_' . strtolower($ownerName)); $arResult['CONTAINER_CLASS'] = htmlspecialcharsbx(strtolower($ownerName) . '-product-rows'); $arResult['ROW_CLASS'] = ''; $arResult['PRODUCT_DATA_FIELD_NAME'] = isset($arParams['PRODUCT_DATA_FIELD_NAME']) ? $arParams['PRODUCT_DATA_FIELD_NAME'] : 'PRODUCT_ROW_DATA'; // crmProductCreateDialog dialog settings $bVatMode = CCrmTax::isVatMode(); $arResult['INVOICE_PRODUCT_CREATE_DLG_SETTINGS'] = array('url' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_EDIT'], array('product_id' => 0)), 'sessid' => bitrix_sessid(), 'messages' => array('dialogTitle' => GetMessage('CRM_PRODUCT_CREATE'), 'waitMessage' => GetMessage('CRM_PRODUCT_CREATE_WAIT'), 'ajaxError' => GetMessage('CRM_PRODUCT_CREATE_AJAX_ERR'), 'buttonCreateTitle' => GetMessage('CRM_BUTTON_CREATE_TITLE'), 'buttonCancelTitle' => GetMessage('CRM_BUTTON_CANCEL_TITLE'), 'NAME' => GetMessage('CRM_FIELD_NAME'), 'DESCRIPTION' => GetMessage('CRM_FIELD_DESCRIPTION'), 'ACTIVE' => GetMessage('CRM_FIELD_ACTIVE'), 'CURRENCY' => GetMessage('CRM_FIELD_CURRENCY'), 'PRICE' => GetMessage('CRM_FIELD_PRICE'), 'VAT_ID' => GetMessage('CRM_FIELD_VAT_ID'), 'VAT_INCLUDED' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'SECTION_ID' => GetMessage('CRM_FIELD_SECTION'), 'SORT' => GetMessage('CRM_FIELD_SORT')), 'fields' => array(array('textCode' => 'NAME', 'type' => 'text', 'maxLength' => 255, 'value' => '', 'skip' => 'N'), array('textCode' => 'DESCRIPTION', 'type' => 'textarea', 'maxLength' => 7500, 'value' => '', 'skip' => 'N'), array('textCode' => 'ACTIVE', 'type' => 'checkbox', 'value' => 'Y', 'skip' => 'N'), array('textCode' => 'CURRENCY', 'type' => 'select', 'value' => CCrmCurrency::GetBaseCurrencyID(), 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmCurrencyHelper::PrepareListItems()), 'skip' => 'N'), array('textCode' => 'PRICE', 'type' => 'text', 'maxLength' => 21, 'value' => '0.00', 'skip' => 'N'), array('textCode' => 'VAT_ID', 'type' => 'select', 'value' => '', 'items' => $bVatMode ? CCrmViewHelper::prepareSelectItemsForJS(CCrmVat::GetVatRatesListItems()) : null, 'skip' => $bVatMode ? 'N' : 'Y'), array('textCode' => 'VAT_INCLUDED', 'type' => 'checkbox', 'value' => 'N', 'skip' => $bVatMode ? 'N' : 'Y'), array('textCode' => 'SECTION_ID', 'type' => 'select', 'value' => '0', 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmProductHelper::PrepareSectionListItems(CCrmCatalog::EnsureDefaultExists())), 'skip' => 'N'), array('textCode' => 'SORT', 'type' => 'text', 'maxLength' => 11, 'value' => 100, 'skip' => 'N')), "ownerCurrencyId" => $currencyID); unset($bVatMode); $this->IncludeComponentTemplate();
} unset($arFields, $fieldID, $obFile, $obFileControl, $html, $fieldValue); $visibleFields = array(); $productFormOptions = CUserOptions::GetOption('main.interface.form', 'CRM_PRODUCT_EDIT', array()); if (is_array($productFormOptions) && is_array($productFormOptions['tabs']) && count($productFormOptions['tabs']) && (!isset($productFormOptions['settings_disabled']) || $productFormOptions['settings_disabled'] !== 'Y')) { $tabFound = false; $tab = null; foreach ($productFormOptions['tabs'] as $tab) { if (isset($tab['id']) && $tab['id'] === 'tab_1') { $tabFound = true; break; } } if ($tabFound) { if (is_array($tab) && is_array($tab['fields'])) { foreach ($tab['fields'] as $field) { if (isset($field['type']) && isset($field['id']) && $field['type'] !== 'section') { $visibleFields[] = $field['id']; } } } } } $arResult['PRODUCT_CREATE_DLG_VISIBLE_FIELDS'] = $visibleFields; unset($productFormOptions); $arResult['PRODUCT_CREATE_DLG_SETTINGS'] = array('formId' => 'crm_product_create_dialog_form', 'url' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_EDIT'], array('product_id' => 0)), 'sessid' => bitrix_sessid(), 'messages' => array('dialogTitle' => GetMessage('CRM_PRODUCT_CREATE'), 'waitMessage' => GetMessage('CRM_PRODUCT_CREATE_WAIT'), 'ajaxError' => GetMessage('CRM_PRODUCT_CREATE_AJAX_ERR'), 'buttonCreateTitle' => GetMessage('CRM_BUTTON_CREATE_TITLE'), 'buttonCancelTitle' => GetMessage('CRM_BUTTON_CANCEL_TITLE'), 'NAME' => GetMessage('CRM_FIELD_PRODUCT_NAME'), 'DESCRIPTION' => GetMessage('CRM_FIELD_DESCRIPTION'), 'ACTIVE' => GetMessage('CRM_FIELD_ACTIVE'), 'CURRENCY' => GetMessage('CRM_FIELD_CURRENCY'), 'PRICE' => GetMessage('CRM_FIELD_PRICE'), 'MEASURE' => GetMessage('CRM_FIELD_MEASURE'), 'VAT_ID' => GetMessage('CRM_FIELD_VAT_ID'), 'VAT_INCLUDED' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'SECTION' => GetMessage('CRM_FIELD_SECTION'), 'SORT' => GetMessage('CRM_FIELD_SORT'), 'PREVIEW_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_PREVIEW_PICTURE'), 'DETAIL_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_DETAIL_PICTURE')), 'fields' => array(array('textCode' => 'NAME', 'type' => 'text', 'maxLength' => 255, 'value' => '', 'skip' => 'N', 'required' => 'Y'), array('textCode' => 'DESCRIPTION', 'type' => 'textarea', 'maxLength' => 7500, 'value' => '', 'skip' => !CCrmProductHelper::IsFieldVisible('DESCRIPTION', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'ACTIVE', 'type' => 'checkbox', 'value' => 'Y', 'skip' => 'Y'), array('textCode' => 'CURRENCY', 'type' => 'select', 'value' => CCrmCurrency::GetBaseCurrencyID(), 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmCurrencyHelper::PrepareListItems()), 'skip' => !CCrmProductHelper::IsFieldVisible('CURRENCY', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'PRICE', 'type' => 'text', 'maxLength' => 21, 'value' => '0.00', 'skip' => !CCrmProductHelper::IsFieldVisible('PRICE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'MEASURE', 'type' => 'select', 'value' => '', 'items' => CCrmViewHelper::prepareSelectItemsForJS($measureListItems), 'skip' => !CCrmProductHelper::IsFieldVisible('MEASURE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'VAT_ID', 'type' => 'select', 'value' => '', 'items' => $arResult['ALLOW_TAX'] ? CCrmViewHelper::prepareSelectItemsForJS(CCrmVat::GetVatRatesListItems()) : null, 'skip' => $arResult['ALLOW_TAX'] ? !CCrmProductHelper::IsFieldVisible('VAT_ID', $visibleFields) ? 'Y' : 'N' : 'Y'), array('textCode' => 'VAT_INCLUDED', 'type' => 'checkbox', 'value' => 'N', 'skip' => $arResult['ALLOW_TAX'] ? !CCrmProductHelper::IsFieldVisible('VAT_INCLUDED', $visibleFields) ? 'Y' : 'N' : 'Y'), array('textCode' => 'SECTION', 'type' => 'select', 'value' => '0', 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmProductHelper::PrepareSectionListItems(CCrmCatalog::EnsureDefaultExists())), 'skip' => !CCrmProductHelper::IsFieldVisible('SECTION', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'SORT', 'type' => 'text', 'maxLength' => 11, 'value' => 100, 'skip' => 'Y'), array('textCode' => 'PREVIEW_PICTURE', 'type' => 'custom', 'value' => $htmlPreviewPictureValue, 'skip' => !CCrmProductHelper::IsFieldVisible('PREVIEW_PICTURE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'DETAIL_PICTURE', 'type' => 'custom', 'value' => $htmlDetailPictureValue, 'skip' => !CCrmProductHelper::IsFieldVisible('DETAIL_PICTURE', $visibleFields) ? 'Y' : 'N')), "ownerCurrencyId" => $currencyID); unset($visibleFields); $arResult['PRODUCT_PROPS_USER_TYPES'] = $arPropUserTypeList; $arResult['PRODUCT_PROPS'] = $arProps; /** @var CBitrixComponent $this */ $this->IncludeComponentTemplate();
$arSections['0'] = GetMessage('CRM_PRODUCT_LIST_FILTER_SECTION_ROOT'); $rsSections = CIBlockSection::GetList(array('left_margin' => 'asc'), array('IBLOCK_ID' => $catalogID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N')); while ($arSection = $rsSections->GetNext()) { $arResult['SECTION_LIST'][$arSection['ID']] = array('ID' => $arSection['ID'], 'NAME' => $arSection['~NAME'], 'LIST_URL' => str_replace('#section_id#', $arSection['ID'], $arResult['PAGE_URI_TEMPLATE'])); $arSections[$arSection['ID']] = str_repeat(' . ', $arSection['DEPTH_LEVEL']) . $arSection['~NAME']; } $arResult['FILTER'] = array(array('id' => 'ID', 'name' => GetMessage('CRM_COLUMN_ID'), 'type' => 'string', 'default' => true), array('id' => 'NAME', 'name' => GetMessage('CRM_COLUMN_NAME'), 'type' => 'string', 'default' => true), array('id' => 'LIST_SECTION_ID', 'name' => GetMessage('CRM_COLUMN_SECTION'), 'type' => 'list', 'default' => true, 'items' => $arSections, 'value' => '0'), array('id' => 'ACTIVE', 'name' => GetMessage('CRM_COLUMN_ACTIVE'), 'type' => 'list', 'items' => array('' => GetMessage('CRM_NOT_SELECTED'), 'Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO'))), array('id' => 'DESCRIPTION', 'name' => GetMessage('CRM_COLUMN_DESCRIPTION'))); $arResult['FILTER_PRESETS'] = array(); //} // Headers initialization --> $arResult['HEADERS'] = array(array('id' => 'ID', 'name' => GetMessage('CRM_COLUMN_ID'), 'sort' => 'id', 'default' => false, 'editable' => false), array('id' => 'NAME', 'name' => GetMessage('CRM_COLUMN_NAME'), 'sort' => 'name', 'default' => true, 'editable' => true, 'params' => array('size' => 45)), array('id' => 'PRICE', 'name' => GetMessage('CRM_COLUMN_PRICE'), 'default' => true, 'editable' => true), array('id' => 'MEASURE', 'name' => GetMessage('CRM_COLUMN_MEASURE'), 'default' => true, 'editable' => array('items' => $arResult['MEASURE_LIST_ITEMS']), 'type' => 'list')); if ($bVatMode) { $arResult['HEADERS'][] = array('id' => 'VAT_ID', 'name' => GetMessage('CRM_COLUMN_VAT_ID'), 'default' => true, 'editable' => array('items' => $arResult['VAT_RATE_LIST_ITEMS'], 'type' => 'list')); $arResult['HEADERS'][] = array('id' => 'VAT_INCLUDED', 'name' => GetMessage('CRM_COLUMN_VAT_INCLUDED'), 'default' => true, 'editable' => true, 'type' => 'checkbox'); } $arResult['HEADERS'] = array_merge($arResult['HEADERS'], array(array('id' => 'SECTION_ID', 'name' => GetMessage('CRM_COLUMN_SECTION'), 'default' => true, 'editable' => array('items' => CCrmProductHelper::PrepareSectionListItems($catalogID, true)), 'type' => 'list'), array('id' => 'SORT', 'name' => GetMessage('CRM_COLUMN_SORT'), 'sort' => 'sort', 'default' => false, 'editable' => true), array('id' => 'ACTIVE', 'name' => GetMessage('CRM_COLUMN_ACTIVE'), 'sort' => 'active', 'default' => false, 'editable' => true, 'type' => 'checkbox'), array('id' => 'DESCRIPTION', 'name' => GetMessage('CRM_COLUMN_DESCRIPTION'), 'sort' => 'description', 'default' => true, 'editable' => true), array('id' => 'PREVIEW_PICTURE', 'name' => GetMessage('CRM_PRODUCT_FIELD_PREVIEW_PICTURE'), 'sort' => 'preview_picture', 'default' => false, 'editable' => false), array('id' => 'DETAIL_PICTURE', 'name' => GetMessage('CRM_PRODUCT_FIELD_DETAIL_PICTURE'), 'sort' => 'detail_picture', 'default' => false, 'editable' => false))); // <-- Headers initialization // Product properties // <editor-fold defaultstate="collapsed" desc="Product properties"> $arPropUserTypeList = CCrmProductPropsHelper::GetPropsTypesByOperations(false, array('view', 'filter')); $arResult['PROP_USER_TYPES'] = $arPropUserTypeList; $arProps = CCrmProductPropsHelper::GetProps($catalogID, $arPropUserTypeList); $arResult['PROPS'] = $arProps; $arFilterable = array(); $arCustomFilter = array(); $arDateFilter = array(); CCrmProductPropsHelper::ListAddFilterFields($arPropUserTypeList, $arProps, $arResult['GRID_ID'], $arResult['FILTER'], $arFilterable, $arCustomFilter, $arDateFilter); CCrmProductPropsHelper::ListAddHeades($arPropUserTypeList, $arProps, $arResult['HEADERS']); // </editor-fold> $bTree = false; // check hit from section tree