private function runecommercedefaults()
 {
     $request = true;
     $buildTask = new EcommerceTaskCreateMemberGroups($request);
     $buildTask->run($request);
     $obj = new EcommerceDBConfig();
     $obj->Title = "Test Configuration";
     $obj->UseThisOne = 1;
     $obj->write();
 }
 /**
  * request approval: sends email to shop admin to request approval.
  */
 function requestapproval($data, $form, $request)
 {
     if ($this->member) {
         $email = new Email();
         $email->setTo(Order_Email::get_from_email());
         $email->setSubject(_t("EcommerceCorporateAccount.REQUESTINGACCOUNTAPPROVE", "A request for an account approval from ") . $this->member->Email);
         $email->setTemplate('EcommerceCorporateGroupApprovalRequest');
         $config = SiteConfig::current_site_config();
         $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
         $email->populateTemplate(array('SiteConfig' => $config, 'EcommerceConfig' => $ecommerceConfig, 'Member' => $this->member));
         $email->send();
         $form->sessionMessage(_t('EcommerceCorporateAccount.REQUESTHASBEENSENT', 'The request has been sent.'), 'good');
         Director::redirectBack();
     } else {
         $form->sessionMessage(_t('EcommerceCorporateAccount.REQUESTCOULDNOTBESEND', 'The request could not be sent.'), 'bad');
         Director::redirectBack();
     }
 }
 /**
  *
  * @return EcommerceCustomDeliveryPostalCode | null
  */
 private function MyPostalCodeObject()
 {
     $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
     $postalCode = intval($this->LivePostalCode());
     if ($postalCode) {
         return $ecommerceConfig->SpecialPricePostalCodes()->where("{$postalCode} >= \"PostalCodeLowestNumber\" AND {$postalCode} <= \"PostalCodeHighestNumber\" ")->First();
     }
     return null;
 }
 function doProductSearchForm($data, $form)
 {
     if (!$this->maximumNumberOfResults) {
         $this->maximumNumberOfResults = EcommerceConfig::get("ProductGroup", "maximum_number_of_products_to_list");
     }
     if (isset($data["DebugSearch"])) {
         $this->debug = $data["DebugSearch"] ? true : false;
     }
     if ($this->debug) {
         $this->debugOutput("<hr /><hr /><hr /><h2>Debugging Search Results</h2>");
     }
     //what is the baseclass?
     $baseClassName = $this->baseClassForBuyables;
     if (!$baseClassName) {
         $baseClassName = EcommerceConfig::get("ProductGroup", "base_buyable_class");
     }
     if (!$baseClassName) {
         user_error("Can not find {$baseClassName} (baseClassName)");
     }
     //basic get
     $searchableFields = $baseClassName::create()->stat('searchable_fields');
     $baseList = $baseClassName::get()->filter(array("ShowInSearch" => 1));
     $ecomConfig = EcommerceDBConfig::current_ecommerce_db_config();
     if ($ecomConfig->OnlyShowProductsThatCanBePurchased) {
         $baseList->filter(array("AllowPurchase" => 1));
     }
     $limitToCurrentSection = false;
     if (isset($data["SearchOnlyFieldsInThisSection"]) && $data["SearchOnlyFieldsInThisSection"]) {
         $limitToCurrentSection = true;
         if ($this->productsToSearch instanceof DataList) {
             $this->productsToSearch = $this->productsToSearch->map("ID", "ID")->toArray();
         }
         $baseList = $baseList->filter(array("ID" => $this->productsToSearch));
     }
     if (isset($data["MinimumPrice"]) && $data["MinimumPrice"]) {
         $baseList = $baseList->filter(array("Price:GreaterThanOrEqual" => floatval($data["MinimumPrice"])));
     }
     if (isset($data["MaximumPrice"]) && $data["MaximumPrice"]) {
         $baseList = $baseList->filter(array("Price:LessThanOrEqual" => floatval($data["MaximumPrice"])));
     }
     //defining some variables
     $isKeywordSearch = false;
     if ($this->debug) {
         $this->debugOutput("<hr /><h3>BASE LIST</h3><pre>" . str_replace($this->sqlWords, array_flip($this->sqlWords), $baseList->sql()) . "</pre>");
     }
     //KEYWORD SEARCH - only bother if we have any keywords and results at all ...
     if (isset($data["ShortKeyword"]) && !isset($data["Keyword"])) {
         $data["Keyword"] = $data["ShortKeyword"];
     }
     if (isset($data["Keyword"]) && ($keywordPhrase = $data["Keyword"])) {
         if ($baseList->count()) {
             if (strlen($keywordPhrase) > 1) {
                 $isKeywordSearch = true;
                 $this->resultArrayPos = 0;
                 $this->resultArray = array();
                 $keywordPhrase = Convert::raw2sql($keywordPhrase);
                 $keywordPhrase = strtolower($keywordPhrase);
                 SearchHistory::add_entry($keywordPhrase);
                 // 1) Exact search by code
                 $count = 0;
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h2>SEARCH BY CODE</h2>");
                 }
                 if ($code = intval($keywordPhrase)) {
                     $list1 = $baseList->filter(array("InternalItemID" => $code));
                     $count = $list1->count();
                     if ($count == 1) {
                         if (!$this->debug) {
                             return $this->controller->redirect($list1->First()->Link());
                         }
                     } elseif ($count > 1) {
                         if ($this->addToResults($list1)) {
                             break;
                         }
                     }
                 }
                 if ($this->debug) {
                     $this->debugOutput("<h3>SEARCH BY CODE RESULT: {$count}</h3>");
                 }
                 // 2) Search of the entire keyword phrase and its replacements
                 $count = 0;
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h3>FULL KEYWORD SEARCH</h3>");
                 }
                 if ($this->resultArrayPos <= $this->maximumNumberOfResults) {
                     //now we are going to look for synonyms
                     $words = explode(' ', trim(preg_replace('!\\s+!', ' ', $keywordPhrase)));
                     foreach ($words as $wordKey => $word) {
                         if ($this->debug) {
                             $this->debugOutput("checking for aliases of {$word}");
                         }
                         $replacements = SearchReplacement::get()->where("\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") = '{$word}' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '%,{$word}' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '{$word},%' OR\n\t\t\t\t\t\t\t\t\tLOWER(\"Search\") LIKE '%,{$word},%'");
                         if ($replacements->count()) {
                             $replacementsArray = $replacements->map('ID', 'Replace')->toArray();
                             if ($this->debug) {
                                 $this->debugOutput("found alias for {$word}");
                             }
                             foreach ($replacementsArray as $replacementWord) {
                                 $keywordPhrase = str_replace($word, $replacementWord, $keywordPhrase);
                             }
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<pre>WORD ARRAY: " . print_r($keywordPhrase, 1) . "</pre>");
                     }
                     //work out searches
                     $singleton = $baseClassName::create();
                     foreach ($this->extraBuyableFieldsToSearchFullText as $tempClassName => $fieldArrayTemp) {
                         if ($singleton instanceof $tempClassName) {
                             $fieldArray = $fieldArrayTemp;
                             break;
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<pre>FIELD ARRAY: " . print_r($fieldArray, 1) . "</pre>");
                     }
                     $searches = $this->getSearchArrays($keywordPhrase, $fieldArray);
                     //if($this->debug) { $this->debugOutput("<pre>SEARCH ARRAY: ".print_r($searches, 1)."</pre>");}
                     //we search exact matches first then other matches ...
                     foreach ($searches as $search) {
                         $list2 = $baseList->where($search);
                         $count = $list2->count();
                         if ($this->debug) {
                             $this->debugOutput("<p>{$search}: {$count}</p>");
                         }
                         if ($count == 1) {
                             if (!$this->debug) {
                                 return $this->controller->redirect($list2->First()->Link());
                             }
                         } elseif ($count > 1) {
                             if ($this->addToResults($list2)) {
                                 break;
                             }
                         }
                         if ($this->resultArrayPos > $this->maximumNumberOfResults) {
                             break;
                         }
                     }
                 }
                 if ($this->debug) {
                     $this->debugOutput("<h3>FULL KEYWORD SEARCH: {$count}</h3>");
                 }
                 if ($this->debug) {
                     $this->debugOutput("<hr /><h3>PRODUCT GROUP SEARCH</h3>");
                 }
                 // 3) Do the same search for Product Group names
                 $count = 0;
                 if ($limitToCurrentSection) {
                     //cant search other sections in this case...
                 } else {
                     $searches = $this->getSearchArrays($keywordPhrase);
                     if ($this->debug) {
                         $this->debugOutput("<pre>SEARCH ARRAY: " . print_r($searches, 1) . "</pre>");
                     }
                     foreach ($searches as $search) {
                         $productGroups = ProductGroup::get()->where($search)->filter(array("ShowInSearch" => 1));
                         $count = $productGroups->count();
                         //redirect if we find exactly one match and we have no matches so far...
                         if ($count == 1 && !$this->resultArrayPos) {
                             if (!$this->debug) {
                                 return $this->controller->redirect($productGroups->First()->Link());
                             }
                         } elseif ($count) {
                             foreach ($productGroups as $productGroup) {
                                 //we add them like this because we like to keep them in order!
                                 if (!in_array($productGroup->ID, $this->productGroupIDs)) {
                                     $this->productGroupIDs[] = $productGroup->ID;
                                 }
                             }
                         }
                     }
                     if ($this->debug) {
                         $this->debugOutput("<h3>PRODUCT GROUP SEARCH: {$count}</h3>");
                     }
                 }
             }
         }
     }
     if (!$isKeywordSearch) {
         $this->addToResults($baseList);
     }
     $redirectToPage = null;
     //if no specific section is being searched then we redirect to search page:
     if (!$limitToCurrentSection) {
         $redirectToPage = ProductGroupSearchPage::get()->first();
     }
     if (!$redirectToPage) {
         // for section specific search,
         // redirect to the specific section (basically where we came from)
         $redirectToPage = $this->controller->dataRecord;
     }
     if ($this->debug) {
         $this->debugOutput("<hr />" . "<h3>Previous Search Products: " . $redirectToPage->SearchResultsSessionVariable(false) . "</h3><p>" . print_r(Session::get($redirectToPage->SearchResultsSessionVariable(false)), 1) . "</p>" . "<h3>Previous Search Groups: " . $redirectToPage->SearchResultsSessionVariable(true) . "</h3><p>" . print_r(Session::get($redirectToPage->SearchResultsSessionVariable(true)), 1) . "</p>");
     }
     Session::set($redirectToPage->SearchResultsSessionVariable(false), implode(",", $this->resultArray));
     Session::set($redirectToPage->SearchResultsSessionVariable(true), implode(",", $this->productGroupIDs));
     Session::save();
     if ($this->debug) {
         $this->debugOutput("<hr />" . "<h3>SAVING Products to session: " . $redirectToPage->SearchResultsSessionVariable(false) . "</h3><p>" . print_r(explode(",", Session::get($redirectToPage->SearchResultsSessionVariable(false))), 1) . "</p>" . "<h3>SAVING Groups to session: " . $redirectToPage->SearchResultsSessionVariable(true) . "</h3><p>" . print_r(explode(",", Session::get($redirectToPage->SearchResultsSessionVariable(true))), 1) . "</p>");
     }
     $link = $redirectToPage->Link($this->controllerSearchResultDisplayMethod);
     if ($this->additionalGetParameters) {
         $link .= "?" . $this->additionalGetParameters;
     }
     if ($this->debug) {
         die($link);
     }
     $this->controller->redirect($link);
 }
 /**
  * returns the standard EcommerceDBConfig for use within OrderSteps.
  * @return EcommerceDBConfig
  */
 protected function EcomConfig()
 {
     return EcommerceDBConfig::current_ecommerce_db_config();
 }
 /**
  * Adding EcommerceDBConfig values
  */
 protected function addEcommerceDBConfigToConfigs()
 {
     $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
     $fields = $ecommerceConfig->fieldLabels();
     if ($fields) {
         foreach ($fields as $field => $description) {
             if ($field != "Title") {
                 $defaultsDefaults = $ecommerceConfig->stat("defaults");
                 $this->definitions["EcommerceDBConfig"][$field] = "{$description}. <br />THIS IS SET IN THE <a href=\"/admin/shop\">Ecommerce Configuration</a>";
                 $this->configs["EcommerceDBConfig"][$field] = $ecommerceConfig->{$field};
                 $this->defaults["EcommerceDBConfig"][$field] = isset($defaultsDefaults[$field]) ? $defaultsDefaults[$field] : "no default set";
                 $imageField = $field . "ID";
                 if (isset($ecommerceConfig->{$imageField})) {
                     if ($image = $ecommerceConfig->{$field}()) {
                         if ($image->exists() && $image instanceof Image) {
                             $this->configs["EcommerceDBConfig"][$field] = "[Image]  --- <img src=\"" . $image->Link() . "\" />";
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * returns ID of Mailing List that people are subscribing to.
  * @return CampaignMonitorPage
  */
 protected function campaignMonitorPage()
 {
     $config = EcommerceDBConfig::current_ecommerce_db_config();
     return $config->CampaignMonitorSignupPage();
 }
 function orderSteps()
 {
     $steps = OrderStep::get();
     if ($steps->count()) {
         foreach ($steps as $step) {
             $fields = Config::inst()->get($step->ClassName, "db");
             $defaultsArray = $step->stat("defaults", true);
             $configArray = array();
             foreach ($fields as $fieldKey => $fieldType) {
                 if ($fields) {
                     $configArray[$fieldKey] = $step->{$fieldKey};
                     if (!isset($defaultsArray[$fieldKey])) {
                         $defaultsArray[$fieldKey] = "[default not set]";
                     }
                 }
             }
             $ecommerceDBConfig = EcommerceDBConfig::current_ecommerce_db_config();
             $this->definitions["OrderStep"][$step->Code] = $step->Description . "<br />see: <a href=\"/admin/shop/OrderStep/EditForm/field/OrderStep/item/" . $step->ID . "/edit\">Ecommerce Configuration</a>.";
             $this->configs["OrderStep"][$step->Code] = $configArray;
             $this->defaults["OrderStep"][$step->Code] = $defaultsArray;
             $this->databaseValues["OrderStep"][$step->Code] = true;
         }
     }
 }
 /**
  * standard SS Method
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!self::current_ecommerce_db_config()) {
         $obj = EcommerceDBConfig::create();
         $obj->write();
     }
     DB::alteration_message("\n\t\t\t<hr /><hr /><hr /><hr /><hr />\n\t\t\t<h1 style=\"color: darkRed\">Please make sure to review your <a href=\"/dev/ecommerce/\">e-commerce settings</a>.</h1>\n\t\t\t<hr /><hr /><hr /><hr /><hr />", "edited");
 }
 function quickaddtocartform_add($data, $form)
 {
     $shoppingCart = ShoppingCart::singleton();
     $buyableID = intval($data["BuyableID"]);
     $buyableClassName = Convert::raw2sql($data["BuyableClassName"]);
     $version = Intval($data["Version"]);
     $quantity = floatval($data["Quantity"]);
     $status = "bad";
     $message = _t("AddToCartPage.ERRORPRODUCTNOTADDED", "ERROR: Product Not Added - make sure to find a product first.");
     if (class_exists($buyableClassName) && EcommerceDBConfig::is_buyable($buyableClassName)) {
         $buyable = $buyableClassName::get()->byID($buyableID);
         if ($buyable) {
             $shoppingCart->addBuyable($buyable, $quantity);
             $status = "good";
             $message = _t("AddToCartPage.ADDED", "Added");
         }
     }
     if (Director::is_ajax()) {
         return $shoppingCart->setMessageAndReturn($message, $status, $form);
     } else {
         $form->setMessage($message, $status);
         $this->redirectBack();
     }
 }
 /**
  * standard SS Method
  * Sends an email to the member letting her / him know that the account has been approved.
  */
 function onAfterWrite()
 {
     if ($this->owner->isApprovedCorporateCustomer()) {
         if (!$this->owner->ApprovalEmailSent) {
             $config = SiteConfig::current_site_config();
             $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
             $email = new Email();
             $email->setTo($this->owner->Email);
             $email->setSubject(_t("EcommerceCorporateAccount.ACCOUNTAPPROVEDFOR", "Account approved for ") . $config->Title);
             $email->setBcc(Order_Email::get_from_email());
             $email->setTemplate('EcommerceCorporateGroupApprovalEmail');
             $email->populateTemplate(array('SiteConfig' => $config, 'EcommerceConfig' => $ecommerceConfig, 'Member' => $this->owner));
             $email->send();
             $this->owner->ApprovalEmailSent = 1;
             $this->owner->write();
         }
     }
 }
 /**
  * standard SS method
  */
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $countryField = $this->createGridField("EcommerceCountry", "AvailableInCountries", "Countries");
     if ($countryField) {
         $fields->replaceField("AvailableInCountries", $countryField);
     }
     $regionField = $this->createGridField("EcommerceRegion", "AvailableInRegions", "Regions");
     if ($regionField) {
         $fields->replaceField("AvailableInRegions", $regionField);
     }
     if (class_exists("DataObjectSorterController") && $this->hasExtension("DataObjectSorterController")) {
         $fields->addFieldToTab("Root.Sort", new LiteralField("InvitationToSort", $this->dataObjectSorterPopupLink()));
     }
     $fields->replaceField("ExplanationPageID", new OptionalTreeDropdownField($name = "ExplanationPageID", $title = "Page", "SiteTree"));
     //add headings
     $fields->addFieldToTab("Root.Main", new HeaderField("Charges", _t("PickUpOrDeliveryModifierOptions.CHARGES", "Charges (enter zero (0) to ignore)")), "Percentage");
     $fields->addFieldToTab("Root.Main", new HeaderField("MinimumAndMaximum", _t("PickUpOrDeliveryModifierOptions.MIN_AND_MAX", "Minimum and Maximum (enter zero (0) to ignore)")), "MinimumDeliveryCharge");
     $fields->addFieldToTab("Root.Main", new HeaderField("ExplanationHeader", _t("PickUpOrDeliveryModifierOptions.EXPLANATION_HEADER", "More information about delivery option")), "ExplanationPageID");
     if (EcommerceDBConfig::current_ecommerce_db_config()->ProductsHaveWeight) {
         $weightBrackets = $this->WeightBrackets();
         if ($weightBrackets && $weightBrackets->count()) {
             $fields->removeByName("WeightMultiplier");
             $fields->removeByName("WeightUnit");
         } else {
             $fields->addFieldToTab("Root.Main", new HeaderField("WeightOptions", "Weight Options (also see Weight Brackets tab)"), "WeightMultiplier");
         }
     } else {
         $fields->removeByName("WeightBrackets");
         $fields->removeByName("WeightMultiplier");
         $fields->removeByName("WeightUnit");
     }
     $fields->addFieldToTab("Root.Main", new HeaderField("MoreInformation", "Other Settings"), "Sort");
     foreach ($this->Config()->get("field_labels_right") as $fieldName => $fieldDescription) {
         $field = $fields->dataFieldByName($fieldName);
         if ($field) {
             $field->setRightTitle($fieldDescription);
         }
     }
     return $fields;
 }
 protected function moveSiteConfigToEcommerceDBConfig_140()
 {
     $explanation = "\r\n\t\t\t<h1>140. Move Site Config fields to Ecommerce DB Config</h1>\r\n\t\t\t<p>Moving the general config fields from the SiteConfig to the EcommerceDBConfig.</p>\r\n\t\t";
     if ($this->retrieveInfoOnly) {
         return $explanation;
     } else {
         echo $explanation;
     }
     $fields = array("ShopClosed", "ShopPricesAreTaxExclusive", "ShopPhysicalAddress", "ReceiptEmail", "PostalCodeURL", "PostalCodeLabel", "NumberOfProductsPerPage", "OnlyShowProductsThatCanBePurchased", "ProductsHaveWeight", "ProductsHaveModelNames", "ProductsHaveQuantifiers", "ProductsAlsoInOtherGroups", "EmailLogoID", "DefaultProductImageID");
     $ecomConfig = EcommerceDBConfig::get()->First();
     if (!$ecomConfig) {
         $ecomConfig = EcommerceDBConfig::create();
         $ecomConfig->write();
     }
     $sc = SiteConfig::current_site_config();
     if ($ecomConfig && $sc) {
         foreach ($fields as $field) {
             if ($this->hasTableAndField("SiteConfig", $field)) {
                 if (!$this->hasTableAndField("EcommerceDBConfig", $field)) {
                     $this->DBAlterationMessageNow("Could not find EcommerceDBConfig.{$field} - this is unexpected!", "deleted");
                 } else {
                     $this->DBAlterationMessageNow("Migrated SiteConfig.{$field}", "created");
                     $ecomConfig->{$field} = DB::query("SELECT \"{$field}\" FROM \"SiteConfig\" WHERE \"ID\" = " . $sc->ID)->value();
                     $ecomConfig->write();
                     $this->makeFieldObsolete("SiteConfig", $field);
                 }
             } else {
                 $this->DBAlterationMessageNow("SiteConfig.{$field} has been moved");
             }
         }
     } else {
         $this->DBAlterationMessageNow("ERROR: SiteConfig or EcommerceDBConfig are not available", "deleted");
     }
     return 0;
 }
 /**
  * Gets a buyable object based on URL actions
  *@return DataObject | Null - returns buyable
  */
 protected function buyable()
 {
     $buyableClassName = Convert::raw2sql($this->getRequest()->param('OtherID'));
     $buyableID = intval($this->getRequest()->param('ID'));
     if ($buyableClassName && $buyableID) {
         if (EcommerceDBConfig::is_buyable($buyableClassName)) {
             $obj = DataObject::get_by_id($buyableClassName, intval($buyableID));
             if ($obj) {
                 if ($obj->ClassName == $buyableClassName) {
                     return $obj;
                 }
             }
         } else {
             if (strpos($buyableClassName, "OrderItem")) {
                 user_error("ClassName in URL should be buyable and not an orderitem", E_USER_NOTICE);
             }
         }
     }
     return null;
 }
 function run($request)
 {
     $update = array();
     // ACCOUNT PAGE
     $accountPage = DataObject::get_one('AccountPage');
     if (!$accountPage) {
         $accountPage = new AccountPage();
         $accountPage->Title = 'Account';
         $accountPage->MenuTitle = 'Account';
         $accountPage->MetaTitle = 'Account';
         $accountPage->Content = '<p>This is the account page. It is used for shop users to login and change their member details if they have an account.</p>';
         $accountPage->URLSegment = 'account';
         $accountPage->ShowInMenus = 0;
         $accountPage->writeToStage('Stage');
         $accountPage->publish('Stage', 'Live');
         DB::alteration_message('Account page \'Account\' created', 'created');
     } else {
         DB::alteration_message('No need to create an account page, it already exists.');
     }
     //CHECKOUT PAGE
     //CHECKOUT PAGE
     $checkoutPage = DataObject::get_one('CheckoutPage');
     if (!$checkoutPage) {
         $checkoutPage = new CheckoutPage();
         $checkoutPage->Content = '<p>This is the checkout page. You can edit all the messages in the Content Management System.</p>';
         $checkoutPage->Title = 'Checkout';
         $checkoutPage->TermsAndConditionsMessage = 'You must agree with the terms and conditions to proceed. ';
         $checkoutPage->MetaTitle = 'Checkout';
         $checkoutPage->MenuTitle = 'Checkout';
         $checkoutPage->URLSegment = 'checkout';
         $update[] = 'Checkout page \'Checkout\' created';
         $checkoutPage->ShowInMenus = 0;
         DB::alteration_message('new checkout page created.', 'created');
     } else {
         DB::alteration_message('No need to create an checkout page, it already exists.');
     }
     if ($checkoutPage) {
         if ($checkoutPage->TermsPageID == 0 && ($termsPage = DataObject::get_one('Page', "\"URLSegment\" = 'terms-and-conditions'"))) {
             $checkoutPage->TermsPageID = $termsPage->ID;
             DB::alteration_message('terms and conditions page linked.', "created");
         } else {
             DB::alteration_message('No terms and conditions page linked.');
         }
         $checkoutPage->writeToStage('Stage');
         $checkoutPage->publish('Stage', 'Live');
         DB::alteration_message('Checkout page saved');
         if (!DataObject::get_one('OrderConfirmationPage')) {
             $orderConfirmationPage = new OrderConfirmationPage();
             $orderConfirmationPage->ParentID = $checkoutPage->ID;
             $orderConfirmationPage->Title = 'Order confirmation';
             $orderConfirmationPage->MenuTitle = 'Order confirmation';
             $orderConfirmationPage->MetaTitle = 'Order confirmation';
             $orderConfirmationPage->Content = '<p>This is the order confirmation page. It is used to confirm orders after they have been placed in the checkout page.</p>';
             $orderConfirmationPage->URLSegment = 'order-confirmation';
             $orderConfirmationPage->ShowInMenus = 0;
             $orderConfirmationPage->writeToStage('Stage');
             $orderConfirmationPage->publish('Stage', 'Live');
             DB::alteration_message('Order Confirmation created', 'created');
         } else {
             DB::alteration_message('No need to create an Order Confirmation Page. It already exists.');
         }
     }
     $update = array();
     $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config();
     if ($ecommerceConfig) {
         if (!$ecommerceConfig->ReceiptEmail) {
             $ecommerceConfig->ReceiptEmail = Email::getAdminEmail();
             if (!$ecommerceConfig->ReceiptEmail) {
                 user_error("you must set an AdminEmail (Email::setAdminEmail)", E_USER_NOTICE);
             }
             $update[] = "created default entry for ReceiptEmail";
         }
         if (!$ecommerceConfig->NumberOfProductsPerPage) {
             $ecommerceConfig->NumberOfProductsPerPage = 12;
             $update[] = "created default entry for NumberOfProductsPerPage";
         }
         if (count($update)) {
             $ecommerceConfig->write();
             DB::alteration_message($ecommerceConfig->ClassName . " created/updated: " . implode(" --- ", $update), 'created');
         }
     }
 }
 /**
  * returns the instance of EcommerceDBConfig
  *
  * @return EcommerceDBConfig
  **/
 public function EcomConfig()
 {
     return EcommerceDBConfig::current_ecommerce_db_config();
 }
 /**
  * works out if Weight is applicable at all
  * @return Boolean
  */
 protected function useWeight()
 {
     return EcommerceDBConfig::current_ecommerce_db_config()->ProductsHaveWeight;
 }