21 private const STORE_LIMIT = 10;
22 private const ENTITY_ID =
'store';
26 $this->options[
'searchDisabledStores'] =
$options[
'searchDisabledStores'] ??
true;
27 $this->options[
'useAddressAsTitle'] =
$options[
'useAddressAsTitle'] ??
true;
28 $this->options[
'productId'] = (int)(
$options[
'productId'] ?? 0);
30 if ($this->options[
'productId'] > 0)
33 'filter' => [
'=ID' => $this->options[
'productId']],
34 'select' => [
'MEASURE']
37 $this->options[
'measureSymbol'] = $this->getMeasureSymbol((
int)$product[
'MEASURE']);
41 $this->options[
'measureSymbol'] =
'';
44 parent::__construct();
47 private function getMeasureSymbol(
int $measureId =
null): string
49 $measureResult = \CCatalogMeasure::getList(
50 array(
'CODE' =>
'ASC'),
54 array(
'CODE',
'SYMBOL_RUS',
'SYMBOL_INTL',
'IS_DEFAULT',
'ID')
58 while ($measureFields = $measureResult->Fetch())
60 $symbol = $measureFields[
'SYMBOL_RUS'] ?? $measureFields[
'SYMBOL_INTL'];
61 if ($measureId === (
int)$measureFields[
'ID'])
66 if ($measureFields[
'IS_DEFAULT'] ===
'Y')
77 return $this->
getOptions()[
'searchDisabledStores'];
82 return $this->
getOptions()[
'useAddressAsTitle'];
92 return $GLOBALS[
"USER"]->IsAuthorized();
97 return $this->getStores([
'ID' => $ids]);
102 return $this->getStores([
'=ID' => $ids]);
112 '%ADDRESS' => $query,
116 $items = $this->getStores($filter);
133 $recentItemsCount = count($dialog->
getRecentItems()->getEntityItems(self::ENTITY_ID));
135 if ($recentItemsCount < self::STORE_LIMIT)
137 foreach ($this->getStores() as $store)
144 private function getStores(array $filter = []): array
146 $allowedStores = AccessController::getCurrent()->getPermissionValue(ActionDictionary::ACTION_STORE_VIEW);
147 if (empty($allowedStores))
152 if (!in_array(PermissionDictionary::VALUE_VARIATION_ALL, $allowedStores,
true))
154 $filter[
'=ID'] = $allowedStores;
157 $filter[
'=ACTIVE'] =
'Y';
164 'select' => [
'STORE_ID',
'AMOUNT',
'QUANTITY_RESERVED'],
167 while ($storeProduct = $storeProductRaw->fetch())
169 $storeProducts[$storeProduct[
'STORE_ID']] = [
170 'RESERVED' => $storeProduct[
'QUANTITY_RESERVED'],
171 'AMOUNT' => $storeProduct[
'AMOUNT'],
176 $storeRaw = StoreTable::getList([
177 'select' => [
'ID',
'TITLE',
'ADDRESS',
'IMAGE_ID'],
182 while ($store = $storeRaw->fetch())
184 $store[
'PRODUCT_AMOUNT'] = 0;
185 if (isset($storeProducts[$store[
'ID']]))
187 $store[
'PRODUCT_AMOUNT'] = $storeProducts[$store[
'ID']][
'AMOUNT'];
188 $store[
'PRODUCT_RESERVED'] = $storeProducts[$store[
'ID']][
'RESERVED'];
191 if ($store[
'IMAGE_ID'] !==
null)
193 $store[
'IMAGE_ID'] = (int)$store[
'IMAGE_ID'];
194 if ($store[
'IMAGE_ID'] <= 0)
196 $store[
'IMAGE_ID'] =
null;
200 $store[
'IMAGE_ID'] !==
null
201 ? $this->getImageSource($store[
'IMAGE_ID'])
212 static function ($first, $second)
214 return ($first[
'PRODUCT_AMOUNT'] > $second[
'PRODUCT_AMOUNT']) ? -1 : 1;
220 foreach ($stores as $key => $store)
222 $store[
'SORT'] = 100 * $key;
223 $items[] = $this->makeItem($store);
229 private function getImageSource(
int $id): ?string
236 $file = \CFile::GetFileArray($id);
242 return Tools::getImageSrc($file,
false) ?:
null;
245 private function makeItem($store): Item
252 : Loc::getMessage(
'STORE_SELECTOR_EMPTY_TITLE')
257 'id' => $store[
'ID'],
258 'sort' => $store[
'SORT'],
259 'entityId' => self::ENTITY_ID,
261 'subtitle' => $store[
'ADDRESS'],
262 'avatar' => $store[
'IMAGE'],
266 ? $store[
'PRODUCT_AMOUNT'] .
' ' . $this->
getOptions()[
'measureSymbol']
272 'amount' => (float)$store[
'PRODUCT_AMOUNT'],
273 'availableAmount' => (float)$store[
'PRODUCT_AMOUNT'] - (float)$store[
'PRODUCT_RESERVED'],
static getRow(array $parameters)
static getList(array $parameters=array())
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)
$GLOBALS['____1444769544']