diff --git a/code/account/OrderManipulation.php b/code/account/OrderManipulation.php index 357a84214..5d3ffeeba 100644 --- a/code/account/OrderManipulation.php +++ b/code/account/OrderManipulation.php @@ -108,7 +108,8 @@ public function PastOrders($paginated = false) public function order(SS_HTTPRequest $request) { //move the shopping cart session id to past order ids, if it is now an order - ShoppingCart::singleton()->archiveorderid(); + ShoppingCart::singleton()->archiveorderid($request->param('ID')); + $order = $this->orderfromid(); if (!$order) { return $this->owner->httpError(404, "Order could not be found"); diff --git a/code/cart/ShoppingCart.php b/code/cart/ShoppingCart.php index 9ea27cb75..dfb47195a 100644 --- a/code/cart/ShoppingCart.php +++ b/code/cart/ShoppingCart.php @@ -300,16 +300,24 @@ public function get(Buyable $buyable, $customfilter = array()) /** * Store old cart id in session order history + * @param int|null $requestedOrderId optional parameter that denotes the order that was requested */ - public function archiveorderid() + public function archiveorderid($requestedOrderId = null) { + $sessionId = Session::get(self::$cartid_session_name); $order = Order::get() ->filter("Status:not", "Cart") - ->byId(Session::get(self::$cartid_session_name)); + ->byId($sessionId); if ($order && !$order->IsCart()) { OrderManipulation::add_session_order($order); } - $this->clear(); + // in case there was no order requested + // OR there was an order requested AND it's the same one as currently in the session, + // then clear the cart. This check is here to prevent clearing of the cart if the user just + // wants to view an old order (via AccountPage). + if (!$requestedOrderId || ($sessionId == $requestedOrderId)) { + $this->clear(); + } } /**