Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
singlerefreshstrategy.php
1
<?php
2
3
namespace
Bitrix\Sale\Basket
;
4
5
use
Bitrix\Main\ArgumentNullException
;
6
use
Bitrix\Main\ObjectNotFoundException
;
7
use
Bitrix\Sale\BasketBase
;
8
9
class
SingleRefreshStrategy
extends
RefreshStrategy
10
{
11
public
function
__construct
(array
$data
=
null
)
12
{
13
parent::__construct(
$data
);
14
15
if
(empty($this->data[
'BASKET_ITEM'
]) && empty($this->data[
'BASKET_ITEM_CODE'
]))
16
{
17
throw
new
ArgumentNullException
(
'Parameters "BASKET_ITEM" or "BASKET_ITEM_CODE" should not be empty.'
);
18
}
19
}
20
21
protected
function
extractItem
(
BasketBase
$basket)
22
{
23
$basketItem =
null
;
24
25
if
(isset($this->data[
'BASKET_ITEM'
]) && $this->data[
'BASKET_ITEM'
] instanceof
BasketItem
)
26
{
27
$basketItem = $this->data[
'BASKET_ITEM'
];
28
}
29
elseif (!empty($this->data[
'BASKET_ITEM_CODE'
]))
30
{
31
$basketItem = $basket->
getItemByBasketCode
($this->data[
'BASKET_ITEM_CODE'
]);
32
}
33
34
return
$basketItem;
35
}
36
37
protected
function
getItemToRefresh
(
BasketBase
$basket)
38
{
39
$basketItem = $this->
extractItem
($basket);
40
if
($basketItem ===
null
)
41
{
42
throw
new
ObjectNotFoundException
(
'Entity "BasketItem" not found'
);
43
}
44
45
$basketRefreshStart = time();
46
$refreshGap
= $this->
getBasketRefreshGapTime
();
47
48
$basketItemLastRefresh = $this->getBasketItemRefreshTimestamp($basketItem);
49
if
($basketRefreshStart - $basketItemLastRefresh >=
$refreshGap
)
50
{
51
return
$basketItem;
52
}
53
54
return
null
;
55
}
56
57
protected
function
getProductData
(
BasketBase
$basket)
58
{
59
$itemToRefresh = $this->
getItemToRefresh
($basket);
60
61
$items = array();
62
if
(!empty($itemToRefresh))
63
{
64
$items[] = $itemToRefresh;
65
}
66
67
return
$this->
getProviderResult
($basket, $items);
68
}
69
}
Bitrix\Main\ArgumentNullException
Definition
exception.php:54
Bitrix\Main\ObjectNotFoundException
Definition
exception.php:203
Bitrix\Sale\Basket\BaseRefreshStrategy\$data
$data
Definition
baserefreshstrategy.php:24
Bitrix\Sale\Basket\BaseRefreshStrategy\$refreshGap
$refreshGap
Definition
baserefreshstrategy.php:25
Bitrix\Sale\Basket\BaseRefreshStrategy\getBasketRefreshGapTime
getBasketRefreshGapTime()
Definition
baserefreshstrategy.php:54
Bitrix\Sale\Basket\BaseRefreshStrategy\getProviderResult
getProviderResult(BasketBase $basket, $itemsToRefresh=array())
Definition
baserefreshstrategy.php:373
Bitrix\Sale\Basket\RefreshStrategy
Definition
refreshstrategy.php:12
Bitrix\Sale\Basket\SingleRefreshStrategy
Definition
singlerefreshstrategy.php:10
Bitrix\Sale\Basket\SingleRefreshStrategy\__construct
__construct(array $data=null)
Definition
singlerefreshstrategy.php:11
Bitrix\Sale\Basket\SingleRefreshStrategy\extractItem
extractItem(BasketBase $basket)
Definition
singlerefreshstrategy.php:21
Bitrix\Sale\Basket\SingleRefreshStrategy\getItemToRefresh
getItemToRefresh(BasketBase $basket)
Definition
singlerefreshstrategy.php:37
Bitrix\Sale\Basket\SingleRefreshStrategy\getProductData
getProductData(BasketBase $basket)
Definition
singlerefreshstrategy.php:57
Bitrix\Sale\BasketBase
Definition
basketbase.php:17
Bitrix\Sale\BasketBase\getItemByBasketCode
getItemByBasketCode($code)
Definition
basketbase.php:45
Bitrix\Sale\BasketItem
Definition
basketitem.php:27
Bitrix\Sale\Basket
Definition
baserefreshstrategy.php:3
modules
sale
lib
basket
singlerefreshstrategy.php
Создано системой
1.10.0