You are here

function commerce_ss_increase_by_line_item in Commerce Stock 7.2

Adds the sold amount in a line item to stock.

Typically used when a line item is removed from an order (as when items are added to and removed from cart).

Parameters

array $line_item: A line item object.

File

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

Code

function commerce_ss_increase_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);
      }
    }
  }
}