1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
catalogsettings.php
См. документацию.
1<?php
2
4
17use Bitrix\Crm\Integration\Sale\Reservation;
18use Bitrix\Intranet\Settings\AbstractSettings;
19use Bitrix\Intranet\Settings\SettingsInterface;
28
29Loader::includeModule('intranet');
30
31final class CatalogSettings extends AbstractSettings
32{
33 private const OPTION_DEFAULT_SUBSCRIBE = 'default_subscribe';
34 private const OPTION_DEFAULT_PRODUCT_VAT_INCLUDED = 'default_product_vat_included';
35 private const OPTION_DEFAULT_CAN_BUY_ZERO = 'default_can_buy_zero';
36 private const OPTION_DEFAULT_QUANTITY_TRACE = 'default_quantity_trace';
37 private const OPTION_PRODUCT_CARD_SLIDER_ENABLED = 'product_card_slider_enabled';
38
39 private const PRODUCT_SLIDER_HELP_LINK_EU = 'https://training.bitrix24.com/support/training/course/index.php?COURSE_ID=178&LESSON_ID=25692';
40 private const PRODUCT_SLIDER_HELP_LINK_RU = 'https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=48&LESSON_ID=25488';
41
42 public function save(): Result
43 {
44 $result = new Result();
45
46 if (Loader::includeModule('crm'))
47 {
48 if (is_array($this->data['reservationSettings']))
49 {
50 if (Manager::isOnecMode())
51 {
52 foreach ($this->data['reservationSettings'] as $entityCode => $reservationSettingsValue)
53 {
54 if (isset($reservationSettingsValue['autoWriteOffOnFinalize']))
55 {
56 Reservation\Config\EntityFactory::make($entityCode)
57 ->setValue(
58 'autoWriteOffOnFinalize',
59 $reservationSettingsValue['autoWriteOffOnFinalize'],
60 )
61 ->save()
62 ;
63 }
64 }
65 }
66 else
67 {
68 foreach ($this->data['reservationSettings'] as $entityCode => $reservationSettingsValue)
69 {
70 Reservation\Config\EntityFactory::make($entityCode)
71 ->setValues($reservationSettingsValue)
72 ->save()
73 ;
74 }
75 }
76 }
77 }
78
79 if (isset($this->data['checkRightsOnDecreaseStoreAmount']))
80 {
81 if ($this->data['checkRightsOnDecreaseStoreAmount'] === 'Y')
82 {
85 );
86 }
87 else
88 {
91 );
92 }
93 }
94
95 if (
96 !empty($this->data['costPriceCalculationMethod'])
99 )
100 {
101 CostPriceCalculator::setMethod($this->data['costPriceCalculationMethod']);
102 if (!StoreBatchTable::getRow(['select' => ['ID']]))
103 {
104 Stepper::bindClass(
105 '\Bitrix\Catalog\Update\ProductBatchConverter',
106 'catalog',
107 0
108 );
109 }
110 }
111
112 $catalogOptionSettings = [
113 'defaultQuantityTrace' => self::OPTION_DEFAULT_QUANTITY_TRACE,
114 'defaultCanBuyZero' => self::OPTION_DEFAULT_CAN_BUY_ZERO,
115 'defaultSubscribe' => self::OPTION_DEFAULT_SUBSCRIBE,
116 'defaultProductVatIncluded' => self::OPTION_DEFAULT_PRODUCT_VAT_INCLUDED,
117 ];
118
119 if ($this->canEnableProductCardSlider())
120 {
121 $catalogOptionSettings['productCardSliderEnabled'] = self::OPTION_PRODUCT_CARD_SLIDER_ENABLED;
122 }
123
124 if (isset($this->data['defaultProductVatId']))
125 {
126 $this->updateDefaultVat((int)$this->data['defaultProductVatId']);
127 }
128
129 foreach ($catalogOptionSettings as $key => $optionName)
130 {
131 if (!isset($this->data[$key]))
132 {
133 continue;
134 }
135
136 Option::set('catalog', $optionName, $this->data[$key]);
137 }
138
139 return $result;
140 }
141
142 public function get(): SettingsInterface
143 {
144 $data = [];
145
146 // reservation options
147 if (Loader::includeModule('crm'))
148 {
149 $data['reservationEntities'] = $this->getReservationEntities();
150 }
151
152 $accessController = AccessController::getCurrent();
153
154 $data = array_merge($data, [
155 'costPriceCalculationMethod' => $this->getCostPriceCalculationMethodSetting(),
156 // product options
157 'checkRightsOnDecreaseStoreAmount' => CheckRightsOnDecreaseStoreAmount::isEnabled() ? 'Y' : 'N',
158 'defaultQuantityTrace' => Option::get('catalog', self::OPTION_DEFAULT_QUANTITY_TRACE, 'N'),
159 'defaultSubscribe' => Option::get('catalog', self::OPTION_DEFAULT_SUBSCRIBE, 'Y'),
160 'defaultProductVatIncluded' => Option::get('catalog', self::OPTION_DEFAULT_PRODUCT_VAT_INCLUDED, 'N'),
161 'defaultCanBuyZero' => Option::get('catalog', self::OPTION_DEFAULT_CAN_BUY_ZERO, 'N'),
162 'productCardSliderEnabled' => Option::get('catalog', self::OPTION_PRODUCT_CARD_SLIDER_ENABLED, self::isBitrix24() ? 'Y' : 'N'),
163 'vats' => $this->getVats(),
164 'defaultProductVatId' => $this->getDefaultProductVatId() ?? 0,
165 // inventory management options
166 'isEnabledInventoryManagement' => State::isEnabledInventoryManagement(),
167 'storeControlMode' => Manager::getCurrentMode(),
168 'storeControlAvailableModes' => Manager::getAvailableModes(),
169 'hasConductedDocumentsOrQuantities' => ConditionsChecker::hasConductedDocumentsOrQuantities(),
170 'onecStatusUrl' => OnecAppManager::getStatusUrl(),
171 // access and misc. options
172 'canEnableProductCardSlider' => $this->canEnableProductCardSlider(),
173 'hasAccessToReservationSettings' => $accessController->check(ActionDictionary::ACTION_RESERVED_SETTINGS_ACCESS),
174 'hasAccessToCatalogSettings' => $accessController->check(ActionDictionary::ACTION_CATALOG_SETTINGS_ACCESS),
175 'isStoreBatchUsed' => Feature::isStoreBatchEnabled(),
176 'isBitrix24' => self::isBitrix24() ? 'Y' : 'N',
177 'isInventoryManagementRestricted' => !Feature::isInventoryManagementEnabled(),
179 'hasAccessToChangeCanBuyZero' => $accessController->check(ActionDictionary::ACTION_SELL_NEGATIVE_COMMODITIES_SETTINGS_EDIT),
180 'productsCount' => $this->getProductsCount(),
181 'busProductCardHelpLink' => self::getBusProductCardHelpLink(),
182 'configCatalogSource' => Context::getCurrent()->getRequest()->get('configCatalogSource'),
183 ]);
184
186 {
187 $negativeBalanceItem = StoreProductTable::getList([
188 'select' => ['ID'],
189 'filter' => [
190 '<AMOUNT' => 0,
191 ],
192 'limit' => 1,
193 ])
194 ->fetch()
195 ;
196
197 $data['showNegativeStoreAmountPopup'] = !empty($negativeBalanceItem);
198 if (!empty($negativeBalanceItem))
199 {
200 $productGridComponent = 'bitrix:catalog.report.store_stock.products.grid';
201 $productGridPath = \CComponentEngine::makeComponentPath($productGridComponent);
202
203 $data['storeBalancePopupLink'] = getLocalPath('components' . $productGridPath . '/slider.php');
204 }
205 }
206
207 return new self($data);
208 }
209
215 private function getDefaultProductVatId(): ?int
216 {
217 $defaultProductCatalogId = \Bitrix\Crm\Product\Catalog::getDefaultId();
218
219 if (!$defaultProductCatalogId)
220 {
221 return null;
222 }
223
224 $defaultProductCatalogInfo = ServiceContainer::getIblockInfo($defaultProductCatalogId);
225
226 return $defaultProductCatalogInfo?->getVatId();
227 }
228
234 private function getVats(): array
235 {
236 $currentVat = (int)$this->getDefaultProductVatId();
237 $vatList = [
238 [
239 'value' => 0,
240 'name' => Loc::getMessage("CATALOG_SETTINGS_VAT_NOT_SELECTED"),
241 'selected' => $currentVat === 0,
242 ],
243 ];
244 $hints = [
245 0 => Loc::getMessage('CATALOG_SETTINGS_VAT_HINT'),
246 ];
247
249 'select' => [
250 'ID',
251 'NAME',
252 ],
253 'filter' => [
254 '=ACTIVE' => 'Y',
255 ],
256 'order' => [
257 'SORT' => 'ASC',
258 'NAME' => 'ASC',
259 ]
260 ]);
261
262 while ($row = $iterator->fetch())
263 {
264 $vatList[] = [
265 'value' => $row['ID'],
266 'name' => htmlspecialcharsbx($row['NAME']),
267 'selected' => $currentVat === (int)$row['ID'],
268 ];
269
270 $hints[$row['ID']] = Loc::getMessage('CATALOG_SETTINGS_VAT_HINT');
271 }
272
273 unset($row, $iterator);
274
275 return [
276 'items' => $vatList,
277 'hints' => $hints,
278 'current' => $currentVat,
279 ];
280 }
281
282 private function getReservationEntities(): array
283 {
284 $result = [];
285
286 $reservationEntities = Reservation\Config\EntityFactory::makeAllKnown();
287 foreach ($reservationEntities as $reservationEntity)
288 {
289 $result[] = [
290 'code' => $reservationEntity::getCode(),
291 'name' => $reservationEntity::getName(),
292 'settings' => [
293 'scheme' => $reservationEntity::getScheme(),
294 'values' => $reservationEntity->getValues(),
295 ],
296 ];
297 }
298
299 return $result;
300 }
301
302 private function getCostPriceCalculationMethodSetting(): array
303 {
304 $currentMethod = CostPriceCalculator::getMethod();
305 $methodList = CostPriceCalculator::getMethodList();
306
307 return [
308 'items' => [
309 [
310 'value' => '',
311 'name' => Loc::getMessage('CATALOG_SETTINGS_CALCULATION_METHOD_NOT_SELECTED'),
312 'selected' => empty($currentMethod),
313 'disabled' => true,
314 'hidden' => true,
315 ],
316 [
317 'value' => CostPriceCalculator::METHOD_AVERAGE,
318 'name' => $methodList[CostPriceCalculator::METHOD_AVERAGE],
319 'selected' => $currentMethod === CostPriceCalculator::METHOD_AVERAGE,
320 ],
321 [
322 'value' => CostPriceCalculator::METHOD_FIFO,
323 'name' => $methodList[CostPriceCalculator::METHOD_FIFO],
324 'selected' => $currentMethod === CostPriceCalculator::METHOD_FIFO,
325 ],
326 ],
327 'hints' => [
328 CostPriceCalculator::METHOD_AVERAGE => Loc::getMessage('CATALOG_SETTINGS_CALCULATION_METHOD_AVERAGE_HINT'),
329 CostPriceCalculator::METHOD_FIFO => Loc::getMessage('CATALOG_SETTINGS_CALCULATION_METHOD_FIFO_HINT'),
330 ],
331 'current' => CostPriceCalculator::getMethod(),
332 ];
333 }
334
335 private function canEnableProductCardSlider(): bool
336 {
337 if (self::isBitrix24())
338 {
339 return Option::get('catalog', self::OPTION_PRODUCT_CARD_SLIDER_ENABLED) !== 'Y';
340 }
341
342 return true;
343 }
344
351 private function updateDefaultVat(int $defaultProductVatId): bool
352 {
353 try
354 {
355 $defaultProductCatalogId = \Bitrix\Crm\Product\Catalog::getDefaultId();
356 $updateResult = CatalogIblockTable::update(
357 $defaultProductCatalogId,
358 [
359 'VAT_ID' => $defaultProductVatId,
360 ]
361 );
362 } catch (\Exception)
363 {
364 return false;
365 }
366
367 if (!$updateResult->isSuccess())
368 {
369 return false;
370 }
371
372 return true;
373 }
374
375 private static function isBitrix24(): bool
376 {
377 static $isBitrix24Included;
378
379 if (!isset($isBitrix24Included))
380 {
381 $isBitrix24Included = Loader::includeModule('bitrix24');
382 }
383
384 return $isBitrix24Included;
385 }
386
387 private function getProductsCount(): int
388 {
389 $result = 0;
390
391 $catalogList = \CCatalogProductSettings::getCatalogList();
392 foreach ($catalogList as $catalog)
393 {
394 $result += $catalog['COUNT'];
395
396 }
397
398 return $result;
399 }
400
401 private static function getBusProductCardHelpLink(): string
402 {
403 if (self::isBitrix24())
404 {
405 return '';
406 }
407
408 if (in_array(Application::getInstance()->getLicense()->getRegion(), ['ru', 'by', 'kz'], true))
409 {
410 return self::PRODUCT_SLIDER_HELP_LINK_RU;
411 }
412
413 return self::PRODUCT_SLIDER_HELP_LINK_EU;
414 }
415}
$accessController
Определения options.php:23
$catalogList
Определения catalog_reindex.php:128
static isInventoryManagementEnabled()
Определения feature.php:148
static isStoreBatchEnabled()
Определения feature.php:230
static set(string $value)
Определения option.php:35
static isProductBatchMethodSelected()
Определения state.php:921
static isEnabledInventoryManagement()
Определения state.php:57
Определения vat.php:38
Определения loader.php:13
static getRow(array $parameters)
Определения datamanager.php:398
static getList(array $parameters=array())
Определения datamanager.php:431
static update($primary, array $data)
Определения datamanager.php:1256
static makeComponentPath($componentName)
Определения component_engine.php:81
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$catalog
Определения iblock_catalog_edit.php:135
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
Определения culture.php:9
if(empty($signedUserToken)) $key
Определения quickway.php:257
$optionName
Определения options.php:1735
$iterator
Определения yandex_run.php:610
$vatList
Определения yandex_run.php:916