Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
checkbox.php
1<?php
2
4
7
8Loc::loadMessages(__FILE__);
9
10class Checkbox extends Base
11{
12 public function __construct($id, array $structure, $currency, $value = null, array $additionalParams = array())
13 {
14 $structure["PARAMS"]["ONCHANGE"] = $this->createJSOnchange($id, $structure["PARAMS"]["PRICE"] ?? 0);
15 parent::__construct($id, $structure, $currency, $value, $additionalParams);
16 $this->params["TYPE"] = "Y/N";
17 }
18
19 public static function getClassTitle()
20 {
21 return Loc::getMessage("DELIVERY_EXTRA_SERVICE_CHECKBOX_TITLE");
22 }
23
24 public function getCost()
25 {
26 return
27 $this->value === 'Y'
28 ? (float)$this->getPrice()
29 : 0
30 ;
31 }
32
33 public static function getAdminParamsName()
34 {
35 return Loc::getMessage("DELIVERY_EXTRA_SERVICE_CHECKBOX_PRICE");
36 }
37
38 public static function prepareParamsToSave(array $params): array
39 {
40 $params['PARAMS']['PRICE'] ??= 0.0;
41 $params['PARAMS']['PRICE'] = (float)$params['PARAMS']['PRICE'];
42
43 return $params;
44 }
45 public static function getAdminParamsControl($name, array $params, $currency = "")
46 {
47 $currency = (string)$currency;
48
49 return
50 \Bitrix\Sale\Internals\Input\Manager::getEditHtml(
51 $name."[PARAMS][PRICE]",
52 [
53 "TYPE" => "NUMBER"
54 ],
55 $params["PARAMS"]["PRICE"] ?? 0
56 )
57 . ($currency !== '' ? ' (' . $currency . ')' : '')
58 ;
59 }
60
61 public function setOperatingCurrency($currency)
62 {
63 $this->params["ONCHANGE"] = $this->createJSOnchange($this->id, $this->getPrice());
64 parent::setOperatingCurrency($currency);
65 }
66
67 protected function createJSOnchange($id, $price)
68 {
69 $price = roundEx(floatval($price), SALE_VALUE_PRECISION);
70 return "BX.onCustomEvent('onDeliveryExtraServiceValueChange', [{'id' : '".$id."', 'value': this.checked, 'price': this.checked ? '".$price."' : '0'}]);";
71 }
72
76 public function getDisplayValue(): ?string
77 {
78 if ($this->value === 'Y')
79 {
80 return Loc::getMessage('DELIVERY_EXTRA_SERVICE_CHECKBOX_YES');
81 }
82
83 if ($this->value === 'N')
84 {
85 return Loc::getMessage('DELIVERY_EXTRA_SERVICE_CHECKBOX_NO');
86 }
87
88 return null;
89 }
90}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct($id, array $structure, $currency, $value=null, array $additionalParams=array())
Definition checkbox.php:12
static getAdminParamsControl($name, array $params, $currency="")
Definition checkbox.php:45
static prepareParamsToSave(array $params)
Definition checkbox.php:38