Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
emptydeliveryservice.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
18{
20 protected $handlerCode = 'BITRIX_EMPTY';
21
22 const CACHE_ID = 'BITRIX_SALE_EMPTY_DELIVERY_SRV_ID';
23 const TTL = 31536000;
24
28 public static function getClassTitle()
29 {
30 return Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_TITLE');
31 }
32
36 public static function getClassDescription()
37 {
38 return Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_DESC');
39 }
40
45 public static function getEmptyDeliveryServiceId()
46 {
47 $id = 0;
48 $cacheManager = Application::getInstance()->getManagedCache();
49
50 if($cacheManager->read(self::TTL, self::CACHE_ID))
51 $id = $cacheManager->get(self::CACHE_ID);
52
53 if ($id <= 0)
54 {
55 $data = Table::getRow(
56 array(
57 'select' => array('ID'),
58 'filter' => array('=CLASS_NAME' => '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService')
59 )
60 );
61 if ($data !== null)
62 $id = $data['ID'];
63 else
64 $id = self::create();
65
66 if ($id > 0)
67 $cacheManager->set(self::CACHE_ID, $id);
68 }
69
70 return (int)$id;
71 }
72
76 private static function create()
77 {
78 $fields["NAME"] = Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_TITLE');
79 $fields["CLASS_NAME"] = '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService';
80 $fields["PARENT_ID"] = 0;
81 $fields["CURRENCY"] = Currency\CurrencyManager::getBaseCurrency();
82 $fields["ACTIVE"] = "Y";
83 $fields["CONFIG"] = array('MAIN' => array('CURRENCY' => Currency\CurrencyManager::getBaseCurrency(), 'PRICE' => 0, 'PERIOD' => array('FROM' => 0,'TO' => 0,'TYPE' => 'D')));
84 $fields["SORT"] = 100;
85
86 $res = Table::add($fields);
87
88 if (!$res->isSuccess())
89 return 0;
90
91 ServiceRestrictionTable::add(array('SORT' => 100, 'SERVICE_ID' => $res->getId(), 'PARAMS' => array('PUBLIC_SHOW' => 'N'), 'SERVICE_TYPE' => '0', 'CLASS_NAME' => '\Bitrix\Sale\Delivery\Restrictions\ByPublicMode'));
92
93 return $res->getId();
94 }
95
96 public static function isHandlerCompatible()
97 {
98 return true;
99 }
100}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29