Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storage.php
1<?php
2
3namespace Bitrix\Sale\Basket;
4
7
8class Storage
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 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
72
74 $basketClassName = $registry->getBasketClassName();
75
76 $this->basket = $basketClassName::loadItemsForFUser($this->getFUserId(), $this->getSiteId());
77 }
78
79 return $this->basket;
80 }
81
82 public function getOrderableBasket()
83 {
84 if (!isset($this->orderableBasket))
85 {
87 $basketClone = $this->getBasket()->createClone();
88 $this->orderableBasket = $basketClone->getOrderableItems();
89 }
90
91 return $this->orderableBasket;
92 }
93}
static getHash($fUserId, $siteId)
Definition storage.php:30
static getInstance($fUserId, $siteId)
Definition storage.php:45