Skip to content

Commit

Permalink
Don't archive the order when viewing.
Browse files Browse the repository at this point in the history
  • Loading branch information
bummzack committed Mar 18, 2016
1 parent 55280d0 commit 342be26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion code/account/OrderManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 11 additions & 3 deletions code/cart/ShoppingCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down

0 comments on commit 342be26

Please sign in to comment.