You are here

function commerce_ss_decrease_by_line_item in Commerce Stock 7.2

Subtracts from stock the sold amount in a line item.

Parameters

array $line_item: A line item object.

File

modules/commerce_ss/commerce_ss.rules.inc, line 86
Rules integration for Commerce Simple Stock.

Code

function commerce_ss_decrease_by_line_item($line_item) {
  if (in_array($line_item->type, commerce_product_line_item_types())) {

    // The product SKU that will have its stock level adjusted.
    $sku = commerce_ss_line_item_sku($line_item);
    $product = commerce_product_load_by_sku($sku);
    if (commerce_ss_product_type_enabled($product->type)) {
      if (!(commerce_ss_product_type_override_enabled($product->type) && isset($product->commerce_stock_override['und']) && $product->commerce_stock_override['und'][0]['value'] == 1)) {
        $qty = $line_item->quantity;

        // Subtract the sold amount from the available stock level.
        commerce_ss_stock_adjust($product, -$qty);
      }
    }
  }
}