function _uc_coupon_apply_to_order in Ubercart Discount Coupons 6
Create, update or remove the coupon line item in an order.
2 calls to _uc_coupon_apply_to_order()
- uc_checkout_pane_coupon in ./
uc_coupon.module - Checkout Pane callback function.
- uc_coupon_order in ./
uc_coupon.module - Implementation of hook_order().
File
- ./
uc_coupon.module, line 1106 - Provides discount coupons for Ubercart.
Code
function _uc_coupon_apply_to_order($order_id, $coupon) {
$lid = db_result(db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = %d AND type = 'coupon'", $order_id));
if ($lid) {
if ($coupon) {
db_query("UPDATE {uc_coupons_orders} SET cid = %d, code = '%s', value = %f WHERE oid = %d", $coupon->cid, $coupon->code, $coupon->amount, $order_id);
uc_order_update_line_item($lid, $coupon->title, -$coupon->amount);
}
else {
db_query('DELETE FROM {uc_coupons_orders} WHERE oid = %d', $order_id);
uc_order_delete_line_item($lid);
}
}
else {
db_query("INSERT INTO {uc_coupons_orders} (cid, oid, code, value) VALUES (%d, %d, '%s', %f)", $coupon->cid, $order_id, $coupon->code, $coupon->amount);
uc_order_line_item_add($order_id, 'coupon', $coupon->title, -$coupon->amount);
}
}