Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
byprice.php
1
<?php
2
namespace
Bitrix\Sale\Delivery\Restrictions
;
3
4
use \Bitrix\Main\Localization\Loc;
5
use
Bitrix\Sale\Delivery\Restrictions\Base
;
6
use
Bitrix\Sale\Internals\CollectableEntity
;
7
use
Bitrix\Sale\Internals\Entity
;
8
use
Bitrix\Sale\Services\Base\RestrictionManager
;
9
use
Bitrix\Sale\Shipment
;
10
11
Loc::loadMessages
(__FILE__);
12
18
class
ByPrice
extends
Base
19
{
20
public
static
function
getClassTitle
()
21
{
22
return
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PRICE_NAME"
);
23
}
24
25
public
static
function
getClassDescription
()
26
{
27
return
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PRICE_DESCRIPT"
);
28
}
29
30
public
static
function
check
($price, array $restrictionParams, $deliveryId = 0)
31
{
32
if
(empty($restrictionParams))
33
return
true
;
34
35
if
($price < 0)
36
return
true
;
37
38
$price = floatval($price);
39
40
if
(floatval($restrictionParams[
"MIN_PRICE"
]) > 0 && $price < floatval($restrictionParams[
"MIN_PRICE"
]))
41
$result =
false
;
42
elseif(floatval($restrictionParams[
"MAX_PRICE"
]) > 0 && $price > floatval($restrictionParams[
"MAX_PRICE"
]))
43
$result =
false
;
44
else
45
$result =
true
;
46
47
return
$result;
48
}
49
50
51
public
static
function
checkByEntity
(
Entity
$shipment, array $restrictionParams, $mode, $deliveryId = 0)
52
{
53
$severity = self::getSeverity($mode);
54
55
if
($severity ==
RestrictionManager::SEVERITY_NONE
)
56
return
RestrictionManager::SEVERITY_NONE
;
57
58
$price =
self::extractParams
($shipment);
59
$sCurrency = $shipment->getCurrency();
60
61
if
(!empty($sCurrency) && !empty($restrictionParams[
"CURRENCY"
]) && \
Bitrix
\Main\Loader::includeModule(
'currency'
))
62
{
63
$price = \CCurrencyRates::convertCurrency(
64
$price,
65
$sCurrency,
66
$restrictionParams[
"CURRENCY"
]
67
);
68
}
69
70
$res =
self::check
($price, $restrictionParams, $deliveryId);
71
return
$res ?
RestrictionManager::SEVERITY_NONE
: $severity;
72
}
73
74
protected
static
function
extractParams
(
Entity
$entity)
75
{
76
if
($entity instanceof
Shipment
)
77
{
78
if
(!$itemCollection = $entity->getShipmentItemCollection())
79
return
-1;
80
}
81
else
82
{
83
return
-1;
84
}
85
86
return
$itemCollection->getPrice();
87
}
88
89
public
static
function
getParamsStructure
($entityId = 0)
90
{
91
return
array(
92
"MIN_PRICE"
=> array(
93
"TYPE"
=>
"NUMBER"
,
94
"DEFAULT"
=>
"0"
,
95
'MIN'
=> 0,
96
"LABEL"
=>
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PRICE_MIN_PRICE"
)
97
),
98
99
"MAX_PRICE"
=> array(
100
"TYPE"
=>
"NUMBER"
,
101
"DEFAULT"
=>
"0"
,
102
'MIN'
=> 0,
103
"LABEL"
=>
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PRICE_MAX_PRICE"
)
104
),
105
106
"CURRENCY"
=> array(
107
"TYPE"
=>
"ENUM"
,
108
"DEFAULT"
=>
"RUB"
,
109
"LABEL"
=>
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PRICE_CURRECY"
),
110
"OPTIONS"
=> \
Bitrix
\
Sale
\
Delivery
\
Helper::getCurrenciesList
()
111
)
112
);
113
}
114
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Catalog\Product\Store\DistributionStrategy\Base
Definition
base.php:21
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sale\Delivery\ExtraServices\Base
Definition
base.php:10
Bitrix\Sale\Delivery\Helper\getCurrenciesList
static getCurrenciesList()
Definition
helper.php:26
Bitrix\Sale\Delivery\Restrictions\ByPrice
Definition
byprice.php:19
Bitrix\Sale\Delivery\Restrictions\ByPrice\extractParams
static extractParams(Entity $entity)
Definition
byprice.php:74
Bitrix\Sale\Delivery\Restrictions\ByPrice\getClassTitle
static getClassTitle()
Definition
byprice.php:20
Bitrix\Sale\Delivery\Restrictions\ByPrice\check
static check($price, array $restrictionParams, $deliveryId=0)
Definition
byprice.php:30
Bitrix\Sale\Delivery\Restrictions\ByPrice\checkByEntity
static checkByEntity(Entity $shipment, array $restrictionParams, $mode, $deliveryId=0)
Definition
byprice.php:51
Bitrix\Sale\Delivery\Restrictions\ByPrice\getClassDescription
static getClassDescription()
Definition
byprice.php:25
Bitrix\Sale\Delivery\Restrictions\ByPrice\getParamsStructure
static getParamsStructure($entityId=0)
Definition
byprice.php:89
Bitrix\Sale\Internals\CollectableEntity
Definition
collectableentity.php:14
Bitrix\Sale\Services\Base\RestrictionManager
Definition
restrictionmanager.php:20
Bitrix\Sale\Services\Base\RestrictionManager\SEVERITY_NONE
const SEVERITY_NONE
Definition
restrictionmanager.php:29
Bitrix\Sale\Services\PaySystem\Restrictions\Delivery
Definition
delivery.php:23
Bitrix\Sale\Shipment
Definition
shipment.php:21
Bitrix\Sale\Delivery\Restrictions
Definition
base.php:2
Bitrix
Sale
modules
sale
lib
delivery
restrictions
byprice.php
Создано системой
1.10.0