public function __construct($controller, $name, $show_actions = true)
 {
     $TempBasketID = Store_BasketController::get_temp_basket_id();
     $order_id = DB::Query("SELECT id FROM `order` WHERE (`TempBasketID`='" . $TempBasketID . "')")->value();
     /* Basket GridField */
     $config = new GridFieldConfig();
     $dataColumns = new GridFieldDataColumns();
     $dataColumns->setDisplayFields(array('getPhoto' => "Photo", 'Title' => 'Product', 'Price' => 'Item Price', 'Quantity' => 'Quantity', 'productPrice' => 'Total Price', 'getfriendlyTaxCalculation' => 'Tax Inc/Exc', 'TaxClassName' => 'Tax'));
     $config->addComponent($dataColumns);
     $config->addComponent(new GridFieldTitleHeader());
     $basket = GridField::create("BasketItems", "", DataObject::get("Order_Items", "(OrderID='" . $order_id . "')"), $config);
     /* Basket Subtotal */
     $subtotal = new Order();
     $subtotal = $subtotal->calculateSubTotal($order_id);
     $subtotal = ReadonlyField::create("SubTotal", "Basket Total (" . Product::getDefaultCurrency() . ")", $subtotal);
     /* Fields */
     $fields = FieldList::create($basket, $subtotal, ReadonlyField::create("Tax", "Tax", "Calculated on the Order Summary page."));
     /* Actions */
     $actions = FieldList::create(CompositeField::create(FormAction::create('continueshopping', 'Continue Shopping'), FormAction::create('placeorder', 'Place Order')));
     /* Required Fields */
     $required = new RequiredFields(array());
     /*
      * Now we create the actual form with our fields and actions defined 
      * within this class.
      */
     return parent::__construct($controller, $name, $fields, $show_actions ? $actions : FieldList::create(), $required);
 }
 /**
  * Add fields to the CMS for this courier.
  */
 public function getCMSFields()
 {
     //Fetch the fields from the Courier DataObject
     $fields = parent::getCMSFields();
     //Add new fields
     $fields->addFieldsToTab("Root.Main", array(HeaderField::create("Item Rate"), CompositeField::create(NumericField::create("FlatRate", "Item Rate (" . Product::getDefaultCurrency() . ")")->setRightTitle("Enter a flat rate of shipping to charge for every item in this order."))));
     return $fields;
 }
 /**
  * Add fields to the CMS for this courier.
  */
 public function getCMSFields()
 {
     //Fetch the fields from the Courier DataObject
     $fields = parent::getCMSFields();
     //Add new fields
     $fields->addFieldsToTab("Root.Main", array(HeaderField::create("Minimum Spend"), CompositeField::create(NumericField::create("MinSpend", "Qualifying Spend (" . Product::getDefaultCurrency() . ")")->setRightTitle("Enter the amount a customer must spend before qualifying for Free Shipping."))));
     return $fields;
 }
 public function __construct($controller, $name, $order)
 {
     /* Fields */
     $fields = FieldList::create(ReadonlyField::create("Shipping", "Shipping Total (" . Product::getDefaultCurrency() . ")", $shipping_total = Order::create()->calculateShippingTotal($order->ID, $order->Courier)), FieldGroup::create("Tax (" . Product::getDefaultCurrency() . ")", ReadonlyField::create("ProductTaxInclusive", "Product Tax (Inclusive)", Order::create()->calculateProductTax(1, $order))->setRightTitle("Basket total is inclusive of this tax."), ReadonlyField::create("ProductTaxExclusive", "Product Tax (Exclusive)", $exc_product_tax = Order::create()->calculateProductTax(2, $order))->setRightTitle("Basket total is exclusive of this tax."), ReadonlyField::create("ShippingTax", "Shipping Tax", $shipping_tax = Order::create()->calculateShippingTax(Order::create()->calculateShippingTotal($order->ID, $order->Courier), $order))->setRightTitle(StoreSettings::get_settings()->TaxSettings_ShippingInclusiveExclusive == 1 ? "Shipping price is inclusive of this tax." : "Shipping price is exclusive of this tax.")), ReadonlyField::create("Total", "Final Total", Order::create()->calculateOrderTotal($order)));
     /* Actions */
     $actions = FieldList::create();
     /* Required Fields */
     $required = new RequiredFields(array());
     /*
      * Now we create the actual form with our fields and actions defined 
      * within this class.
      */
     return parent::__construct($controller, $name, $fields, $actions, $required);
 }
 /**
  * getCMSFields
  * Alter the FieldList provided by the Member class to 
  * the requirements of an online store.
  * 
  * @return FieldList
  */
 public function getCMSFields()
 {
     Requirements::css('torindul-silverstripe-shop/css/LeftAndMain.css');
     $fields = parent::getCMSFields();
     /** REMOVE SCAFFOLDED FIELDS TO ADD LATER
      * -- Locale is removed. As these users will not use the CMS itself so the default values will suffice for now.
      * -- DirectGroups is removed. Customer group membership is handled by onAfterWrite().
      * -- DateFormat and TimeFormat are removed. The default will be fine for nearly all installations.
      * -- Those fields not mentioned are re-added later.
      */
     $fields->removeFieldsFromTab("Root.Main", array("FirstName", "Surname", "CompanyName", "Email", "Password", "StoreCredit", "LandlineNumber", "MobileNumber", "DirectGroups", "Locale", "FailedLoginCount", "LastVisited", "TimeFormat", "DateFormat"));
     //If the customer record has been created, display the ID of the record as the account number.
     if ($this->exists()) {
         $fields->addFieldsToTab("Root.Main", array(HeaderField::create("Account Details"), CompositeField::create(ReadonlyField::create("AccountNo", "Account Number", $this->ID), ReadonlyField::create("LastVisited", "Last Signed In", $this->LastVisited), NumericField::create("StoreCredit", "StoreCredit")->setRightTitle("The amount of credit this customer can spend on orders in your store."))));
     }
     //Add Customer Details Fields
     $fields->addFieldsToTab("Root.Main", array(HeaderField::create("Customer Details"), CompositeField::create(TextField::create("FirstName", "First Name"), TextField::create("Surname", "Surname"), TextField::create("CompanyName", "Company Name"), TextField::create("LandlineNumber", "Landline Number"), TextField::create("MobileNumber", "Mobile Number")), HeaderField::create("Login Details"), CompositeField::create(EmailField::create("Email", "Email Address"), NumericField::create("FailedLoginCount", "Failed Login Count")->setRightTitle("The total number of failed login attempts this customer has made. Set to 0 to unblock their account."))));
     //Add Confirmed Password Field befoe the FailedLoginCount field
     $password = ConfirmedPasswordField::create('Password', null, null, null, true)->setCanBeEmpty(true);
     if (!$this->ID) {
         $password->showOnClick = false;
     }
     $fields->addFieldToTab("Root.Main", $password, "FailedLoginCount");
     //Customer Address Book Tab
     $fields->addFieldsToTab("Root.AddressBook", array(HeaderField::create($this->exists() ? $this->FirstName . " " . $this->Surname . "'s Address Book" : "Customer Address Book"), CompositeField::create(LiteralField::create($title = "CustomFieldsDescription", "<div class=\"literal-field literal-field-noborder\">\n\t\t\t\t\t\tThe address book is used to store multiple customer addresses for shipping and billing purposes.\n\t\t\t\t\t</div>"), $this->exists() ? GridField::create("Customer_AddressBook", "", $this->Addresses(), GridFieldConfig_RecordEditor::create()) : LiteralField::create($title = "AddressBookNotice", "<div class=\"literal-field field\">\n\t\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"message notice\">\n\t\t\t\t\t\t\t<i class=\"fa fa-info-circle\"></i>\n\t\t\t\t\t\t\tThis customer doesn't exist in the system yet. To be able to see addresses for this customer you must first \n\t\t\t\t\t\t\tclick create.\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\n\t\t\t\t\t</div>"))));
     //Customer Orders Tab
     $fields->addFieldsToTab("Root.Orders", array(HeaderField::create($this->exists() ? $this->FirstName . " " . $this->Surname . "'s Orders" : "Customer Orders"), CompositeField::create(LiteralField::create($title = "CustomFieldsDescription", "<div class=\"literal-field literal-field-noborder\">\n\t\t\t\t\t\tIf this customer has placed orders with your store you can see them below.\n\t\t\t\t\t</div>"), $this->exists() ? GridField::create("Customers_Orders", "", $this->Orders(), GridFieldConfig_RecordEditor::create()) : LiteralField::create($title = "OrdersNotice", "<div class=\"literal-field field\">\n\t\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"message notice\">\n\t\t\t\t\t\t\t<i class=\"fa fa-info-circle\"></i>\n\t\t\t\t\t\t\tThis customer doesn't exist in the system yet. To be able to see orders for this customer you must first \n\t\t\t\t\t\t\tclick create.\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\n\t\t\t\t\t</div>"))));
     //Update Store Credit Field
     $storecredit = NumericField::create("StoreCredit", "Store Credit (" . Product::getDefaultCurrency() . ")");
     $fields->replaceField("StoreCredit", $storecredit);
     //Remove Automatically Generated Address GridField
     $fields->removeFieldFromTab("Root", "Addresses");
     $fields->removeFieldFromTab("Root", "Permissions");
     $fields->removeFieldFromTab("Root.Orders", "Orders");
     return $fields;
 }
 public function getCouriers($order_id = null, $show_price = null)
 {
     if ($this->exists() || !is_null($order_id)) {
         //Variable to hold available couriers
         $couriers = array();
         //Fetch all Enabled Couriers
         $query = new SQLQuery();
         $query->setFrom('Courier')->addWhere("(`Enabled`='1')");
         //Result of query
         $result = $query->execute();
         //Iterate over each courier and if check_criteria_met() method returns true, add to the available array.
         foreach ($result as $row) {
             //Class of the Courier
             $ClassName = $row["ClassName"];
             //Does check_criteria_met() equal true, if yes add to couriers array.
             if ($ClassName::check_criteria_met($order_id)) {
                 //If $show_price equal to true, show the price with the Courier name.
                 if ($show_price) {
                     $title = $row["Title"] . " (" . Product::getDefaultCurrency() . $ClassName::calculate_shipping_total($order_id) . ")";
                 } else {
                     $title = $row["Title"];
                 }
                 $couriers[$row["ID"]] = $title;
             } else {
             }
         }
         return $couriers;
     }
 }
 /**
  * productPrice
  * Price to display in the GridField 
  *
  * @return float The product price.
  */
 public function productPrice()
 {
     /* Discounted CSS Class */
     $discounted = $this->Discounted != 0 ? "GridFieldSaleNewPrice" : "";
     /* Price of the Product * Quantity */
     $price = StoreCurrency::convertToCurrency($this->Price * $this->Quantity);
     /* Field to Create */
     $text = LiteralField::create($title = "Price", "");
     $text->setValue("<span class='{$discounted}'>" . Product::getDefaultCurrency() . $price . "</span>");
     return $text;
 }
 public function customerOrderStatusUpdate($order_no, $status, $override = false)
 {
     //Get Store Settings
     $settings = StoreSettings::get_settings();
     //Get the details of both the order, the customer who placed it and the status
     $order = DataObject::get_by_id("Order", $order_no);
     $customer = DataObject::get_by_id("Customer", $order->CustomerID);
     $status = DataObject::get_one("Order_Statuses", "(`SystemTitle`='" . $status . "')");
     /**
      * If override is set, set the send flag to true.
      * Otherwise, check the store notification settings tpo
      * see if we're allowed to send this status update email. 
      */
     if ($override) {
         $send = true;
     } else {
         //Convert store notification settings to array
         $enabled_statuses = explode(",", $settings->EmailNotification_OrderStatuses);
         //Is the new status in this array, if yes, send send to true.
         $send = in_array($status->ID, $enabled_statuses) ? true : false;
     }
     /**
      * If $send is equal to true send the email notification.
      */
     if ($send) {
         //Send The Email
         $email = new Email();
         $email->setFrom($settings->EmailNotification_SendEmailsFrom)->setTo($customer->Email)->setSubject('Order [' . $order_no . '] has been updated')->setTemplate('Email_Order_StatusUpdate')->populateTemplate(new ArrayData(array('StoreName' => $settings->StoreSettings_StoreName, 'Customer' => $customer, 'Order' => $order, 'OrderStatus' => $status, 'OrderLink' => '', 'OrderItems' => DataObject::get("Order_Items", "(`OrderID`='" . $order->ID . "')"), 'OrderCourier' => DataObject::get_one("Courier", "(`id`='" . $order->Courier . "')")->Title, 'OrderTrackingNo' => $order->TrackingNo ? $order->TrackingNo : "No tracking number provided for this order", 'ProductTax' => StoreCurrency::convertToCurrency($order->calculateProductTax(1) + $order->calculateProductTax(2)), 'BillingAddress' => DataObject::get_one("Customer_AddressBook", "(`id`='" . $order->BillingAddressID . "')"), 'ShippingAddress' => DataObject::get_one("Customer_AddressBook", "(`id`='" . $order->BillingAddressID . "')"), 'CurrencySymbol' => Product::getDefaultCurrency())));
         $email->send();
         //Store the email in the order email log
         $this->SentTo = $customer->Email . " (CUSTOMER)";
         $this->Subject = 'Order [' . $order_no . '] has been updated';
         $this->Body = $email->body;
         $this->OrderID = $order_no;
         $this->write();
         return true;
     } else {
         return false;
     }
 }