3namespace Sale\Handlers\DiscountPreset;
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\SelectProductPreset;
12use Bitrix\Sale\Discount\Preset\State;
16 public function getTitle()
18 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_DELIVERY_NAME');
21 public function getDescription()
29 public function getCategory()
31 return Manager::CATEGORY_DELIVERY;
34 public function getFirstStepName()
39 public function processShowInputName(State $state)
44 public function processSaveInputName(State $state)
54 protected function getDeliverySystems(
$siteId)
59 'SITES' =>
'RESTRICTION_BY_SITE.PARAMS',
63 '!=CLASS_NAME' =>
array(
64 '\Bitrix\Sale\Delivery\Services\Group',
65 '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService',
69 'RESTRICTION_BY_SITE' =>
array(
70 'data_type' =>
'Bitrix\Sale\Internals\ServiceRestrictionTable',
72 'ref.SERVICE_ID' =>
'this.ID',
73 'ref.SERVICE_TYPE' =>
array(
75 \Bitrix\Sale\Delivery\Restrictions\Manager::SERVICE_TYPE_SHIPMENT,
77 'ref.CLASS_NAME' =>
array(
'?',
'\Bitrix\Sale\Delivery\Restrictions\BySite'),
79 'join_type' =>
'left',
85 $dbResultList = \Bitrix\Sale\Delivery\Services\Table::getList($parameters);
86 while(
$service = $dbResultList->fetch())
97 $deliveryService = \Bitrix\Sale\Delivery\Services\Manager::createObject(
$service);
98 if (!$deliveryService || $deliveryService->canHasProfiles() || $deliveryService->canHasChildren())
109 protected function getLabelDiscountValue()
111 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_DELIVERY_DELIVERY_DISCOUNT_VALUE');
114 public function processShowInputAmount(State $state)
116 $lid = $state->get(
'discount_lid');
117 $currency = \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($lid);
118 $deliverySystems = $this->getDeliverySystems($lid);
120 $forSelectData =
array();
121 foreach($deliverySystems as $id => $deliverySystem)
123 $forSelectData[$id] = $deliverySystem->getNameWithParent();
125 Main\Type\Collection::sortByColumn($forSelectData,
'NAME',
'',
null,
true);
128 <table width="100%" border="0" cellspacing="7" cellpadding="0">
131 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_SHIPMENT_DELIVERY_ORDER_AMOUNT') .
':</strong></td>
132 <td class="adm-detail-content-cell-r" style="width:60%;">
133 <input type="text" name="discount_order_amount" value="' .
htmlspecialcharsbx($state->get(
'discount_order_amount')) .
'" size="39" maxlength="100" style="width: 100px;"> <span>' .
$currency .
'</span>
135 </tr>' . $this->renderDiscountValue($state,
$currency) .
'
137 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_SHIPMENT_DELIVERY_LABEL') .
':</strong></td>
138 <td class="adm-detail-content-cell-r">
139 ' . HtmlHelper::generateSelect(
'discount_delivery', $forSelectData, $state->get(
'discount_delivery')) .
'
147 protected function renderDiscountValue(State $state,
$currency)
151 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . $this->getLabelDiscountValue() .
':</strong></td>
152 <td class="adm-detail-content-cell-r" style="width:60%;">
153 <input type="text" name="discount_value" value="' .
htmlspecialcharsbx($state->get(
'discount_value')) .
'" maxlength="100" style="width: 100px;"> '
154 . HtmlHelper::generateSelect(
'discount_type',
array(
155 'Perc' => Loc::getMessage(
'SHD_BT_SALE_ACT_GROUP_BASKET_SELECT_PERCENT'),
157 ), $state->get(
'discount_type')) .
'
163 public function processSaveInputAmount(State $state)
165 if(!trim($state->get(
'discount_value')))
167 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE'));
170 if(!trim($state->get(
'discount_order_amount')))
172 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_ORDER_AMOUNT'));
175 if((
int)$state->get(
'discount_delivery') < 0)
177 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_DELIVERY'));
180 if(!$this->errorCollection->isEmpty())
182 return array($state,
'InputAmount');
185 return array($state,
'CommonSettings');
188 public function processShowCommonSettings(State $state)
193 public function processSaveCommonSettings(State $state)
198 public function generateState(
array $discountFields)
203 'discount_lid' => $discountFields[
'LID'],
204 'discount_name' => $discountFields[
'NAME'],
206 'discount_value' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Value'),
207 'discount_type' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Unit'),
208 'discount_order_amount' => ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.0.DATA.Value'),
209 'discount_delivery' => ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.1.DATA.value.0'),
212 return parent::generateState($discountFields)->append($stateFields);
215 public function generateDiscount(State $state)
217 return array_merge(parent::generateDiscount($state),
array(
218 'CONDITIONS' =>
array(
219 'CLASS_ID' =>
'CondGroup',
226 'CLASS_ID' =>
'CondBsktAmtGroup',
229 'Value' => $state->get(
'discount_order_amount'),
232 'CHILDREN' =>
array(),
235 'CLASS_ID' =>
'CondSaleDelivery',
238 'value' =>
array((
int)$state->get(
'discount_delivery')),
244 'CLASS_ID' =>
'CondGroup',
250 'CLASS_ID' =>
'ActSaleDelivery',
253 'Value' => $state->get(
'discount_value'),
254 'Unit' => $state->get(
'discount_type',
'Cur'),
normalizeDiscountFields(array $discountFields)
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
processSaveInputNameInternal(State $state, $nextStep)
processShowInputNameInternal(State $state)
processShowCommonSettingsInternal(State $state)
getUserGroupsByDiscount($discountId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)