1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
paysystem.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\DiscountPreset;
4
5use Bitrix\Main;
6use Bitrix\Main\Error;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Discount\Preset\ArrayHelper;
9use Bitrix\Sale\Discount\Preset\BasePreset;
10use Bitrix\Sale\Discount\Preset\HtmlHelper;
11use Bitrix\Sale\Discount\Preset\Manager;
12use Bitrix\Sale\Discount\Preset\State;
13use Bitrix\Sale;
14
15class PaySystem extends BasePreset
16{
17 public function getTitle()
18 {
19 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_PAYSYSTEM_NAME');
20 }
21
22 public function getDescription()
23 {
24 return '';
25 }
26
30 public function getCategory()
31 {
32 return Manager::CATEGORY_PAYMENT;
33 }
34
35 public function getFirstStepName()
36 {
37 return 'InputName';
38 }
39
40 public function processShowInputName(State $state)
41 {
42 return $this->processShowInputNameInternal($state);
43 }
44
45 public function processSaveInputName(State $state)
46 {
47 return $this->processSaveInputNameInternal($state, 'InputAmount');
48 }
49
50 protected function getPaymentSystems()
51 {
52 $dbRes = Sale\PaySystem\Manager::getList(array(
53 'select' => array(
54 'ID',
55 'NAME',
56 'SORT',
57 'DESCRIPTION',
58 'ACTIVE',
59 'ACTION_FILE',
60 'LOGOTIP',
61 )
62 ));
63
64 $result = array();
65 while($paySystem = $dbRes->fetch())
66 {
67 $logoFileArray = \CFile::GetFileArray($paySystem['LOGOTIP']);
68 $paySystem['LOGOTIP'] = \CFile::ShowImage($logoFileArray, 100, 100, "border=0", "", false);
69
70 $result[$paySystem['ID']] = $paySystem;
71 }
72
73 return $result;
74 }
75
76 public function processShowInputAmount(State $state)
77 {
78 $lid = $state->get('discount_lid');
79 $currency = \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($lid);
80 $paymentSystems = $this->getPaymentSystems();
81
82 $forSelectData = array();
83 foreach($paymentSystems as $id => $paymentSystem)
84 {
85 $forSelectData[$id] = $paymentSystem['NAME'];
86 }
87 Main\Type\Collection::sortByColumn($forSelectData, 'NAME', '', null, true);
88
89 return '
90 <table width="100%" border="0" cellspacing="7" cellpadding="0">
91 <tbody>
92 <tr>
93 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . $this->getLabelDiscountValue() . ':</strong></td>
94 <td class="adm-detail-content-cell-r" style="width:60%;">
95 <input type="text" name="discount_value" value="' . htmlspecialcharsbx($state->get('discount_value')) . '" maxlength="100" style="width: 100px;"> <span>' . $currency . '</span>
96 </td>
97 </tr>
98 <tr>
99 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_PAYSYSTEM_PAYMENT_LABEL') . ':</strong></td>
100 <td class="adm-detail-content-cell-r">
101 ' . HtmlHelper::generateSelect('discount_payment', $forSelectData, $state->get('discount_payment')) . '
102 </td>
103 </tr>
104 </tbody>
105 </table>
106 ';
107 }
108
109 public function processSaveInputAmount(State $state)
110 {
111 if(!trim($state->get('discount_value')))
112 {
114 }
115
116 if(!$state->get('discount_payment'))
117 {
118 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_PAYMENT'));
119 }
120
121 if(!$this->errorCollection->isEmpty())
122 {
123 return array($state, 'InputAmount');
124 }
125
126 return array($state, 'CommonSettings');
127 }
128
129 public function processShowCommonSettings(State $state)
130 {
131 return $this->processShowCommonSettingsInternal($state);
132 }
133
134 public function processSaveCommonSettings(State $state)
135 {
136 return $this->processSaveCommonSettingsInternal($state);
137 }
138
139 public function generateState(array $discountFields)
140 {
141 $discountFields = $this->normalizeDiscountFields($discountFields);
142
143 $stateFields = [
144 'discount_lid' => $discountFields['LID'],
145 'discount_name' => $discountFields['NAME'],
146 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
147 'discount_value' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Value'),
148 'discount_type' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Unit'),
149 'discount_payment' => ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.0.DATA.value.0'),
150 ];
151
152 return parent::generateState($discountFields)->append($stateFields);
153 }
154
155 public function generateDiscount(State $state)
156 {
157 return array_merge(
158 parent::generateDiscount($state),
159 [
160 'CONDITIONS' => [
161 'CLASS_ID' => 'CondGroup',
162 'DATA' => [
163 'All' => 'AND',
164 'True' => 'True',
165 ],
166 'CHILDREN' => [
167 [
168 'CLASS_ID' => 'CondSalePaySystem',
169 'DATA' => [
170 'logic' => 'Equal',
171 'value' => [$state->get('discount_payment')],
172 ],
173 ],
174 ],
175 ],
176 'ACTIONS' => [
177 'CLASS_ID' => 'CondGroup',
178 'DATA' => [
179 'All' => 'AND',
180 ],
181 'CHILDREN' => [
182 [
183 'CLASS_ID' => 'ActSaleBsktGrp',
184 'DATA' => [
185 'Type' => $this->getTypeOfDiscount(),
186 'Value' => $state->get('discount_value'),
187 'Unit' => $state->get('discount_type', 'CurAll'),
188 'Max' => 0,
189 'All' => 'AND',
190 'True' => 'True',
191 ],
192 'CHILDREN' => [],
193 ],
194 ],
195 ],
196 ]
197 );
198 }
199}
normalizeDiscountFields(array $discountFields)
Определения basepreset.php:608
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
Определения basepreset.php:923
processSaveInputNameInternal(State $state, $nextStep)
Определения basepreset.php:811
processShowInputNameInternal(State $state)
Определения basepreset.php:789
processShowCommonSettingsInternal(State $state)
Определения basepreset.php:836
getUserGroupsByDiscount($discountId)
Определения basepreset.php:703
</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
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
trait Error
Определения error.php:11
$currency
Определения template.php:266
$dbRes
Определения yandex_detail.php:168