function uc_order_edit_products in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_order/uc_order.admin.inc \uc_order_edit_products()
Populate 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 - Implementation of hook_menu().
File
- uc_order/
uc_order.module, line 1741
Code
function uc_order_edit_products($order_id) {
if (is_null($order_id) || $order_id == 0) {
exit;
}
if (is_array($_POST['products'])) {
foreach ($_POST['products'] as $key => $product) {
$product['data'] = unserialize($product['data']);
uc_order_product_save($order_id, (object) $product);
}
}
switch ($_POST['action']) {
case 'add_blank':
db_query("INSERT INTO {uc_order_products} (order_product_id, order_id, qty) VALUES (%d, %d, 1)", db_next_id('{uc_order_products}_order_product_id'), $order_id);
if (variable_get('uc_order_logging', TRUE)) {
uc_order_log_changes($order_id, array(
'add' => 'Added new product line to order.',
));
}
break;
case 'add':
$product = node_load(intval($_POST['nid']));
$product->qty = intval($_POST['qty']);
$product->price = $product->sell_price;
if (module_exists('uc_manufacturer')) {
$product->manufacturer = uc_product_get_manufacturer($product->nid);
$product->manufacturer = $product->manufacturer->name;
}
if (module_exists('uc_attribute')) {
$form_values = array(
'nid' => intval($_POST['nid']),
'attributes' => $_POST['attributes'],
);
$product->data = module_invoke_all('add_to_cart_data', $form_values);
$attributes = array();
$product->options = _uc_cart_product_get_options($product);
foreach ($product->options as $option) {
$product->cost += $option['cost'];
$product->price += $option['price'];
$product->weight += $option['weight'];
$attributes[$option['attribute']] = $option['name'];
}
$product->data['attributes'] = $attributes;
$product->module = $product->data['module'];
if ($product->data['model']) {
$product->model = $product->data['model'];
}
}
uc_order_product_save($order_id, $product);
if (variable_get('uc_order_logging', TRUE)) {
uc_order_log_changes($order_id, array(
'add' => 'Added (' . $product->qty . ') ' . $product->title . ' to order.',
));
}
break;
case 'remove':
db_query("DELETE FROM {uc_order_products} WHERE order_product_id = %d", intval($_POST['opid']));
break;
}
$result = db_query("SELECT * FROM {uc_order_products} WHERE order_id = %d ORDER BY order_product_id", $order_id);
while ($product = db_fetch_object($result)) {
$products[] = $product;
}
print uc_strip_form(drupal_get_form('uc_order_edit_products_form', $products));
exit;
}