Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
priceprovider.php
1<?php
2
4
8
10{
11 private const PREFIX_PRICE_COLUMN_ID = 'PRICE_';
12 private const PREFIX_CURRENCY_COLUMN_ID= 'CURRENCY_';
13
14 public function prepareColumns(): array
15 {
16 $result = [];
17
18 $editable = false;
19 foreach (Catalog\GroupTable::getTypeList() as $priceType)
20 {
21 $priceTypeId = (int)$priceType['ID'];
22 $columnId = static::getPriceTypeColumnId($priceTypeId);
23
24 $result[$columnId] = [
25 'type' => Grid\Column\Type::MONEY,
26 'name' => $priceType['NAME_LANG'] ?? $priceType['NAME'],
27 'necessary' => false,
28 'editable' => $editable ?: new Grid\Column\Editable\MoneyConfig($columnId),
29 'multiple' => false,
30 'sort' => 'SCALED_PRICE_' . $priceTypeId,
31 'align' => 'right',
32 'select' => [
33 self::getPriceTypeColumnId($priceTypeId),
34 self::getCurrencyPriceTypeId($priceTypeId),
35 ],
36 ];
37 }
38
39 return $this->createColumns($result);
40 }
41
42 public static function parsePriceTypeId(string $columnId): ?int
43 {
44 $prefix = preg_quote(self::PREFIX_PRICE_COLUMN_ID);
45 $re = "/^{$prefix}(\d+)$/";
46
47 if (preg_match($re, $columnId, $m))
48 {
49 return (int)$m[1];
50 }
51
52 return null;
53 }
54
55 public static function getPriceTypeColumnId(int $priceTypeId): string
56 {
57 return self::PREFIX_PRICE_COLUMN_ID . $priceTypeId;
58 }
59
60 public static function getCurrencyPriceTypeId(int $priceTypeId)
61 {
62 return self::PREFIX_CURRENCY_COLUMN_ID . $priceTypeId;
63 }
64
65 protected function allowPriceEdit(): bool
66 {
67 return
68 $this->allowProductEdit()
69 && $this->accessController->check(Access\ActionDictionary::ACTION_PRICE_EDIT)
70 ;
71 }
72}
static getPriceTypeColumnId(int $priceTypeId)
static getCurrencyPriceTypeId(int $priceTypeId)
static parsePriceTypeId(string $columnId)