/** * Add a product variation to the cart, change the cart so that it is out of date * then delete it */ function testRemoveAbandonedCartsWithProductVariationsTask() { $teeshirtA = $this->objFromFixture('Product', 'teeshirtA'); $this->logInAs('admin'); $teeshirtA->doPublish(); $this->logOut(); $teeshirtAVariation = $this->objFromFixture('Variation', 'teeshirtExtraLargePurpleCotton'); $this->assertEquals('Enabled', $teeshirtAVariation->Status); $this->assertEquals(5, $teeshirtAVariation->StockLevel()->Level); //Add variation to the cart $this->get(Director::makeRelative($teeshirtA->Link())); $data = array('Quantity' => 1); foreach ($teeshirtAVariation->Options() as $option) { $data["Options[{$option->AttributeID}]"] = $option->ID; } $this->submitForm('AddToCartForm_AddToCartForm', null, $data); $teeshirtAVariation = $this->objFromFixture('Variation', 'teeshirtExtraLargePurpleCotton'); $this->assertEquals(4, $teeshirtAVariation->StockLevel()->Level); $order = CartControllerExtension::get_current_order(); $this->logInAs('admin'); $order->LastActive = '2011-12-22 17:02:49'; $order->Status = 'Cart'; $order->write(); $this->logOut(); Order::delete_abandoned(); DataObject::flush_and_destroy_cache(); $teeshirtAVariation = $this->objFromFixture('Variation', 'teeshirtExtraLargePurpleCotton'); $this->assertEquals(5, $teeshirtAVariation->StockLevel()->Level); }
/** * Include some CSS and javascript for the checkout page * * TODO why didn't I use init() here? * * @return Array Contents for page rendering */ function index() { //Update stock levels Order::delete_abandoned(); Requirements::css('swipestripe/css/Shop.css'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript('swipestripe/javascript/CheckoutPage.js'); return array('Content' => $this->Content, 'Form' => $this->Form); }
/** * Display a {@link Product}. * * @param SS_HTTPRequest $request */ function index(SS_HTTPRequest $request) { //Update stock levels before displaying product Order::delete_abandoned(); $product = $this->data(); if ($product && $product->exists()) { $data = array('Product' => $product, 'Content' => $this->Content, 'Form' => $this->AddToCartForm()); return $this->Customise($data)->renderWith(array('Product', 'Page')); /* $ssv = new SSViewer("Page"); $ssv->setTemplateFile("Layout", "Product_show"); return $this->Customise($data)->renderWith($ssv); */ } else { return $this->httpError(404, 'Sorry that product could not be found'); } }
/** * Remove {@link Order}s that have not been active for a certain period of time, * do not have a {@link Payment} attached and have the status of 'Cart'. * * @see Order::delete_abandoned() * @see CliController::process() */ function process() { date_default_timezone_set('Pacific/Auckland'); Order::delete_abandoned(); }
/** * Carts abandoned longer than set lifetime are deleted */ public function testDeleteAbandonedCarts() { $productA = $this->objFromFixture('Product', 'productA'); $shopConfig = $this->objFromFixture('ShopConfig', 'config'); $this->assertEquals(1, $shopConfig->CartTimeout); $this->assertEquals('hour', $shopConfig->CartTimeoutUnit); $this->loginAs('admin'); $productA->doPublish(); $this->logOut(); $productALink = $productA->Link(); $this->get(Director::makeRelative($productALink)); $this->submitForm('ProductForm_ProductForm', null, array('Quantity' => 1)); $order = Cart::get_current_order(); $this->assertTrue($order->exists()); Order::delete_abandoned(); DataObject::flush_and_destroy_cache(); $order = Cart::get_current_order(); $this->assertTrue($order->exists()); //Log in as admin, change the shop config and the cart last active and try to delete it $this->loginAs('admin'); $shopConfig->CartTimeout = 15; $shopConfig->CartTimeoutUnit = 'minute'; $shopConfig->write(); $date = new DateTime(); $date->sub(new DateInterval('PT20M')); $order->LastActive = $date->format('Y-m-d H:i:s'); $order->write(); $this->logOut(); Order::delete_abandoned(); DataObject::flush_and_destroy_cache(); $order = Cart::get_current_order(); $this->assertTrue(!$order->exists()); }
/** * Include some CSS for the cart page. * * @return Array Contents for page rendering */ function index() { //Update stock levels Order::delete_abandoned(); Requirements::css('swipestripe/css/Shop.css'); return array('Content' => $this->Content, 'Form' => $this->Form); }