function run($request)
 {
     $orderStatusLogClassName = "OrderStatusLog";
     $submittedOrderStatusLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     if ($submittedOrderStatusLogClassName) {
         $sampleSubmittedStatusLog = DataObject::get_one($submittedOrderStatusLogClassName);
         if ($sampleSubmittedStatusLog) {
             $lastOrderStep = DataObject::get_one("OrderStep", "", "\"Sort\" DESC");
             if ($lastOrderStep) {
                 $joinSQL = "INNER JOIN \"{$orderStatusLogClassName}\" ON \"{$orderStatusLogClassName}\".\"OrderID\" = \"Order\".\"ID\"";
                 $whereSQL = "WHERE \"StatusID\" <> " . $lastOrderStep->ID . " AND \"{$orderStatusLogClassName}\".ClassName = '{$submittedOrderStatusLogClassName}'";
                 $count = DB::query("\r\n\t\t\t\t\t\tSELECT COUNT (\"Order\".\"ID\")\r\n\t\t\t\t\t\tFROM \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t")->value();
                 $do = DB::query("\r\n\t\t\t\t\t\tUPDATE \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\tSET \"StatusID\" = " . $lastOrderStep->ID . "\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t");
                 if ($count) {
                     DB::alteration_message("NOTE: {$count} records were updated.", "created");
                 } else {
                     DB::alteration_message("No records were updated.");
                 }
             } else {
                 DB::alteration_message("Could not find the last order step.", "deleted");
             }
         } else {
             DB::alteration_message("Could not find any submitted order logs.", "deleted");
         }
     } else {
         DB::alteration_message("Could not find a class name for submitted orders.", "deleted");
     }
 }
 function run($request)
 {
     db::alteration_message("========================== <br />creating customer group", "created");
     $this->CreateGroup($code = EcommerceConfig::get("EcommerceRole", "customer_group_code"), $name = EcommerceConfig::get("EcommerceRole", "customer_group_name"), $parentGroup = null, $permissionCode = EcommerceConfig::get("EcommerceRole", "customer_permission_code"), $roleTitle = "", $permissionArray = array(), $member = null);
     db::alteration_message("========================== <br />creating sales manager", "created");
     $email = EcommerceConfig::get("EcommerceRole", "admin_group_user_email");
     if (!$email) {
         $email = "websales@" . $_SERVER['HTTP_HOST'];
     }
     if (!$member) {
         $member = Member::create();
     }
     $firstName = EcommerceConfig::get("EcommerceRole", "admin_group_user_first_name");
     if (!$firstName) {
         $firstName = "Web";
     }
     $surname = EcommerceConfig::get("EcommerceRole", "admin_group_user_surname");
     if (!$surname) {
         $surname = "Sales";
     }
     $member = Member::get()->filter(array("Email" => $email))->first();
     if (!$member) {
         $member = Member::create();
     }
     $member->FirstName = $firstName;
     $member->Surname = $surname;
     $member->Email = $email;
     if (!$member->Password) {
         $password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+<>?:"{}|[]|'), 0, 16);
         $member->Password = $password;
     }
     $member->write();
     db::alteration_message("================================<br />creating shop admin group ", "created");
     $this->CreateGroup($code = EcommerceConfig::get("EcommerceRole", "admin_group_code"), $name = EcommerceConfig::get("EcommerceRole", "admin_group_name"), $parentGroup = null, $permissionCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code"), $roleTitle = EcommerceConfig::get("EcommerceRole", "admin_role_title"), $permissionArray = EcommerceConfig::get("EcommerceRole", "admin_role_permission_codes"), $member);
 }
 /**
  *NOTE: we semi-enforce using the OrderModifier_Controller here to deal with the submission of the OrderModifierForm
  * You can use your own modifiers or an extension of OrderModifier_Controller by setting the first parameter (optionalController)
  * to your own controller.
  *
  *@param $optionalController Controller
  *@param $name String
  *@param $fields FieldList
  *@param $actions FieldList
  *@param $validator SS_Validator
  **/
 function __construct(Controller $optionalController = null, $name, FieldList $fields, FieldList $actions, Validator $optionalValidator = null)
 {
     if (!$optionalController) {
         $controllerClassName = EcommerceConfig::get("OrderModifierForm", "controller_class");
         $optionalController = new $controllerClassName();
     }
     if (!$optionalValidator) {
         $validatorClassName = EcommerceConfig::get("OrderModifierForm", "validator_class");
         $optionalValidator = new $validatorClassName();
     }
     parent::__construct($optionalController, $name, $fields, $actions, $optionalValidator);
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $optionalValidator);
     $this->setValidator($optionalValidator);
     $this->setAttribute("autocomplete", "off");
     Requirements::themedCSS($this->ClassName, 'ecommerce');
     $this->addExtraClass($this->myLcFirst(ucwords($name)));
     Requirements::javascript(THIRDPARTY_DIR . "/jquery-form/jquery.form.js");
     //add JS for the modifier - added in modifier
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateOrderModifierForm', $this);
 }
 /**
  * Standard SS method.
  * Runs after the Page::init method is called.
  */
 function onAfterInit()
 {
     Requirements::javascript(EcommerceConfig::get("EcommerceConfigAjax", "cart_js_file_location"));
     Requirements::javascript(EcommerceConfig::get("EcommerceConfigAjax", "dialogue_js_file_location"));
     Requirements::themedCSS("Cart");
     Requirements::themedCSS("jquery.colorbox");
 }
 function run($request)
 {
     $count = 0;
     $array = EcommerceCountry::get_country_dropdown();
     $allowedArray = EcommerceConfig::get("EcommerceCountry", "allowed_country_codes");
     foreach ($array as $code => $name) {
         $ecommerceCountry = EcommerceCountry::get()->Filter(array("Code" => Convert::raw2sql($code)))->First();
         if ($ecommerceCountry) {
             //do nothing
             $count++;
         } else {
             DB::alteration_message("adding {$code} to Ecommerce Country", "created");
             $ecommerceCountry = EcommerceCountry::create();
             $ecommerceCountry->Code = $code;
         }
         if ($allowedArray && count($allowedArray)) {
             if (in_array($code, $allowedArray)) {
                 //do nothing
                 $ecommerceCountry->DoNotAllowSales = 0;
             } else {
                 $ecommerceCountry->DoNotAllowSales = 1;
             }
         }
         $ecommerceCountry->Name = $name;
         $ecommerceCountry->write();
     }
     DB::alteration_message("Created / Checked {$count} Ecommerce Countries", "edited");
 }
 /**
  * set the requestor
  * @param DataObject $do - the object that requested the data.
  */
 public function setRequestor($do)
 {
     if (self::$prefix === null) {
         self::$prefix = EcommerceConfig::get("Order", "template_id_prefix");
     }
     $this->requestor = $do;
 }
 protected function createSubmissionLogForArchivedOrders()
 {
     $lastOrderStep = OrderStep::get()->sort("Sort", "DESC")->First();
     $submissionLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     $obj = $submissionLogClassName::create();
     if (!is_a($obj, Object::getCustomClass("OrderStatusLog"))) {
         user_error('EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order") refers to a class that is NOT an instance of OrderStatusLog');
     }
     $orderStatusLogClassName = "OrderStatusLog";
     $offset = 0;
     $orders = $this->getOrdersForCreateSubmissionLogForArchivedOrders($lastOrderStep, $orderStatusLogClassName, $offset);
     while ($orders->count()) {
         foreach ($orders as $order) {
             $isSubmitted = $submissionLogClassName::get()->Filter(array("OrderID" => $order->ID))->count();
             if (!$isSubmitted) {
                 $obj = $submissionLogClassName::create();
                 $obj->OrderID = $order->ID;
                 //it is important we add this here so that we can save the 'submitted' version.
                 //this is particular important for the Order Item Links.
                 $obj->write();
                 $obj->OrderAsHTML = $order->ConvertToHTML();
                 $obj->write();
                 DB::alteration_message("creating submission log for Order #" . $obj->OrderID, "created");
             }
         }
         $offset += 100;
         $orders = $this->getOrdersForCreateSubmissionLogForArchivedOrders($lastOrderStep, $orderStatusLogClassName, $offset);
     }
 }
 function setActualQuantity($value)
 {
     if (!$this->owner->ID) {
         $this->owner->write();
     }
     //only set stock level if it differs from previous
     $shopAdminCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
     if ($this->owner->ID) {
         if ($shopAdminCode && Permission::check($shopAdminCode)) {
             if ($value != $this->owner->getActualQuantity()) {
                 $parent = BuyableStockCalculatedQuantity::get_by_buyable($this->owner);
                 if ($parent) {
                     $member = Member::currentUser();
                     $obj = new BuyableStockManualUpdate();
                     $obj->ParentID = $parent->ID;
                     $obj->Quantity = (int) $value;
                     $obj->MemberID = $member->ID;
                     $obj->write();
                 } else {
                     user_error("Could not write BuyableStockCalculatedQuantity Object because there was no parent " . $this->owner->Title);
                 }
             }
         } else {
             user_error("Could not write BuyableStockCalculatedQuantity Object because you do not have permissions " . $this->owner->Title);
         }
     }
 }
 function run($request)
 {
     //IMPORTANT!
     Config::inst()->update("Email", "send_all_emails_to", "no-one@localhost");
     Email::set_mailer(new EcommerceTaskTryToFinaliseOrders_Mailer());
     $orderStatusLogClassName = "OrderStatusLog";
     $submittedOrderStatusLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     if ($submittedOrderStatusLogClassName) {
         $sampleSubmittedStatusLog = $submittedOrderStatusLogClassName::get()->First();
         if ($sampleSubmittedStatusLog) {
             $lastOrderStep = OrderStep::get()->sort("Sort", "DESC")->First();
             if ($lastOrderStep) {
                 $joinSQL = "INNER JOIN \"{$orderStatusLogClassName}\" ON \"{$orderStatusLogClassName}\".\"OrderID\" = \"Order\".\"ID\"";
                 $whereSQL = "WHERE \"StatusID\" <> " . $lastOrderStep->ID . " AND \"{$orderStatusLogClassName}\".ClassName = '{$submittedOrderStatusLogClassName}'";
                 $count = DB::query("\r\n\t\t\t\t\t\tSELECT COUNT (\"Order\".\"ID\")\r\n\t\t\t\t\t\tFROM \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t")->value();
                 $do = DB::query("\r\n\t\t\t\t\t\tUPDATE \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\tSET \"Order\".\"StatusID\" = " . $lastOrderStep->ID . "\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t");
                 if ($count) {
                     DB::alteration_message("NOTE: {$count} records were updated.", "created");
                 } else {
                     DB::alteration_message("No records were updated.");
                 }
             } else {
                 DB::alteration_message("Could not find the last order step.", "deleted");
             }
         } else {
             DB::alteration_message("Could not find any submitted order logs.", "deleted");
         }
     } else {
         DB::alteration_message("Could not find a class name for submitted orders.", "deleted");
     }
 }
 protected function canDoAnything($member = null)
 {
     $shopAdminCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
     if (!Permission::check($shopAdminCode)) {
         Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need administrator rights to access it. Enter your credentials below and we will send you right along.'));
     }
     return true;
 }
 protected static function get_default_country_code_combined()
 {
     $country = Config::inst()->get("GSTTaxModifier", "default_country_code");
     if (!$country) {
         $country = EcommerceConfig::get('EcommerceCountry', 'default_country_code');
     }
     return $country;
 }
 /**
  * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields
  * @param FieldList $fields
  * @param Order $order
  * @return FieldList
  **/
 function addOrderStepFields(FieldList $fields, Order $order)
 {
     $fields = parent::addOrderStepFields($fields, $order);
     $title = _t("OrderStep.MUSTDOPAYMENTCHECK", " ... To move this order to the next step you must carry out a payment check (is the money in the bank?) by creating a record here (click me)");
     $fields->addFieldToTab("Root.Next", $order->getOrderStatusLogsTableField("OrderStatusLog_PaymentCheck", $title), "ActionNextStepManually");
     $fields->addFieldToTab("Root.Next", new LiteralField("ExampleOfThingsToCheck", "<ul><li>" . implode("</li><li>", EcommerceConfig::get("OrderStep_Confirmed", "list_of_things_to_check")) . "</li></ul>"), "ActionNextStepManually");
     return $fields;
 }
 /**
  * Returns the singleton instance of the Ajax Config definitions class.
  * This class basically contains a bunch of methods that return
  * IDs and Classes for use with AJAX.
  *
  * @param DataObject $requestor the object requesting the Ajax Config Definitions
  * @return EcommerceConfigAjaxDefinitions (or other object)
  */
 public static function get_one($requestor)
 {
     if (!isset(self::$singleton[$requestor->ClassName][$requestor->ID])) {
         $className = EcommerceConfig::get("EcommerceConfigAjax", "definitions_class_name");
         self::$singleton[$requestor->ClassName][$requestor->ID] = new $className();
         self::$singleton[$requestor->ClassName][$requestor->ID]->setRequestor($requestor);
     }
     return self::$singleton[$requestor->ClassName][$requestor->ID];
 }
 /**
  * standard Silverstripe method - required
  *
  */
 function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // or if on CLI.
     // Access to this controller is always allowed in "dev-mode", or if the user is ADMIN.
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN") || Permission::check(EcommerceConfig::get("EcommerceRole", "admin_group_code"));
     if (!$canAccess) {
         return Security::permissionFailure($this, "The e-commerce development control panel is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
 }
 public function doStep($order)
 {
     $noNeedToCheck = false;
     if ($this->doesNotNeedToBeChecked($order)) {
         $subject = $this->EmailSubject;
         if ($subject) {
             $message = "";
             if (!$this->hasBeenSent($order)) {
                 $order->sendEmail($subject, $message, $resend = false, $adminOnly = false, $emailClass = 'Order_StatusEmail');
             }
         }
     } else {
         $noNeedToCheck = true;
     }
     if ($noNeedToCheck || $this->hasBeenChecked($order)) {
         if (!$order->IsSubmitted()) {
             $className = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
             if (class_exists($className)) {
                 $obj = new $className();
                 if ($obj instanceof OrderStatusLog) {
                     $obj->OrderID = $order->ID;
                     $obj->Title = $this->Name;
                     //it is important we add this here so that we can save the 'submitted' version.
                     //this is particular important for the Order Item Links.
                     $obj->write();
                     $saved = false;
                     if ($this->SaveOrderAsJSON) {
                         $obj->OrderAsJSON = $order->ConvertToJSON();
                         $saved = true;
                     }
                     if ($this->SaveOrderAsHTML) {
                         $obj->OrderAsHTML = $order->ConvertToHTML();
                         $saved = true;
                     }
                     if ($this->SaveOrderAsSerializedObject || !$saved) {
                         $obj->OrderAsString = $order->ConvertToString();
                         $saved = true;
                     }
                     $obj->write();
                 } else {
                     user_error('EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order") refers to a class that is NOT an instance of OrderStatusLog');
                 }
             } else {
                 user_error('EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order") refers to a non-existing class');
             }
         }
         return true;
     }
     return false;
 }
 /**
  * @return array Map of class name to an array of 'title' (see {@link $managed_models})
  */
 function getManagedModels()
 {
     $models = EcommerceConfig::get($this->class, "managed_models");
     foreach ($models as $key => $model) {
         if (is_array($model)) {
             $model = $key;
         }
         if (!class_exists($model)) {
             unset($models[$key]);
         }
     }
     Config::inst()->update('ModelAdminEcommerceBaseClass', 'managed_models', $models);
     return parent::getManagedModels();
 }
 /**
  *NOTE: we semi-enforce using the OrderLog_Controller here to deal with the submission of the OrderStatusLogForm
  * You can use your own Logs or an extension of OrderLog_Controller by setting the first parameter (optionalController)
  * to your own controller.
  *
  *@param $optionalController Controller
  *@param $name String
  *@param $fields FieldSet
  *@param $actions FieldSet
  *@param $validator SS_Validator
  **/
 function __construct($optionalController = null, $name, FieldSet $fields, FieldSet $actions, $optionalValidator = null)
 {
     if (!$optionalController) {
         $controllerClassName = EcommerceConfig::get("OrderStatusLogForm", "controller_class");
         $optionalController = new $controllerClassName();
     }
     if (!$optionalValidator) {
         $validatorClassName = EcommerceConfig::get("OrderStatusLogForm", "validator_class");
         $optionalValidator = new $validatorClassName();
     }
     parent::__construct($optionalController, $name, $fields, $actions, $optionalValidator);
     Requirements::themedCSS($this->ClassName);
     Requirements::javascript(THIRDPARTY_DIR . "/jquery-form/jquery.form.js");
     //add JS for the Log - added in Log
 }
 function init()
 {
     // Only administrators can run this method
     $shopAdminCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
     if (!Permission::check("ADMIN") && !Permission::check($shopAdminCode)) {
         Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need administrator rights to access it. Enter your credentials below and we will send you right along.'));
     }
     parent::init();
     Requirements::themedCSS("StockControlPage", 'ecommerce_stockcontrol');
     Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
     //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js");
     //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
     Requirements::javascript("ecommerce_stockcontrol/javascript/StockControlPage.js");
     $url = Director::absoluteURL($this->Link() . "update/");
     Requirements::customScript("StockControlPage.set_url('" . $url . "');", "StockControlPage.set_url");
 }
 function run($request)
 {
     $arrayOfBuyables = EcommerceConfig::get("EcommerceDBConfig", "array_of_buyables");
     foreach ($arrayOfBuyables as $buyable) {
         if ($allproducts = DataObject::get($buyable)) {
             foreach ($allproducts as $product) {
                 if ($product instanceof SiteTree) {
                     $product->deleteFromStage('Live');
                     $product->deleteFromStage('Stage');
                 } else {
                     $product->delete();
                 }
                 $product->destroy();
                 //TODO: remove versions
             }
         }
     }
 }
 function run($request)
 {
     //reset time limit
     set_time_limit(1200);
     //file data
     $now = Date("d-m-Y-H-i");
     $fileName = "export-{$now}.csv";
     //data object variables
     $orderStatusSubmissionLog = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     $fileData = "";
     $offset = 0;
     $count = 50;
     while ($orders = Order::get()->sort("\"Order\".\"ID\" ASC")->innerJoin("OrderStatusLog", "\"Order\".\"ID\" = \"OrderStatusLog\".\"OrderID\"")->innerJoin($orderStatusSubmissionLog, "\"{$orderStatusSubmissionLog}\".\"ID\" = \"OrderStatusLog\".\"ID\"")->leftJoin("Member", "\"Member\".\"ID\" = \"Order\".\"MemberID\"")->limit($count, $offset) && ($ordersCount = $orders->count())) {
         $offset = $offset + $count;
         foreach ($orders as $order) {
             if ($order->IsSubmitted()) {
                 $memberIsOK = false;
                 if (!$order->MemberID) {
                     $memberIsOK = true;
                 } elseif (!$order->Member()) {
                     $memberIsOK = true;
                 } elseif ($member = $order->Member()) {
                     $memberIsOK = true;
                     if ($member->IsShopAdmin()) {
                         $memberIsOK = false;
                     }
                 }
                 if ($memberIsOK) {
                     $items = OrderItem::get()->filter(array("OrderID" => $order->ID));
                     if ($items && $items->count()) {
                         $fileData .= $this->generateExportFileData($order->getOrderEmail(), $order->SubmissionLog()->Created, $items);
                     }
                 }
             }
         }
         unset($orders);
     }
     if ($fileData) {
         SS_HTTPRequest::send_file($fileData, $fileName, "text/csv");
     } else {
         user_error("No records found", E_USER_ERROR);
     }
 }
 function run($request)
 {
     $arrayOfBuyables = EcommerceConfig::get("EcommerceDBConfig", "array_of_buyables");
     foreach ($arrayOfBuyables as $buyable) {
         $allproducts = $buyable::get();
         if ($allproducts->count()) {
             foreach ($allproducts as $product) {
                 DB::alteration_message("Deleting " . $product->ClassName . " ID = " . $product->ID, "deleted");
                 if (is_a($product, Object::getCustomClass("SiteTree"))) {
                     $product->deleteFromStage('Live');
                     $product->deleteFromStage('Stage');
                 } else {
                     $product->delete();
                 }
                 $product->destroy();
                 //TODO: remove versions
             }
         }
     }
 }
 function run($request)
 {
     //set starting order number ID
     $number = EcommerceConfig::get("Order", "order_id_start_number");
     $currentMax = 0;
     //set order ID
     if ($number) {
         $count = DB::query("SELECT COUNT( \"ID\" ) FROM \"Order\" ")->value();
         if ($count > 0) {
             $currentMax = DB::Query("SELECT MAX( \"ID\" ) FROM \"Order\"")->value();
         }
         if ($number > $currentMax) {
             DB::query("ALTER TABLE \"Order\"  AUTO_INCREMENT = {$number} ROW_FORMAT = DYNAMIC ");
             DB::alteration_message("Change OrderID start number to " . $number, "created");
         } else {
             DB::alteration_message("Can not set OrderID start number to " . $number . " because this number has already been used.", "deleted");
         }
     } else {
         DB::alteration_message("Starting OrderID has not been set.", "deleted");
     }
 }
 /**
  * this method returns an associative array of payment methods
  * available for the current order.
  *
  * @return array
  */
 public function SupportedMethods($order = null)
 {
     $hideTestPaymentMethods = false;
     if (Director::isLive()) {
         $hideTestPaymentMethods = false;
     }
     $supportedMethods = EcommerceConfig::get("EcommercePayment", "supported_methods");
     if (ArrayLib::is_associative($supportedMethods)) {
         if ($hideTestPaymentMethods) {
             if (count($supportedMethods)) {
                 foreach ($supportedMethods as $methodClass => $methodTitle) {
                     if (is_subclass_of($methodClass, "EcommercePayment_Test")) {
                         unset($supportedMethods[$methodClass]);
                     }
                 }
             }
         }
     } else {
         user_error('EcommercePayment::$supported_methods() requires an associative array. Right now the supported payments methods are: ' . print_r($supportedMethods, 1), E_USER_NOTICE);
     }
     return $supportedMethods;
 }
 /**
  * Puts together the fields for the Order Form (and other front-end purposes).
  * @return Fieldset
  **/
 public function getFields($member = null)
 {
     $fields = parent::getEcommerceFields();
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $shippingFieldsHeader = new CompositeField(new HeaderField('SendGoodsToADifferentAddress', _t('OrderAddress.SENDGOODSTODIFFERENTADDRESS', 'Send goods to different address'), 3), new LiteralField('ShippingNote', '<p class="message warning">' . _t('OrderAddress.SHIPPINGNOTE', 'Your goods will be sent to the address below.') . '</p>'), new LiteralField('ShippingHelp', '<p>' . _t('OrderAddress.SHIPPINGHELP', 'You can use this for gift giving. No billing information will be disclosed to this address.') . '</p>'));
         if ($member) {
             if ($member->exists()) {
                 $addresses = $this->previousAddressesFromMember($member);
                 if ($addresses) {
                     if ($addresses->count() > 1) {
                         $shippingFieldsHeader->push(new SelectOrderAddressField('SelectShippingAddressField', _t('OrderAddress.SELECTBILLINGADDRESS', 'Select Shipping Address'), $addresses));
                     }
                 }
             }
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         } else {
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         }
         $shippingFields->push(new TextField('ShippingPrefix', _t('OrderAddress.PREFIX', 'Title (e.g. Ms)')));
         $shippingFields->push(new TextField('ShippingAddress', _t('OrderAddress.ADDRESS', 'Address')));
         $shippingFields->push(new TextField('ShippingAddress2', _t('OrderAddress.ADDRESS2', '&nbsp;')));
         $shippingFields->push(new TextField('ShippingCity', _t('OrderAddress.CITY', 'Town')));
         $shippingFields->push($this->getPostalCodeField("ShippingPostalCode"));
         $shippingFields->push($this->getRegionField("ShippingRegionID"));
         $shippingFields->push($this->getCountryField("ShippingCountry"));
         $shippingFields->push(new TextField('ShippingPhone', _t('OrderAddress.PHONE', 'Phone')));
         $shippingFields->push(new TextField('ShippingMobilePhone', _t('OrderAddress.MOBILEPHONE', 'Mobile Phone')));
         $this->makeSelectedFieldsReadOnly($shippingFields);
         $shippingFieldsHeader->SetID("ShippingFieldsHeader");
         $shippingFields->addExtraClass("orderAddressHolder");
         $fields->push($shippingFieldsHeader);
         $shippingFields->SetID('ShippingFields');
         $fields->push($shippingFields);
     }
     $this->extend('augmentEcommerceShippingAddressFields', $fields);
     return $fields;
 }
 /**
  * Return the name of the session variable that should be used.
  * @return String
  */
 protected function sessionVariableName($name = "")
 {
     if (!in_array($name, self::$session_variable_names)) {
         user_error("Tried to set session variable {$name}, that is not in use", E_USER_NOTICE);
     }
     $sessionCode = EcommerceConfig::get("ShoppingCart", "session_code");
     return $sessionCode . "_" . $name;
 }
 /**
  * returns the default format for a site for currency
  *
  * @param Boolean $html
  *
  * @return String
  */
 function NiceDefaultFormat($html = true)
 {
     $function = EcommerceConfig::get('EcommerceMoney', 'default_format');
     return $this->owner->{$function}($html);
 }
 /**
  *@return Array - just so the template is still displayed
  **/
 function sendreceipt($request)
 {
     if ($o = $this->currentOrder) {
         if ($m = $o->Member()) {
             if ($m->Email) {
                 $subject = _t("Account.COPYONLY", "--- COPY ONLY ---");
                 $message = _t("Account.COPYONLY", "--- COPY ONLY ---");
                 $o->sendReceipt($subject, $message, true);
                 $this->message = _t('OrderConfirmationPage.RECEIPTSENT', 'An order receipt has been sent to: ') . $m->Email . '.';
             } else {
                 $this->message = _t('OrderConfirmationPage.RECEIPTNOTSENTNOTSENDING', 'Email could NOT be sent.');
             }
         } else {
             $this->message = _t('OrderConfirmationPage.RECEIPTNOTSENTNOEMAIL', 'No email could be found for sending this receipt.');
         }
     } else {
         $this->message = _t('OrderConfirmationPage.RECEIPTNOTSENTNOORDER', 'Order could not be found.');
     }
     $baseFolder = Director::baseFolder();
     require_once $baseFolder . '/ecommerce/thirdparty/Emogrifier.php';
     Requirements::clear();
     Requirements::themedCSS("typography");
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     Requirements::themedCSS("OrderReport");
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     Requirements::themedCSS("Order_Invoice", "print");
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     $html = $this->renderWith("Order_ReceiptEmail");
     // if it's an html email, filter it through emogrifier
     $cssFileLocation = $baseFolder . "/" . EcommerceConfig::get("Order_Email", "css_file_location");
     $html .= "\r\n\r\n<!-- CSS can be found here: {$cssFileLocation} -->";
     $cssFileHandler = fopen($cssFileLocation, 'r');
     $css = fread($cssFileHandler, filesize($cssFileLocation));
     fclose($cssFileHandler);
     $emog = new Emogrifier($html, $css);
     $html = $emog->emogrify();
     return $html;
 }
 /**
  * Get the value for a static variable.
  * @param $className The data class, as specified in your fixture file.  Parent classes won't work
  * @param $identifier The identifier string, as provided in your fixture file
  * @param $subIdentifier A secondary identifier string, as provided in your fixture file
  * @return Mixed
  * @TODO: implement subIdentfier
  */
 public function getStaticValue($className, $identifier, $subIdentifier = null)
 {
     //this only runs once
     if (!count($this->fixtureDictionary)) {
         $this->loadData();
     }
     if ($subIdentifier) {
         if (isset($this->fixtureDictionary[$className][$identifier][$subIdentifier])) {
             return $this->fixtureDictionary[$className][$identifier][$subIdentifier];
         }
     } elseif (isset($this->fixtureDictionary[$className][$identifier])) {
         return $this->fixtureDictionary[$className][$identifier];
     }
     if (Director::isDev()) {
         echo "Please add the following line to one of these files : <br />\n\t\t\t" . implode(", ", self::$folder_and_file_locations) . "<br />\n\t\t\t<pre>\n{$className}:\n\t {$identifier}: [check default configuration (ecommerce/_config/ecommerce.yaml) for example value]\n\t\t\t</pre><br />\n\t\t\tPlease also make sure to visit <a href=\"/dev/ecommerce/\">/dev/ecommerce/</a> to check all your configurations and run any migration scripts!";
         user_error("Could not find definition for: {$className}.{$identifier}.{$subIdentifier} in " . implode(", ", self::$folder_and_file_locations), E_USER_NOTICE);
     }
     //when in live mode, try to keep the boat floating.
     if (Director::isLive()) {
         $realFiles = self::$folder_and_file_locations;
         $backupFiles = "ecommerce/_config/ecommerce.yaml";
         if ($realFiles != $backupFiles) {
             self::$folder_and_file_locations = $backupFiles;
             $outcome = self::getStaticValue($className, $identifier, $subIdentifier);
             self::$folder_and_file_locations = $realFiles;
             return $outcome;
         }
     }
     return null;
 }
 /**
  * stardard SS method
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $arrayOfModifiers = EcommerceConfig::get("Order", "modifiers");
     if (!is_array($arrayOfModifiers)) {
         $arrayOfModifiers = array();
     }
     if (count($arrayOfModifiers)) {
         foreach ($arrayOfModifiers as $className) {
             $obj = DataObject::get_one("OrderModifier_Descriptor", "\"ModifierClassName\" = '" . $className . "'");
             if (!$obj) {
                 $modifier = singleton($className);
                 $obj = new OrderModifier_Descriptor();
                 $obj->ModifierClassName = $className;
                 $obj->Heading = $modifier->i18n_singular_name();
                 $obj->write();
                 DB::alteration_message("Creating description for " . $className, "created");
             }
         }
     }
     $orderModifierDescriptors = DataObject::get("OrderModifier_Descriptor");
     if ($orderModifierDescriptors) {
         foreach ($orderModifierDescriptors as $orderModifierDescriptor) {
             if (!in_array($orderModifierDescriptor->ModifierClassName, $arrayOfModifiers)) {
                 $orderModifierDescriptor->delete();
                 DB::alteration_message("Deleting description for " . $orderModifierDescriptor->ModifierClassName, "created");
             }
         }
     }
 }
 /**
  * Standard SS Method
  * @return Array
  */
 function getManagedModels()
 {
     return EcommerceConfig::get("StoreAdmin", "managed_models");
 }