Bitrix-D7  20.5.0
emptydeliveryservice.php
См. документацию.
1 <?php
2 
4 
7 use Bitrix\Currency;
9 
10 Loc::loadMessages(__FILE__);
11 
12 /**
13  * Class EmptyDeliveryService
14  * @package Bitrix\Sale\Delivery\Services
15  */
16 
18 {
19  const CACHE_ID = 'BITRIX_SALE_EMPTY_DELIVERY_SRV_ID';
20  const TTL = 31536000;
21 
22  /**
23  * @return string Class title.
24  */
25  public static function getClassTitle()
26  {
27  return Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_TITLE');
28  }
29 
30  /**
31  * @return string Class, service description.
32  */
33  public static function getClassDescription()
34  {
35  return Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_DESC');
36  }
37 
38  /**
39  * @return int
40  * @throws \Bitrix\Main\ArgumentException
41  */
42  public static function getEmptyDeliveryServiceId()
43  {
44  $id = 0;
45  $cacheManager = Application::getInstance()->getManagedCache();
46 
47  if($cacheManager->read(self::TTL, self::CACHE_ID))
48  $id = $cacheManager->get(self::CACHE_ID);
49 
50  if ($id <= 0)
51  {
52  $data = Table::getRow(
53  array(
54  'select' => array('ID'),
55  'filter' => array('=CLASS_NAME' => '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService')
56  )
57  );
58  if ($data !== null)
59  $id = $data['ID'];
60  else
61  $id = self::create();
62 
63  if ($id > 0)
64  $cacheManager->set(self::CACHE_ID, $id);
65  }
66 
67  return $id;
68  }
69 
70  /**
71  * @return int
72  */
73  private static function create()
74  {
75  $fields["NAME"] = Loc::getMessage('SALE_DLVR_HANDL_EMP_DLV_SRV_TITLE');
76  $fields["CLASS_NAME"] = '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService';
77  $fields["PARENT_ID"] = 0;
78  $fields["CURRENCY"] = Currency\CurrencyManager::getBaseCurrency();
79  $fields["ACTIVE"] = "Y";
80  $fields["CONFIG"] = array('MAIN' => array('CURRENCY' => Currency\CurrencyManager::getBaseCurrency(), 'PRICE' => 0, 'PERIOD' => array('FROM' => 0,'TO' => 0,'TYPE' => 'D')));
81  $fields["SORT"] = 100;
82 
83  $res = Table::add($fields);
84 
85  if (!$res->isSuccess())
86  return 0;
87 
88  ServiceRestrictionTable::add(array('SORT' => 100, 'SERVICE_ID' => $res->getId(), 'PARAMS' => array('PUBLIC_SHOW' => 'N'), 'SERVICE_TYPE' => '0', 'CLASS_NAME' => '\Bitrix\Sale\Delivery\Restrictions\ByPublicMode'));
89 
90  return $res->getId();
91  }
92 
93  public static function isHandlerCompatible()
94  {
95  return true;
96  }
97 }
static getBaseCurrency()
Return base currency.
Base class for any application.
static getInstance()
Returns current instance of the Application.
static loadMessages($file)
Loads language messages for specified file in a lazy way.
Definition: loc.php:67
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29