You are here

function uc_order_edit_products in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_order/uc_order.module \uc_order_edit_products()

Populates the product add/edit div on the order edit screen.

1 string reference to 'uc_order_edit_products'
uc_order_menu in uc_order/uc_order.module
Implements hook_menu().

File

uc_order/uc_order.admin.inc, line 1320
Order administration menu items.

Code

function uc_order_edit_products($order) {
  uc_order_module_invoke('edit-products', $order, $_POST);
  if (is_array($_POST['products'])) {
    foreach ($_POST['products'] as $key => $product) {
      $product['data'] = unserialize($product['data']);
      uc_order_product_save($order->order_id, (object) $product);
    }
  }
  switch ($_POST['action']) {
    case 'add_blank':
      db_query("INSERT INTO {uc_order_products} (order_id, qty) VALUES (%d, 1)", $order->order_id);
      if (variable_get('uc_order_logging', TRUE)) {
        uc_order_log_changes($order->order_id, array(
          'add' => t('Added new product line to order.'),
        ));
      }
      break;
    case 'add':
      $form_state['values'] = $_POST;
      $product = node_load(intval($_POST['nid']));
      $product->qty = intval($_POST['qty']);
      $product->price = $product->sell_price;
      $product->data = module_invoke_all('add_to_cart_data', $form_state['values']);
      foreach (module_list() as $module) {
        $function = $module . '_cart_item';
        if (function_exists($function)) {

          // $product must be passed by reference.
          $function('load', $product);
        }
      }
      $price_info = array(
        'price' => $product->price,
        'qty' => 1,
      );
      $context = array(
        'revision' => 'original',
        'type' => 'order_product',
        'subject' => array(
          'order' => $order,
          'product' => $product,
          'node' => clone $product,
        ),
      );
      $product->price = uc_price($price_info, $context);
      drupal_alter('order_product', $product, $order);
      uc_order_product_save($order->order_id, $product);
      if (variable_get('uc_order_logging', TRUE)) {
        uc_order_log_changes($order->order_id, array(
          'add' => t('Added (@qty) @product-title to order.', array(
            '@qty' => $product->qty,
            '@product-title' => $product->title,
          )),
        ));
      }
      break;
    case 'remove':
      $order_product_id = intval($_POST['opid']);
      db_query("DELETE FROM {uc_order_products} WHERE order_product_id = %d", $order_product_id);
      break;
  }
  $result = db_query("SELECT * FROM {uc_order_products} WHERE order_id = %d ORDER BY order_product_id", $order->order_id);
  while ($product = db_fetch_object($result)) {
    $products[] = $product;
  }
  print uc_strip_form(drupal_get_form('uc_order_edit_products_form', $products));
  exit;
}