/** * @param SS_HTTPRequest * @return REDIRECT **/ function clearandlogout(SS_HTTPRequest $request) { $this->cart->clear(); if ($member = Member::currentUser()) { $member->logout(); } $this->redirect(Director::baseURL()); return array(); }
function setUp() { parent::setUp(); EcommerceTest::setConfiguration(); Order::set_modifiers(array("FlatTaxModifer"), true); FlatTaxModifier::set_tax(0.15, "GST", true); $this->objFromFixture('Product', 'mp3player')->publish('Stage', 'Live'); ShoppingCart::clear(); }
function testRemoveFromCart() { /* Retrieve the product to compare from fixture */ $product = $this->objFromFixture('Product', 'mp3player'); $anotherproduct = $this->objFromFixture('Product', 'tshirt'); /* add items via url */ $this->get(ShoppingCart::set_quantity_item_link($product->ID, $product->class) . "?quantity=5"); $this->get(ShoppingCart::add_item_link($anotherproduct->ID, $product->class)); /* remove items via url */ $this->get(ShoppingCart::remove_item_link($product->ID, $product->class)); $this->get(ShoppingCart::remove_item_link($anotherproduct->ID, $product->class)); $items = ShoppingCart::get_items(); $this->assertEquals($items->Count(), 1, 'There is 1 item in the cart'); $this->assertEquals($items->First()->Quantity, 4, 'We have 4 mp3 players in the cart.'); ShoppingCart::clear(); //test clearing cart $this->assertEquals(ShoppingCart::get_items(), null, 'Cart is clear'); //items is a databoject set, and will therefore be null when cart is empty. //TODO: remove item not in cart - insanity check }
function clearandlogout() { $this->cart->clear(); if ($m = Member::currentUser()) { $m->logout(); } Director::redirect("/"); return false; }
function memberLoggedOut() { if (self::$associate_to_current_order) { ShoppingCart::clear(); } }
/** * Process the items in the shopping cart from session, * creating a new {@link Order} record, and updating the * customer's details {@link Member} record. * * {@link Payment} instance is created, linked to the order, * and payment is processed {@link Payment::processPayment()} * * @param array $data Form request data submitted from OrderForm * @param Form $form Form object for this action * @param HTTPRequest $request Request object for this action */ function processOrder($data, $form, $request) { $paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null; $payment = class_exists($paymentClass) ? new $paymentClass() : null; if (!($payment && $payment instanceof Payment)) { user_error(get_class($payment) . ' is not a valid Payment object!', E_USER_ERROR); } if (!ShoppingCart::has_items()) { $form->sessionMessage('Please add some items to your cart', 'bad'); Director::redirectBack(); return false; } // Create new OR update logged in {@link Member} record $member = EcommerceRole::createOrMerge($data); if (!$member) { $form->sessionMessage(_t('OrderForm.MEMBEREXISTS', 'Sorry, a member already exists with that email address. If this is your email address, please log in first before placing your order.'), 'bad'); Director::redirectBack(); return false; } $member->write(); $member->logIn(); // Create new Order from shopping cart, discard cart contents in session $order = ShoppingCart::save_current_order(); ShoppingCart::clear(); // Write new record {@link Order} to database $form->saveInto($order); $order->write(); // Save payment data from form and process payment $form->saveInto($payment); $payment->OrderID = $order->ID; $payment->Amount = $order->Total(); $payment->write(); // Process payment, get the result back $result = $payment->processPayment($data, $form); // isProcessing(): Long payment process redirected to another website (PayPal, Worldpay) if ($result->isProcessing()) { return $result->getValue(); } if ($result->isSuccess()) { $order->sendReceipt(); } Director::redirect($order->Link()); return true; }
function testClearEntireCart() { /* Invoke the existing test for adding items to the cart */ $this->testAddItemsToCart(); /* Get the items from the cart in session */ $items = ShoppingCart::get_items(); /* We have 1 item in the cart */ $this->assertEquals(count($items), 1, 'There is 1 item in the cart'); /* Clear the shopping cart */ ShoppingCart::clear(); /* Take a peek at what items are in the cart */ $items = ShoppingCart::get_items(); /* We have nothing in the cart */ $this->assertEquals(count($items), 0, 'There are no items in the cart'); /* Clear the shopping cart */ ShoppingCart::clear(); }
<?php require 'shoppingCart.class.php'; $cart = new ShoppingCart(); $action = isset($_GET['action']) ? $_GET['action'] : ''; $name = isset($_GET['name']) ? $_GET['name'] : 0; switch ($action) { case 'add': foreach ($products as $product) { if ($product['name'] == $name) { $cart->add($name); break; } } break; case 'empty': $cart->clear(); break; case 'remove': $cart->remove($name); break; } $items = $cart->getItems(); if (!empty($items)) { echo ' <table class="table"> <tr> <td><b>Product</b></td> <td><b>Price</b></td> <td><b>Qty</b></td> <td><b>Total</b></td> <td></td>
function testNoMemberOrder() { //TODO: test configuration that deines non-member orders //adjust configuration to allow non member orders OrderForm::set_user_membership_optional(true); OrderForm::set_force_membership(false); $socks = $this->objFromFixture('Product', 'socks'); $this->get(ShoppingCart::add_item_link($socks->ID)); //add a different product $cart = ShoppingCart::current_order(); $this->placeOrder('Donald', 'Duck', '*****@*****.**', '4 The Strand', null, 'Melbourne', null, 'AU'); $order = DataObject::get_by_id('Order', $cart->ID); $this->assertNotNull($order, 'Order exists'); if ($order) { $this->assertEquals($order->Status, 'Unpaid', 'status is now "unpaid"'); $this->assertEquals($order->MemberID, 0, 'No associated member'); $this->assertEquals($order->Total(), 8, 'grand total'); $this->assertEquals($order->TotalOutstanding(), 8, 'total outstanding'); $this->assertEquals($order->TotalPaid(), 0, 'total outstanding'); $this->assertEquals($order->FirstName, 'Donald', 'order first name'); $this->assertEquals($order->Surname, 'Duck', 'order surname'); $this->assertEquals($order->Email, '*****@*****.**', 'order email'); $this->assertEquals($order->Address, '4 The Strand'); $this->assertNull($order->AddressLine2, 'order address2'); $this->assertEquals($order->City, 'Melbourne', 'order city'); $this->assertNull($order->PostalCode, 'order postcode'); $this->assertEquals($order->Country, 'AU', 'order country'); } ShoppingCart::clear(); //cleanup }