order_reduce_stock_counts_after

Triggered after reducing the ordered product variants’ counts during the order processing. Allows tracking changes to the stock inventory; e.g., to sync data with online marketplaces.

Shop-Script

Input (passed by reference)

$params['order_id'] int Order ID.
$params['counts'] array Information about the quantities of ordered product variants which has been written of from the stocks.
$params['counts'][sku_id][stock_id] float The quantity of product variant with sku_id written off from stock stock_id.
… your plugin code …

Output

Shop-Script

Plugin code example

PHP

public function orderReduceStockCountsAfter($params)
{
    $log_strings = [];

    foreach ($params['counts'] as $sku_id => $sku_quantities) {
        foreach ($sku_quantities as $stock_id => $sku_stock_quantity) {
            $log_strings[] = sprintf(
                '- removed %0.3f of sku #%d from stock #%d',
                $sku_stock_quantity,
                $sku_id,
                $stock_id
            );
        }
    }

    $log_text = sprintf(
        'Values written of from the quantities of product variants during the processing of order #%d:%s',
        $params['order_id'],
        PHP_EOL . implode(PHP_EOL, $log_strings)
    );

    waLog::log(
        $log_text,
        'shop/plugins/' . $this->getId() . '/order_reduce_stock_counts_after.log'
    );
}