order_return_stock_counts_after

Triggered after returning the quantities of ordered product variants to stocks when an ordered is deleted or refunded. 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 returned to stocks.
$params['counts'][sku_id][stock_id] float The quantity of product variant with sku_id, which has been returned to stock stock_id.
… your plugin code …

Output

Shop-Script

Plugin code example

PHP

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

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

    $log_text = sprintf(
        'Quantities of product variants returned 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_return_stock_counts_after.log'
    );
}