I'm using the following code to remember shopping carts per session. The code works just fine, but the problem is that the cart is not emptied on checkout complete, but shows the contents of the completed order. So the session needs to be cleared on checkout completion so that a new empty order will be created. How do I accomplish this?
function mymodule_commerce_cart_order_id($uid = 0) {
$key = $uid . '-' . session_id();
$carts = variable_get('mymodule_carts', array());
if ( isset($carts[$key]) ) {
return intval($carts[$key]);
} else {
// create a new cart for this session
$order = commerce_cart_order_new($uid);
$order->data['last_cart_refresh'] = REQUEST_TIME;
$order_id = intval($order->order_id);
// save the new order id to the module settings cache
$carts[$key] = $order_id;
variable_set('mymodule_carts', $carts);
return $order_id;
}
}