Skip to content

Commit

Permalink
Don't archive the order when viewing. (#492)
Browse files Browse the repository at this point in the history
Cherry picked #460 and #461 into master.
  • Loading branch information
bummzack committed May 3, 2016
1 parent f0c671e commit 2a017d6
Show file tree
Hide file tree
Showing 15 changed files with 104 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 @@ -301,16 +301,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
7 changes: 7 additions & 0 deletions tests/ViewableCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class ViewableCartTest extends SapphireTest
public static $fixture_file = 'silvershop/tests/fixtures/shop.yml';
public static $disable_theme = true;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/cart/ShoppingCartControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class ShoppingCartControllerTest extends FunctionalTest
public static $use_draft_site = false;
protected $autoFollowRedirection = false;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/cart/ShoppingCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class ShoppingCartTest extends SapphireTest
public static $disable_theme = true;
public static $use_draft_site = false;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/checkout/CheckoutFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ class CheckoutFormTest extends SapphireTest
{
public static $fixture_file = 'silvershop/tests/fixtures/shop.yml';

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/checkout/OrderProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class OrderProcessorTest extends SapphireTest
protected static $use_draft_site = true;
protected $processor;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/checkout/SteppedCheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class SteppedCheckoutTest extends FunctionalTest
/** @var Product */
protected $socks;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/model/ShopMemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class ShopMemberTest extends FunctionalTest
'silvershop/tests/fixtures/shop.yml',
);

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function testGetByIdentifier()
{
Member::config()->unique_identifier_field = 'Email';
Expand Down
7 changes: 7 additions & 0 deletions tests/model/ShopPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class ShopPaymentTest extends FunctionalTest
);
public static $disable_theme = true;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/modifiers/FlatTaxModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class FlatTaxModifierTest extends FunctionalTest
protected static $fixture_file = 'silvershop/tests/fixtures/shop.yml';
protected static $disable_theme = true;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/products/CustomProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class CustomProductTest extends FunctionalTest
"CustomProduct_OrderItem",
);

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function testCustomProduct()
{
$thing = CustomProduct::create(
Expand Down
7 changes: 7 additions & 0 deletions tests/products/ProductOrderItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class ProductOrderItemTest extends FunctionalTest
public static $disable_theme = true;
public static $orig = array();

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

/**
* Create and publish some products.
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/products/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class ProductTest extends FunctionalTest
protected static $disable_theme = true;
protected static $use_draft_site = true;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

function setUp()
{
parent::setUp();
Expand Down
7 changes: 7 additions & 0 deletions tests/products/variations/ProductVariationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class ProductVariationTest extends SapphireTest
public static $disable_theme = true;
public static $use_draft_site = true;

public function setUpOnce()
{
parent::setUpOnce();
// clear session
ShoppingCart::singleton()->clear();
}

public function setUp()
{
parent::setUp();
Expand Down

0 comments on commit 2a017d6

Please sign in to comment.