lhungil, would you consider adding a couple of notifiers to the Edit Orders functions?
I've created some customizations that alter the handling of a product within an order and need to perform some additional processing when a product is removed and/or added to the order via Edit Orders. Following are the changes that I've made to /YOUR_ADMIN/includes/functions/extra_functions/edit_orders_functions.php to accomplish what I need:
Code:
function eo_add_product_to_order($order_id, $product) {
global $db, $order, $zco_notifier;
...
$order->products[] = $product;
$zco_notifier->notify ('EDIT_ORDERS_ADD_PRODUCT', array ( 'order_id' => (int)$order_id, 'orders_products_id' => $order_products_id, 'product' => $product ));
return $product;
}
Code:
function eo_remove_product_from_order($order_id, $orders_products_id) {
global $db, $order, $zco_notifier;
// First grab the order <==> product mappings
$orders_products_id_mapping = eo_get_orders_products_id_mappings((int)$order_id);
// Handle product stock
if (STOCK_LIMITED == 'true') {
$query = $db->Execute(
'SELECT `products_id`, `products_quantity` ' .
'FROM `' . TABLE_ORDERS_PRODUCTS . '` ' .
'WHERE `orders_id`=\'' . (int)$order_id . '\' ' .
'AND `orders_products_id`=\'' . (int)$orders_products_id . '\''
);
while (!$query->EOF) {
if (DOWNLOAD_ENABLED == 'true') {
$check = $db->Execute(
'SELECT `p`.`products_quantity`, `pad`.`products_attributes_filename`, `p`.`product_is_always_free_shipping` ' .
'FROM `' . TABLE_PRODUCTS . '` AS `p` ' .
'LEFT JOIN `' . TABLE_PRODUCTS_ATTRIBUTES . '` AS `pa` ON `p`.`products_id`=`pa`.`products_id` ' .
'LEFT JOIN `' . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . '` AS `pad` ON `pa`.`products_attributes_id`=`pad`.`products_attributes_id` ' .
'WHERE `p`.`products_id` = \'' . (int)$query->fields['products_id'] . '\''
);
}
else {
$check = $db->Execute(
'SELECT `p`.`products_quantity` FROM `' . TABLE_PRODUCTS . '` AS `p`' .
'WHERE `p`.`products_id` = \'' . (int)$query->fields['products_id'] . '\''
);
}
if (!$check->EOF && (DOWNLOAD_ENABLED != 'true' || $check->fields['product_is_always_free_shipping'] == 2 || !$check->fields['products_attributes_filename'] )) {
$sql_data_array = array(
'products_quantity' => $check->fields['products_quantity'] + $query->fields['products_quantity'],
'products_ordered' => $check->fields['products_ordered'] - $query->fields['products_quantity']
);
if($sql_data_array['products_ordered'] < 0) $sql_data_array['products_ordered'] = 0;
if($sql_data_array['products_quantity'] > 0) {
// Only set status to on when not displaying sold out
if (SHOW_PRODUCTS_SOLD_OUT == '0') {
$sql_data_array['products_status'] = 1;
}
}
zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', 'products_id = \'' . (int)$query->fields['products_id'] . '\'');
}
$query->MoveNext();
}
unset($check, $query, $sql_data_array);
}
$zco_notifier->notify ('EDIT_ORDERS_REMOVE_PRODUCT', array ( 'order_id' => (int)$order_id, 'orders_products_id' => (int)$orders_products_id ));
...
}
Bookmarks