Bitrix API

AvailableQuantityCalculator

Calculation of balances based on the reservation history.

For example:

$calculator = new \Bitrix\Sale\Reservation\AvailableQuantityCalculator();

// load store balance
$rows = StoreProductTable::getList([...]);
foreach ($rows as $row)
{
    $calculator->setStoreQuantity($row['STORE_ID'], $row['PRODUCT_ID'], $row['AMOUNT']);
}

// load history
$rows = BasketReservationHistoryTable::getList([...]);
foreach ($rows as $row)
{
    $calculator->addReservationHistory(
        $row['STORE_ID'],
        $row['PRODUCT_ID'],
        $row['BASKET_ID'],
        $row['QUANTITY']
    );
}

// get count
$calculator->getQuantityForBatch([
    $basketId => $productId,
    $basketId => $productId,
    // ...
]);
$calculator->getQuantityForItem($productId, $basketId, $storeId);

Table of Contents

Methods

addReservationHistory()  : void
Add an item reservation history.
getQuantityForBatch()  : array<string|int, mixed>
Get available for debit product quantity for batch with basket items.
getQuantityForItem()  : float
Get available for debit product quantity for store.
setStoreQuantity()  : void
Set product store quantity.

Methods

addReservationHistory()

Add an item reservation history.

public addReservationHistory(int $storeId, int $productId, int $basketId, float $quantity) : void

The order of addition is IMPORTANT!

Parameters
$storeId : int
$productId : int
$basketId : int
$quantity : float

getQuantityForBatch()

Get available for debit product quantity for batch with basket items.

public getQuantityForBatch(array<string|int, mixed> $basket2productId) : array<string|int, mixed>
Parameters
$basket2productId : array<string|int, mixed>

in format ['basketId' => 'productId', 'basketId' => 'productId', ...]

Return values
array<string|int, mixed>

in format ['basketId' => ['storeId' => 'avaiableQuantity']]

getQuantityForItem()

Get available for debit product quantity for store.

public getQuantityForItem(int $productId, int $basketId, int $storeId) : float
Parameters
$productId : int
$basketId : int
$storeId : int
Return values
float

setStoreQuantity()

Set product store quantity.

public setStoreQuantity(int $storeId, int $productId, float $quantity) : void
Parameters
$storeId : int
$productId : int
$quantity : float

        
On this page

Search results