Hook allows to implement custom rules to automatically select a stock for new orders.


Input (passed by reference)

$params array Parameters.
$params['order'] array Order data.
$params['rules'] array Rules for stock selection from 'shop_stock_rules' table, which can be modified by a plugin by adding a Boolean value with 'fulfilled' key for the rules which must be processed by a plugin. See also description of См 'backend_settings_stocks' hook about how to modify the settings form to setup custom rules.
$params['stocks'] array Stocks returned by method shopHelper::getStocks().
… your plugin code …



Plugin code example


 * As an example, let us determine whether total quantity of order items is above a value
 * selected in the first available stock rule setting provided by this plugin.
 * For details, see description and code example for 'backend_settings_stock' event
public function frontendCheckoutStockRules($params)
    $quantity = 0;
    foreach ($params['order']['items'] as $item) {
        $quantity += $item['quantity'];

    foreach ($params['rules'] as &$rule) {
        if ($rule['rule_type'] == $this->id) {
            if ($quantity > $rule['rule_data']) {
                $rule['fulfilled'] = true;