Bitrix-D7  20.5.0
sale/lib/configuration.php
См. документацию.
1 <?php
2 namespace Bitrix\Sale;
3 
7 
8 Loc::loadMessages(__FILE__);
9 
10 /**
11  * Class Configuration
12  * @package Bitrix\Sale
13  */
15 {
16  const RESERVE_ON_CREATE = 'O';
17  const RESERVE_ON_PAY = 'R';
18  const RESERVE_ON_FULL_PAY = 'P';
20  const RESERVE_ON_SHIP = 'S';
21  const ALLOW_DELIVERY_ON_PAY = 'R';
23  const STATUS_ON_PAY = 'R';
24  const STATUS_ON_FULL_PAY = 'P';
25 
26  /**
27  * Returns reservation condition list.
28  *
29  * @param bool $extendedMode Format mode.
30  * @return array
31  */
32  public static function getReservationConditionList($extendedMode = false)
33  {
34  $extendedMode = ($extendedMode === true);
35  if ($extendedMode)
36  {
37  return array(
38  self::RESERVE_ON_CREATE => Loc::getMessage('SALE_CONFIGURATION_RESERVE_ON_CREATE'),
39  self::RESERVE_ON_FULL_PAY => Loc::getMessage('SALE_CONFIGURATION_RESERVE_ON_FULL_PAY'),
40  self::RESERVE_ON_PAY => Loc::getMessage('SALE_CONFIGURATION_RESERVE_ON_PAY'),
41  self::RESERVE_ON_ALLOW_DELIVERY => Loc::getMessage('SALE_CONFIGURATION_RESERVE_ON_ALLOW_DELIVERY'),
42  self::RESERVE_ON_SHIP => Loc::getMessage('SALE_CONFIGURATION_RESERVE_ON_SHIP')
43  );
44  }
45  return array(
46  self::RESERVE_ON_CREATE,
47  self::RESERVE_ON_FULL_PAY,
48  self::RESERVE_ON_PAY,
49  self::RESERVE_ON_ALLOW_DELIVERY,
50  self::RESERVE_ON_SHIP
51  );
52  }
53 
54  /**
55  * Returns current reservation condition.
56  *
57  * @return string
58  * @throws \Bitrix\Main\ArgumentNullException
59  */
60  public static function getProductReservationCondition()
61  {
63  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
64 
65  return $optionClassName::get('sale', 'product_reserve_condition');
66  }
67 
68  /**
69  * Returns current clear reserve period.
70  *
71  * @return int
72  * @throws \Bitrix\Main\ArgumentNullException
73  */
74  public static function getProductReserveClearPeriod()
75  {
77  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
78 
79  return (int)$optionClassName::get('sale', 'product_reserve_clear_period');
80  }
81 
82  /**
83  * Check is current reservation with shipment.
84  *
85  * @return bool
86  */
87  public static function isReservationDependsOnShipment()
88  {
89  $condition = static::getProductReservationCondition();
90  return in_array($condition, array(static::RESERVE_ON_SHIP, static::RESERVE_ON_ALLOW_DELIVERY));
91  }
92 
93  /**
94  * Returns true, if current condition - delivery.
95  *
96  * @return bool
97  * @throws \Bitrix\Main\ArgumentNullException
98  */
99  public static function needShipOnAllowDelivery()
100  {
102  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
103 
104  return ((string)$optionClassName::get('sale', 'allow_deduction_on_delivery') === 'Y');
105  }
106 
107  /**
108  * Returns flag allow delivery on pay.
109  *
110  * @return bool
111  * @throws \Bitrix\Main\ArgumentNullException
112  */
113  public static function needAllowDeliveryOnPay()
114  {
115  $condition = static::getAllowDeliveryOnPayCondition();
116  return in_array($condition, array(static::ALLOW_DELIVERY_ON_PAY, static::RESERVE_ON_ALLOW_DELIVERY));
117  }
118 
119  /**
120  * @return string
121  * @throws \Bitrix\Main\ArgumentNullException
122  */
123  public static function getAllowDeliveryOnPayCondition()
124  {
126  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
127 
128  return $optionClassName::get('sale', 'status_on_change_allow_delivery_after_paid');
129  }
130 
131  /**
132  * @param bool $extendedMode
133  *
134  * @return array
135  */
136  public static function getAllowDeliveryAfterPaidConditionList($extendedMode = false)
137  {
138  if ($extendedMode)
139  {
140  return array(
141  self::ALLOW_DELIVERY_ON_PAY => Loc::getMessage('SALE_CONFIGURATION_ON_PAY'),
142  self::ALLOW_DELIVERY_ON_FULL_PAY => Loc::getMessage('SALE_CONFIGURATION_ON_FULL_PAY'),
143  );
144  }
145  return array(
146  self::ALLOW_DELIVERY_ON_PAY,
147  self::ALLOW_DELIVERY_ON_FULL_PAY,
148  );
149  }
150 
151  /**
152  * @return mixed
153  */
154  public static function getStatusPaidCondition()
155  {
157  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
158 
159  return $optionClassName::get('sale', 'status_on_paid_condition');
160  }
161 
162  /**
163  * @return mixed
164  */
165  public static function getStatusAllowDeliveryCondition()
166  {
168  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
169 
170  return $optionClassName::get('sale', 'status_on_paid_condition');
171  }
172 
173  /**
174  * Returns flag enable use stores.
175  *
176  * @return bool
177  */
178  public static function useStoreControl()
179  {
180  if (!Loader::includeModule('catalog'))
181  return false;
182 
184  }
185 
186  /**
187  * Returns flag use reservations.
188  *
189  * @return bool
190  * @throws \Bitrix\Main\ArgumentNullException
191  */
192  public static function isEnabledReservation()
193  {
195  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
196 
197  return ((string)$optionClassName::get('catalog', 'enable_reservation') === 'Y');
198  }
199 
200  /**
201  * Tells if allowed to calculate discount on basket separately.
202  * @return bool
203  */
204  public static function isAllowedSeparatelyDiscountCalculation()
205  {
207  $optionClassName = $registry->get(Registry::ENTITY_OPTIONS);
208 
209  return $optionClassName::get('sale', 'discount_separately_calculation') === 'Y';
210  }
211 }
static isUsedInventoryManagement()
Returns true if warehouse inventory management is allowed and enabled.
static includeModule($moduleName)
Includes a module by its name.
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
static getProductReserveClearPeriod()
Returns current clear reserve period.
static useStoreControl()
Returns flag enable use stores.
static isAllowedSeparatelyDiscountCalculation()
Tells if allowed to calculate discount on basket separately.
static getReservationConditionList($extendedMode=false)
Returns reservation condition list.
static getAllowDeliveryAfterPaidConditionList($extendedMode=false)
static isEnabledReservation()
Returns flag use reservations.
static needShipOnAllowDelivery()
Returns true, if current condition - delivery.
static needAllowDeliveryOnPay()
Returns flag allow delivery on pay.
static getProductReservationCondition()
Returns current reservation condition.
static isReservationDependsOnShipment()
Check is current reservation with shipment.