1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productdelivery.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\HtmlHelper;
10use Bitrix\Sale\Discount\Preset\Manager;
11use Bitrix\Sale\Discount\Preset\State;
12use Bitrix\Sale\Internals;
13
14class ProductDelivery extends Delivery
15{
16 public function getTitle()
17 {
18 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_PRODUCTDELIVERY_NAME');
19 }
20
21 public function getDescription()
22 {
23 return '';
24 }
25
29 public function getCategory()
30 {
31 return Manager::CATEGORY_DELIVERY;
32 }
33
34 public function processShowInputAmount(State $state)
35 {
36 $lid = $state->get('discount_lid');
37 $currency = Internals\SiteCurrencyTable::getSiteCurrency($lid);
38 $deliverySystems = $this->getDeliverySystems($lid);
39
40 $forSelectData = array();
41 foreach($deliverySystems as $id => $deliverySystem)
42 {
43 $forSelectData[$id] = $deliverySystem->getNameWithParent();
44 }
45 Main\Type\Collection::sortByColumn($forSelectData, 'NAME', '', null, true);
46
47 $sectionCount = count($state->get('discount_section', array()));
48
49 return '
50 <table width="100%" border="0" cellspacing="7" cellpadding="0">
51 <tbody>
52 ' . $this->renderDiscountValue($state, $currency) . '
53 <tr>
54 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_SHIPMENT_DELIVERY_LABEL') . ':</strong></td>
55 <td class="adm-detail-content-cell-r">
56 ' . HtmlHelper::generateMultipleSelect('discount_delivery[]', $forSelectData, $state->get('discount_delivery', array())) . '
57 </td>
58 </tr>
59 </tbody>
60 </table>
61
62 <script type="application/javascript">
63 BX.ready(function(){
64 new BX.Sale.Admin.DiscountPreset.SelectProduct({
65 presetId: "' . \CUtil::JSEscape($this->className()) . '",
66 siteId: "' . \CUtil::JSEscape($lid) . '",
67 sectionCount: ' . $sectionCount . ',
68 products: ' . \CUtil::PhpToJSObject($this->generateProductsData($state->get('discount_product'), $lid)) . '
69 });
70 });
71 </script>
72
73 ' . $this->renderElementBlock($state) . '
74 ' . $this->renderSectionBlock($state) . '
75 ';
76 }
77
78 public function processSaveInputAmount(State $state)
79 {
80 if(!trim($state->get('discount_value')))
81 {
82 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE'));
83 }
84
85 if(!$state->get('discount_delivery'))
86 {
87 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_DELIVERY'));
88 }
89
90 if(!$this->errorCollection->isEmpty())
91 {
92 return array($state, 'InputAmount');
93 }
94
95 return array($state, 'CommonSettings');
96 }
97
98 public function generateState(array $discountFields)
99 {
100 $discountFields = $this->normalizeDiscountFields($discountFields);
101
102 $stateFields = [
103 'discount_lid' => $discountFields['LID'],
104 'discount_name' => $discountFields['NAME'],
105 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
106 'discount_value' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Value'),
107 'discount_type' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Unit'),
108 'discount_delivery' => ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.0.DATA.value'),
109 'discount_section' => $this->getSectionsFromConditions(ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.1.CHILDREN.0.CHILDREN')),
110 'discount_product' => $this->getProductsFromConditions(ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.1.CHILDREN.1.CHILDREN')),
111 ];
112
113 return parent::generateState($discountFields)->append($stateFields);
114 }
115
116 public function generateDiscount(State $state)
117 {
118 $generateProductConditions = $this->generateProductConditions($state->get('discount_product'));
119 $generateSectionConditions = $this->generateSectionConditions($state->get('discount_section'));
120
121 return array_merge(
122 parent::generateDiscount($state),
123 [
124 'CONDITIONS' => [
125 'CLASS_ID' => 'CondGroup',
126 'DATA' => [
127 'All' => 'AND',
128 'True' => 'True',
129 ],
130 'CHILDREN' => [
131 [
132 'CLASS_ID' => 'CondSaleDelivery',
133 'DATA' => [
134 'logic' => 'Equal',
135 'value' => $state->get('discount_delivery'),
136 ],
137 ],
138 [
139 'CLASS_ID' => 'CondGroup',
140 'DATA' => [
141 'All' => 'OR',
142 'True' => 'True',
143 ],
144 'CHILDREN' => [
145 $generateSectionConditions? [
146 'CLASS_ID' => 'CondBsktProductGroup',
147 'DATA' => [
148 'Found' => 'Found',
149 'All' => 'OR',
150 ],
151 'CHILDREN' => $generateSectionConditions,
152 ] : [],
153 $generateProductConditions? [
154 'CLASS_ID' => 'CondBsktProductGroup',
155 'DATA' => [
156 'Found' => 'Found',
157 'All' => 'OR',
158 ],
159 'CHILDREN' => $generateProductConditions,
160 ] : [],
161 ],
162 ],
163 [
164 'CLASS_ID' => 'CondBsktCntGroup',
165 'DATA' => [
166 'logic' => 'Equal',
167 'Value' => 0,
168 'All' => 'OR',
169 ],
170 'CHILDREN' => array_merge(
171 $this->generateSectionConditions($state->get('discount_section'), 'Not'),
172 $this->generateProductConditions($state->get('discount_product'), 'Not')
173 ),
174 ],
175 ],
176 ],
177 'ACTIONS' => [
178 'CLASS_ID' => 'CondGroup',
179 'DATA' => [
180 'All' => 'AND',
181 ],
182 'CHILDREN' => [
183 [
184 'CLASS_ID' => 'ActSaleDelivery',
185 'DATA' => [
186 'Type' => $this->getTypeOfDiscount(),
187 'Value' => $state->get('discount_value'),
188 'Unit' => $state->get('discount_type', 'Cur'),
189 ],
190 ],
191 ],
192 ],
193 ]
194 );
195 }
196}
normalizeDiscountFields(array $discountFields)
Определения basepreset.php:608
getUserGroupsByDiscount($discountId)
Определения basepreset.php:703
getSectionsFromConditions(array $conditions=null)
Определения selectproductpreset.php:154
generateSectionConditions($sectionIds, $logic='Equal')
Определения selectproductpreset.php:201
generateProductsData($productIds, $siteId)
Определения selectproductpreset.php:293
renderSectionBlock(State $state, $inputName='discount_section', $multi=true)
Определения selectproductpreset.php:79
renderElementBlock(State $state, $inputName='discount_product', $multi=true)
Определения selectproductpreset.php:35
getProductsFromConditions(array $conditions=null)
Определения selectproductpreset.php:174
generateProductConditions($productIds, $logic='Equal')
Определения selectproductpreset.php:230
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
trait Error
Определения error.php:11
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$currency
Определения template.php:266