Configuring Price List Generation in 1C-Bitrix
A price list is more than a price export. For a B2B client it is a document with current prices for their specific price type, including SKUs, stock levels, and discounts. Automatic price list generation from 1C-Bitrix eliminates manual update errors and gives managers always-current data.
Formats and Tools
Price lists are generated in three formats:
Excel (XLSX) — the most in-demand format. Uses the PhpSpreadsheet library (phpoffice/phpspreadsheet). Supports formatting, formulas, and multiple sheets.
CSV — a simple option for machine processing, without formatting.
PDF — for sending to clients as a presentation document (see the PDF catalog article).
Generating Excel with PhpSpreadsheet
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class BitrixPriceListGenerator
{
public function generate(int $priceTypeId, array $userGroups): string
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Price List');
// Headers
$headers = ['SKU', 'Name', 'Category', 'Price', 'Currency', 'Stock'];
foreach ($headers as $col => $header) {
$sheet->setCellValueByColumnAndRow($col + 1, 1, $header);
}
// Header style
$sheet->getStyle('A1:F1')->getFont()->setBold(true);
$sheet->getStyle('A1:F1')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('FFE0E0E0');
$row = 2;
$res = $this->getProductsWithPrices($priceTypeId, $userGroups);
foreach ($res as $product) {
$sheet->setCellValueByColumnAndRow(1, $row, $product['ARTICLE']);
$sheet->setCellValueByColumnAndRow(2, $row, $product['NAME']);
$sheet->setCellValueByColumnAndRow(3, $row, $product['SECTION']);
$sheet->setCellValueByColumnAndRow(4, $row, $product['PRICE']);
$sheet->setCellValueByColumnAndRow(5, $row, $product['CURRENCY']);
$sheet->setCellValueByColumnAndRow(6, $row, $product['QUANTITY']);
// Price number formatting
$sheet->getStyleByColumnAndRow(4, $row)
->getNumberFormat()
->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
$row++;
}
// Auto-fit column widths
foreach (range('A', 'F') as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
// Add generation date
$sheet->setCellValue('A' . ($row + 1), 'Generated: ' . date('d.m.Y H:i'));
$writer = new Xlsx($spreadsheet);
$tempFile = tempnam(sys_get_temp_dir(), 'pricelist_');
$writer->save($tempFile);
return $tempFile;
}
private function getProductsWithPrices(int $priceTypeId, array $userGroups): array
{
$result = [];
$dbRes = \CIBlockElement::GetList(
['SECTION_ID' => 'ASC', 'SORT' => 'ASC'],
['IBLOCK_ID' => CATALOG_IBLOCK_ID, 'ACTIVE' => 'Y'],
false,
false,
['ID', 'NAME', 'IBLOCK_SECTION_ID', 'PROPERTY_ARTICLE']
);
$sectionCache = [];
while ($el = $dbRes->GetNextElement()) {
$fields = $el->GetFields();
$productId = $fields['ID'];
// Get price for the type
$priceRes = \CCatalogProduct::GetOptimalPrice($productId, 1, $userGroups);
$price = $priceRes['PRICE']['PRICE'] ?? 0;
// Cache section names
$sectionId = $fields['IBLOCK_SECTION_ID'];
if (!isset($sectionCache[$sectionId])) {
$sectionCache[$sectionId] = \CIBlockSection::GetByID($sectionId)->GetNext()['NAME'] ?? '';
}
// Stock levels
$storeData = \CCatalogStoreProduct::GetList(
[], ['PRODUCT_ID' => $productId]
)->Fetch();
$quantity = $storeData['AMOUNT'] ?? 0;
$result[] = [
'ARTICLE' => $fields['PROPERTY_ARTICLE_VALUE'],
'NAME' => $fields['NAME'],
'SECTION' => $sectionCache[$sectionId],
'PRICE' => $price,
'CURRENCY' => $priceRes['PRICE']['CURRENCY'] ?? 'USD',
'QUANTITY' => $quantity,
];
}
return $result;
}
}
Access Control and Price List Differentiation
Different client types receive different price lists. Access is controlled via user groups and price types:
// Determine the price list type for the current user
$userId = \Bitrix\Main\Context::getCurrent()->getUser()->getId();
$userGroups = \CUser::GetUserGroup($userId);
$priceTypeId = 1; // base
if (in_array(WHOLESALE_GROUP_ID, $userGroups)) {
$priceTypeId = 2; // wholesale
} elseif (in_array(VIP_GROUP_ID, $userGroups)) {
$priceTypeId = 3; // VIP
}
Scheduled Auto-Generation
For large catalogs (10,000+ items), generation is moved to a 1C-Bitrix agent that runs nightly and saves the file to /upload/pricelists/:
// Agent added via AddEventHandler or manually in b_agent
function GeneratePriceLists(): string
{
$generator = new BitrixPriceListGenerator();
foreach (getPriceTypes() as $type) {
$file = $generator->generate($type['ID'], $type['USER_GROUPS']);
$targetPath = '/upload/pricelists/pricelist_' . $type['CODE'] . '.xlsx';
rename($file, $_SERVER['DOCUMENT_ROOT'] . $targetPath);
}
return __FUNCTION__ . '();'; // Agent returns itself for re-scheduling
}
Timeline
| Configuration | Timeline |
|---|---|
| Simple CSV price list for one price type | 0.5–1 day |
| Excel with formatting, multiple price types | 2–3 days |
| Scheduled auto-generation + personal account integration | 3–5 days |







