Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketstorage.php
1<?php
2
3namespace Bitrix\Sale\UI;
4
7
9{
11 private static $instance = array();
13 protected $basket;
16
17 private $fUserId;
18 private $siteId;
19
20 private function __construct($fUserId, $siteId)
21 {
22 $this->fUserId = $fUserId;
23 $this->siteId = $siteId;
24 }
25
26 private function __clone()
27 {
28 }
29
30 protected static function getHash($fUserId, $siteId)
31 {
32 return "{$fUserId}_{$siteId}";
33 }
34
35 protected function getFUserId()
36 {
37 return $this->fUserId;
38 }
39
40 protected function getSiteId()
41 {
42 return $this->siteId;
43 }
44
45 public static function getInstance($fUserId, $siteId)
46 {
47 if (empty($fUserId))
48 {
49 throw new Main\ArgumentNullException('fUserId');
50 }
51
52 if (empty($siteId))
53 {
54 throw new Main\ArgumentNullException('siteId');
55 }
56
57 $hash = static::getHash($fUserId, $siteId);
58
59 if (!isset(static::$instance[$hash]))
60 {
61 static::$instance[$hash] = new static($fUserId, $siteId);
62 }
63
64 return static::$instance[$hash];
65 }
66
67 public function getBasket()
68 {
69 if (!isset($this->basket))
70 {
71 $this->basket = Sale\Basket::loadItemsForFUser($this->getFUserId(), $this->getSiteId());
72 }
73
74 return $this->basket;
75 }
76
77 public function getOrderableBasket()
78 {
79 if (!isset($this->orderableBasket))
80 {
82 $basketClone = $this->getBasket()->createClone();
83 $this->orderableBasket = $basketClone->getOrderableItems();
84 }
85
87 }
88}
static getHash($fUserId, $siteId)
static getInstance($fUserId, $siteId)