You are here

function uc_stock_edit_form_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_stock/uc_stock.module \uc_stock_edit_form_submit()
  2. 7.3 uc_stock/uc_stock.admin.inc \uc_stock_edit_form_submit()

Form submission handler for uc_stock_edit_form().

See also

uc_stock_edit_form()

theme_uc_stock_edit_form()

File

uc_stock/uc_stock.admin.inc, line 244
Stock administration menu items.

Code

function uc_stock_edit_form_submit($form, &$form_state) {
  foreach (element_children($form_state['values']['stock']) as $id) {
    db_query("UPDATE {uc_product_stock} SET active = %d, stock = %d, threshold = %d WHERE sku = '%s'", $form_state['values']['stock'][$id]['active'] ? 1 : 0, intval($form_state['values']['stock'][$id]['stock']), intval($form_state['values']['stock'][$id]['threshold']), $form_state['values']['stock'][$id]['sku']);
    if (!db_affected_rows()) {
      @db_query("INSERT INTO {uc_product_stock} (sku, nid, active, stock, threshold) VALUES ('%s', %d, %d, %d, %d)", $form_state['values']['stock'][$id]['sku'], $form_state['values']['nid'], $form_state['values']['stock'][$id]['active'] ? 1 : 0, intval($form_state['values']['stock'][$id]['stock']), intval($form_state['values']['stock'][$id]['threshold']));
    }
  }
  drupal_set_message(t('Stock settings saved.'));
}