403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/catalog/product-model/src/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/catalog/product-model/src/store-collection.js
import {ajax, Text, Type} from "main.core";
import {ProductModel} from "catalog.product-model";
import {RightActionDictionary} from "./right-action-dictionary";

export class StoreCollection
{
	#map: Map = new Map();
	#inited: boolean = false;

	constructor(model: ProductModel = {})
	{
		this.model = model;
	}

	init(map: {})
	{
		this.#setInited(true);
		Object.keys(map).forEach((key) => {
			const item = map[key];
			if (item['STORE_ID'] > 0)
			{
				this.#map.set(
					Text.toNumber(item['STORE_ID']),
					{
						AMOUNT: Text.toNumber(item['AMOUNT']),
						QUANTITY_RESERVED: Text.toNumber(item['QUANTITY_RESERVED']),
						STORE_ID: Text.toNumber(item['STORE_ID']),
						STORE_TITLE: Text.encode(item['STORE_TITLE']),
					}
				);
			}
		});
	}

	refresh(): {}
	{
		this.clear();
		if (this.model.getSkuId() > 0 && this.model.checkAccess(RightActionDictionary.ACTION_PRODUCT_VIEW))
		{
			ajax.runAction(
				'catalog.storeSelector.getProductStores',
				{
					json: {
						productId: this.model.getSkuId(),
					}
				}
			)
				.then((response) => {
					this.#setInited(true);
					response.data.forEach((item) => {
						if (!Type.isNil(item['STORE_ID']))
						{
							this.#map.set(
								Text.toNumber(item['STORE_ID']),
								{
									AMOUNT: Text.toNumber(item['AMOUNT']),
									QUANTITY_RESERVED: Text.toNumber(item['QUANTITY_RESERVED']),
									STORE_ID: Text.toNumber(item['STORE_ID']),
									STORE_TITLE: item['STORE_TITLE'],
								}
							);
						}
					});

					this.model.onChangeStoreData();
				});
		}
	}

	getStoreAmount(storeId): any
	{
		return this.#map.get(Text.toNumber(storeId))?.AMOUNT || 0;
	}

	getStoreReserved(storeId): any
	{
		return this.#map.get(Text.toNumber(storeId))?.QUANTITY_RESERVED || 0;
	}

	getStoreAvailableAmount(storeId): any
	{
		return this.getStoreAmount(storeId) - this.getStoreReserved(storeId);
	}

	getMaxFilledStore(): {}
	{
		let result = {
			'STORE_ID': 0,
			'AMOUNT': 0,
			'STORE_TITLE': '',
			'QUANTITY_RESERVED': 0,
		};
		this.#map.forEach((item) => {
			result =
				item.AMOUNT > result.AMOUNT
					? item
					: result
			;
		});

		return result;
	}

	#setInited(inited: boolean): void
	{
		this.#inited = inited;
	}

	isInited(): boolean
	{
		return this.#inited;
	}

	clear(): StoreCollection
	{
		this.#map.clear();
		this.#setInited(false);

		return this;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit