Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
singlerefreshstrategy.php
1<?php
2
3namespace Bitrix\Sale\Basket;
4
8
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();
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}
getProviderResult(BasketBase $basket, $itemsToRefresh=array())