From 2a017d67686248c78f2649699d1b0f116b75108e Mon Sep 17 00:00:00 2001 From: Roman Schmid Date: Tue, 3 May 2016 17:38:22 +0200 Subject: [PATCH] Don't archive the order when viewing. (#492) Cherry picked #460 and #461 into master. --- code/account/OrderManipulation.php | 3 ++- code/cart/ShoppingCart.php | 14 +++++++++++--- tests/ViewableCartTest.php | 7 +++++++ tests/cart/ShoppingCartControllerTest.php | 7 +++++++ tests/cart/ShoppingCartTest.php | 7 +++++++ tests/checkout/CheckoutFormTest.php | 7 +++++++ tests/checkout/OrderProcessorTest.php | 7 +++++++ tests/checkout/SteppedCheckoutTest.php | 7 +++++++ tests/model/ShopMemberTest.php | 7 +++++++ tests/model/ShopPaymentTest.php | 7 +++++++ tests/modifiers/FlatTaxModifierTest.php | 7 +++++++ tests/products/CustomProductTest.php | 7 +++++++ tests/products/ProductOrderItemTest.php | 7 +++++++ tests/products/ProductTest.php | 7 +++++++ tests/products/variations/ProductVariationTest.php | 7 +++++++ 15 files changed, 104 insertions(+), 4 deletions(-) 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 562219aea..df7f2236d 100644 --- a/code/cart/ShoppingCart.php +++ b/code/cart/ShoppingCart.php @@ -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(); + } } /** diff --git a/tests/ViewableCartTest.php b/tests/ViewableCartTest.php index b01d090fc..ae4291fc2 100644 --- a/tests/ViewableCartTest.php +++ b/tests/ViewableCartTest.php @@ -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(); diff --git a/tests/cart/ShoppingCartControllerTest.php b/tests/cart/ShoppingCartControllerTest.php index ede2199ef..85ad95e34 100644 --- a/tests/cart/ShoppingCartControllerTest.php +++ b/tests/cart/ShoppingCartControllerTest.php @@ -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(); diff --git a/tests/cart/ShoppingCartTest.php b/tests/cart/ShoppingCartTest.php index 220e2d731..de1e7c1b7 100644 --- a/tests/cart/ShoppingCartTest.php +++ b/tests/cart/ShoppingCartTest.php @@ -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(); diff --git a/tests/checkout/CheckoutFormTest.php b/tests/checkout/CheckoutFormTest.php index 9efdb915b..31ebfbaac 100644 --- a/tests/checkout/CheckoutFormTest.php +++ b/tests/checkout/CheckoutFormTest.php @@ -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(); diff --git a/tests/checkout/OrderProcessorTest.php b/tests/checkout/OrderProcessorTest.php index f2b291bdb..0d1648bef 100644 --- a/tests/checkout/OrderProcessorTest.php +++ b/tests/checkout/OrderProcessorTest.php @@ -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(); diff --git a/tests/checkout/SteppedCheckoutTest.php b/tests/checkout/SteppedCheckoutTest.php index 5ca87773e..4097cfa69 100644 --- a/tests/checkout/SteppedCheckoutTest.php +++ b/tests/checkout/SteppedCheckoutTest.php @@ -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(); diff --git a/tests/model/ShopMemberTest.php b/tests/model/ShopMemberTest.php index 317c89be1..3232302c5 100644 --- a/tests/model/ShopMemberTest.php +++ b/tests/model/ShopMemberTest.php @@ -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'; diff --git a/tests/model/ShopPaymentTest.php b/tests/model/ShopPaymentTest.php index e10b16b69..935ebb58f 100644 --- a/tests/model/ShopPaymentTest.php +++ b/tests/model/ShopPaymentTest.php @@ -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(); diff --git a/tests/modifiers/FlatTaxModifierTest.php b/tests/modifiers/FlatTaxModifierTest.php index 52827fc0c..2668fe419 100644 --- a/tests/modifiers/FlatTaxModifierTest.php +++ b/tests/modifiers/FlatTaxModifierTest.php @@ -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(); diff --git a/tests/products/CustomProductTest.php b/tests/products/CustomProductTest.php index 01d3ce7b8..448075086 100644 --- a/tests/products/CustomProductTest.php +++ b/tests/products/CustomProductTest.php @@ -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( diff --git a/tests/products/ProductOrderItemTest.php b/tests/products/ProductOrderItemTest.php index de2a55e5f..0371dcfba 100644 --- a/tests/products/ProductOrderItemTest.php +++ b/tests/products/ProductOrderItemTest.php @@ -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. */ diff --git a/tests/products/ProductTest.php b/tests/products/ProductTest.php index 539d89276..15c0a0315 100644 --- a/tests/products/ProductTest.php +++ b/tests/products/ProductTest.php @@ -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(); diff --git a/tests/products/variations/ProductVariationTest.php b/tests/products/variations/ProductVariationTest.php index f7c10a5a0..0156d7a11 100644 --- a/tests/products/variations/ProductVariationTest.php +++ b/tests/products/variations/ProductVariationTest.php @@ -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();