/** * Clear the cart, and session variables on member logout */ public function memberLoggedOut() { if (Member::config()->login_joins_cart) { ShoppingCart::singleton()->clear(); OrderManipulation::clear_session_order_ids(); } }
public function testForm() { $order = $this->objFromFixture("Order", "unpaid"); OrderManipulation::add_session_order($order); $controller = new CheckoutPage_Controller($this->objFromFixture("CheckoutPage", "checkout")); $form = new OrderActionsForm($controller, "ActionsForm", $order); $form->dopayment(array('OrderID' => $order->ID, 'PaymentMethod' => 'Dummy'), $form); $this->assertEquals(1, $order->Payments()->count()); }
public function testActionsForm() { $order = $this->objFromFixture("Order", "unpaid"); OrderManipulation::add_session_order($order); $this->get("/checkout/order/" . $order->ID); //make payment action $this->post("/checkout/order/ActionsForm", array('OrderID' => $order->ID, 'PaymentMethod' => 'Dummy', 'action_dopayment' => 'submit')); //cancel action $this->post("/checkout/order/ActionsForm", array('OrderID' => $order->ID, 'action_docancel' => 'submit')); $this->markTestIncomplete('Add some assertions'); }
public function setUp() { parent::setUp(); ShopTest::setConfiguration(); // create order from fixture and persist to DB $this->order = $this->objFromFixture("Order", "unpaid"); $this->order->write(); OrderManipulation::add_session_order($this->order); // create checkoug page from fixture and publish it $this->checkoutPage = $this->objFromFixture("CheckoutPage", "checkout"); $this->checkoutPage->publish('Stage', 'Live'); Config::inst()->update('Payment', 'allowed_gateways', array('Dummy')); }
/** * Store old cart id in session order history */ public function archiveorderid() { $order = Order::get()->filter("Status:not", "Cart")->byId(Session::get(self::$cartid_session_name)); if ($order && !$order->IsCart()) { OrderManipulation::add_session_order($order); } $this->clear(); }
/** * Store old cart id in session order history * @param int|null $requestedOrderId optional parameter that denotes the order that was requested */ public function archiveorderid($requestedOrderId = null) { $sessionId = Session::get(self::config()->cartid_session_name); $order = Order::get()->filter("Status:not", "Cart")->byId($sessionId); if ($order && !$order->IsCart()) { OrderManipulation::add_session_order($order); } // 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(); } }
/** * Takes an order from being a cart to awaiting payment. * * @param Member $member - assign a member to the order * * @return boolean - success/failure */ public function placeOrder() { if (!$this->order) { $this->error(_t("OrderProcessor.NoOrderStarted", "A new order has not yet been started.")); return false; } if (!$this->canPlace($this->order)) { //final cart validation return false; } if ($this->order->Locale) { ShopTools::install_locale($this->order->Locale); } // recalculate order to be sure we have the correct total $this->order->calculate(); if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionStart(); } //update status if ($this->order->TotalOutstanding(false)) { $this->order->Status = 'Unpaid'; } else { $this->order->Status = 'Paid'; } if (!$this->order->Placed) { $this->order->Placed = SS_Datetime::now()->Rfc2822(); //record placed order datetime if ($request = Controller::curr()->getRequest()) { $this->order->IPAddress = $request->getIP(); //record client IP } } // Add an error handler that throws an exception upon error, so that we can catch errors as exceptions // in the following block. set_error_handler(function ($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); }, E_ALL & ~(E_STRICT | E_NOTICE)); try { //re-write all attributes and modifiers to make sure they are up-to-date before they can't be changed again $items = $this->order->Items(); if ($items->exists()) { foreach ($items as $item) { $item->onPlacement(); $item->write(); } } $modifiers = $this->order->Modifiers(); if ($modifiers->exists()) { foreach ($modifiers as $modifier) { $modifier->write(); } } //add member to order & customers group if ($member = Member::currentUser()) { if (!$this->order->MemberID) { $this->order->MemberID = $member->ID; } $cgroup = ShopConfig::current()->CustomerGroup(); if ($cgroup->exists()) { $member->Groups()->add($cgroup); } } //allow decorators to do stuff when order is saved. $this->order->extend('onPlaceOrder'); $this->order->write(); } catch (Exception $ex) { // Rollback the transaction if an error occurred if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionRollback(); } $this->error($ex->getMessage()); return false; } finally { // restore the error handler, no matter what restore_error_handler(); } // Everything went through fine, complete the transaction if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionEnd(); } //remove from session $cart = ShoppingCart::curr(); if ($cart && $cart->ID == $this->order->ID) { // clear the cart, but don't write the order in the process (order is finalized and should NOT be overwritten) ShoppingCart::singleton()->clear(false); } //send confirmation if configured and receipt hasn't been sent if (self::config()->send_confirmation && !$this->order->ReceiptSent) { $this->notifier->sendConfirmation(); } //notify admin, if configured if (self::config()->send_admin_notification) { $this->notifier->sendAdminNotification(); } // Save order reference to session OrderManipulation::add_session_order($this->order); return true; //report success }
/** * Takes an order from being a cart to awaiting payment. * * @param Member $member - assign a member to the order * * @return boolean - success/failure */ public function placeOrder() { if (!$this->order) { $this->error(_t("OrderProcessor.NULL", "A new order has not yet been started.")); return false; } if (!$this->canPlace($this->order)) { //final cart validation return false; } if ($this->order->Locale) { ShopTools::install_locale($this->order->Locale); } //remove from session $cart = ShoppingCart::curr(); if ($cart && $cart->ID == $this->order->ID) { ShoppingCart::singleton()->clear(); } //update status if ($this->order->TotalOutstanding()) { $this->order->Status = 'Unpaid'; } else { $this->order->Status = 'Paid'; } if (!$this->order->Placed) { $this->order->Placed = SS_Datetime::now()->Rfc2822(); //record placed order datetime if ($request = Controller::curr()->getRequest()) { $this->order->IPAddress = $request->getIP(); //record client IP } } //re-write all attributes and modifiers to make sure they are up-to-date before they can't be changed again $items = $this->order->Items(); if ($items->exists()) { foreach ($items as $item) { $item->onPlacement(); $item->write(); } } $modifiers = $this->order->Modifiers(); if ($modifiers->exists()) { foreach ($modifiers as $modifier) { $modifier->write(); } } //add member to order & customers group if ($member = Member::currentUser()) { if (!$this->order->MemberID) { $this->order->MemberID = $member->ID; } $cgroup = ShopConfig::current()->CustomerGroup(); if ($cgroup->exists()) { $member->Groups()->add($cgroup); } } //allow decorators to do stuff when order is saved. $this->order->extend('onPlaceOrder'); $this->order->write(); //send confirmation if configured and receipt hasn't been sent if (self::config()->send_confirmation && !$this->order->ReceiptSent) { $this->notifier->sendConfirmation(); } //notify admin, if configured if (self::config()->send_admin_notification) { $this->notifier->sendAdminNotification(); } // Save order reference to session OrderManipulation::add_session_order($this->order); return true; //report success }
static function set_allow_paying($pay = true) { self::$allow_paying = $pay; }
Object::useCustomClass('SS_Datetime', 'I18nDatetime', true); // * * * SHOPPING CART, ORDER, MODIFIERS Order::set_email(null); Order::set_receipt_subject("Shop Sale Information #%d"); Order::set_modifiers(array(), true); Order::set_table_overview_fields(array('ID' => 'Order No', 'Created' => 'Created', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Total' => 'Total', 'Status' => 'Status')); Order::set_maximum_ignorable_sales_payments_difference(0.01); Order::set_order_id_start_number(0); Order::set_cancel_before_payment(true); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(false); OrderForm::set_force_membership(true); OrderManipulation::set_allow_cancelling(false); OrderManipulation::set_allow_paying(false); // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation", "ProductAttributeType")); Product_Image::set_thumbnail_size(140, 100); Product_Image::set_content_image_width(200); Product_Image::set_large_image_width(200); ProductGroup::set_include_child_groups(true); ProductGroup::set_must_have_price(true); ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price')); // * * * CHECKOUT ExpiryDateField::set_short_months(true); OrderFormWithoutShippingAddress::set_fixed_country_code(null); OrderFormWithoutShippingAddress::set_postal_code_url("http://www.nzpost.co.nz/Cultures/en-NZ/OnlineTools/PostCodeFinder"); OrderFormWithoutShippingAddress::set_postal_code_label("find postcode"); OrderFormWithoutShippingAddress::set_login_invite_alternative_text('Please <a href="Security/login?BackURL=/">log in now</a> to retrieve your account details or create an account below.'); // * * * MEMBER
// Order::set_maximum_ignorable_sales_payments_difference(0.001); //sometimes there are small discrepancies in total (for various reasons)- here you can set the max allowed differences Order::set_order_id_start_number(1234567); //sets a start number for order ID, so that they do not start at one. Order::set_cancel_before_payment(false); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(); //optional for user to become a member OrderForm::set_force_membership(); //all users must become members if true, or won't become members if false OrderManipulation::set_allow_cancelling(); //shows a cancel button on the order page OrderManipulation::set_allow_paying(); //shows a payment form // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation")); Product_Image::set_thumbnail_size(140, 100); Product_Image::set_content_image_width(200); Product_Image::set_large_image_width(200); ProductGroup::set_include_child_groups(true); ProductGroup::set_must_have_price(true); ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price')); // * * * CHECKOUT ExpiryDateField::set_short_months(true); //uses short months (e.g. Jan instead of january) for credit card expiry date. OrderFormWithoutShippingAddress::set_fixed_country_code("NZ"); //country is fixed OrderFormWithoutShippingAddress::set_postal_code_url("http://maps.google.com");