7 private static $values = [];
28 static::resetValue(static::QUANTITY, $productId);
29 static::resetValue(static::AVAILABLE_QUANTITY, $productId);
30 static::resetValue(static::RESERVED_QUANTITY, $productId);
31 static::resetValue(static::RESERVER_STORE_QUANTITY, $productId);
45 CatalogProvider::getDefaultStoreId(),
61 CatalogProvider::getDefaultStoreId(),
62 (
float)$value + (
float)static::getQuantity($productId)
73 return self::getValue(
75 CatalogProvider::getDefaultStoreId(),
87 self::resetValue(static::QUANTITY, $productId);
99 static::RESERVED_QUANTITY,
101 CatalogProvider::getDefaultStoreId(),
115 static::RESERVED_QUANTITY,
117 CatalogProvider::getDefaultStoreId(),
118 (
float)$value + (
float)static::getReservedQuantity($productId)
129 return self::getValue(
130 static::RESERVED_QUANTITY,
131 CatalogProvider::getDefaultStoreId(),
143 self::resetValue(static::RESERVED_QUANTITY, $productId);
154 static::RESERVED_QUANTITY,
156 CatalogProvider::getDefaultStoreId(),
157 self::getSummaryValue(
158 static::RESERVER_STORE_QUANTITY,
173 static::AVAILABLE_QUANTITY,
175 CatalogProvider::getDefaultStoreId(),
189 static::AVAILABLE_QUANTITY,
191 CatalogProvider::getDefaultStoreId(),
192 (
float)$value + (
float)static::getAvailableQuantity($productId)
203 return self::getValue(
204 static::AVAILABLE_QUANTITY,
206 CatalogProvider::getDefaultStoreId()
215 self::resetValue(static::AVAILABLE_QUANTITY, $productId);
229 static::RESERVER_STORE_QUANTITY,
237 static::setReservedQuantity(
239 self::getSummaryValue(
240 static::RESERVER_STORE_QUANTITY,
258 static::RESERVER_STORE_QUANTITY,
262 + (
float)static::getReservedStoreQuantity(
270 static::addReservedQuantity($productId, $value);
282 return self::getValue(
283 static::RESERVER_STORE_QUANTITY,
294 self::resetValue(static::RESERVER_STORE_QUANTITY, $productId);
303 private static function setValue(
string $type, $productId,
int $storeId, $value): void
305 if (!isset(self::$values[$type]))
307 self::$values[$type] = [];
309 if (isset(self::$values[$type][$productId]))
311 self::$values[$type][$productId] = [];
313 self::$values[$type][$productId][$storeId] = (float)$value;
323 private static function getValue(
string $type, $productId,
int $storeId): ?float
326 if (isset(self::$values[$type][$productId][$storeId]))
328 $value = self::$values[$type][$productId][$storeId];
340 private static function resetValue(
string $type, $productId =
null): void
342 if ($productId ==
null)
344 unset(self::$values[$type]);
348 unset(self::$values[$type][$productId]);
352 private static function getSummaryValue(
string $type, $productId): ?float
356 isset(self::$values[$type][$productId])
357 && is_array(self::$values[$type][$productId])
360 $result = (float)array_sum(self::$values[$type][$productId]);
372 public static function setValues($productId, array $values): void
374 static::resetAllQuantity($productId);
376 if (isset($values[static::QUANTITY]))
381 CatalogProvider::getDefaultStoreId(),
382 $values[static::QUANTITY]
386 if (isset($values[static::AVAILABLE_QUANTITY]))
389 static::AVAILABLE_QUANTITY,
391 CatalogProvider::getDefaultStoreId(),
392 $values[static::AVAILABLE_QUANTITY]
396 if (isset($values[static::RESERVED_QUANTITY]))
399 static::RESERVED_QUANTITY,
401 CatalogProvider::getDefaultStoreId(),
402 $values[static::RESERVED_QUANTITY]
407 isset($values[static::RESERVER_STORE_QUANTITY])
408 && is_array($values[static::RESERVER_STORE_QUANTITY])
411 foreach ($values[static::RESERVER_STORE_QUANTITY] as $storeId => $storeValue)
414 static::RESERVER_STORE_QUANTITY,
static setQuantity($productId, $value)
static resetReservedStoreQuantity($productId)
static addReservedQuantity($productId, $value)
const QUANTITY_CONTROL_QUANTITY
static resetAllQuantity($productId=null)
static getReservedQuantity($productId)
static addReservedStoreQuantity($productId, int $storeId, $value, bool $summary=false)
static setAvailableQuantity($productId, $value)
static setValues($productId, array $values)
static getAvailableQuantity($productId)
static setReservedQuantityFromStores($productId)
static setReservedQuantity($productId, $value)
static resetQuantity($productId)
static addAvailableQuantity($productId, $value)
static getQuantity($productId)
const QUANTITY_CONTROL_RESERVED_QUANTITY
const QUANTITY_CONTROL_AVAILABLE_QUANTITY
static resetAvailableQuantity($productId)
static addQuantity($productId, $value)
static getReservedStoreQuantity($productId, int $storeId)
static setReservedStoreQuantity($productId, int $storeId, $value, bool $summary=false)
const RESERVER_STORE_QUANTITY
static resetReservedQuantity($productId)