/**
  * Returns the form fields.
  * 
  * @param bool $withUpdate Call extensions to update fields?
  * 
  * @return array
  */
 public function getFormFields($withUpdate = true)
 {
     if (!array_key_exists('Salutation', $this->formFields)) {
         $birthdayFields = array();
         $businessFields = array();
         if ($this->demandBirthdayDate()) {
             $birthdayDays = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'));
             $birthdayMonths = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), '1' => _t('SilvercartPage.JANUARY'), '2' => _t('SilvercartPage.FEBRUARY'), '3' => _t('SilvercartPage.MARCH'), '4' => _t('SilvercartPage.APRIL'), '5' => _t('SilvercartPage.MAY'), '6' => _t('SilvercartPage.JUNE'), '7' => _t('SilvercartPage.JULY'), '8' => _t('SilvercartPage.AUGUST'), '9' => _t('SilvercartPage.SEPTEMBER'), '10' => _t('SilvercartPage.OCTOBER'), '11' => _t('SilvercartPage.NOVEMBER'), '12' => _t('SilvercartPage.DECEMBER'));
             for ($idx = 1; $idx < 32; $idx++) {
                 $birthdayDays[$idx] = $idx;
             }
             $birthdayFields = array('BirthdayDay' => array('type' => 'DropdownField', 'title' => _t('SilvercartPage.DAY'), 'value' => $birthdayDays, 'checkRequirements' => array('isFilledIn' => true)), 'BirthdayMonth' => array('type' => 'DropdownField', 'title' => _t('SilvercartPage.MONTH'), 'value' => $birthdayMonths, 'checkRequirements' => array('isFilledIn' => true)), 'BirthdayYear' => array('type' => 'TextField', 'title' => _t('SilvercartPage.YEAR'), 'maxLength' => 4, 'checkRequirements' => array('isFilledIn' => true, 'isNumbersOnly' => true, 'hasLength' => 4)));
         }
         if ($this->EnableBusinessCustomers()) {
             $businessFields = array('IsBusinessAccount' => array('type' => 'CheckboxField', 'title' => _t('SilvercartCustomer.ISBUSINESSACCOUNT')), 'TaxIdNumber' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.TAXIDNUMBER'), 'maxLength' => 30, 'checkRequirements' => array('isFilledInDependantOn' => array('field' => 'IsBusinessAccount', 'hasValue' => '1'))), 'Company' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.COMPANY'), 'maxLength' => 50, 'checkRequirements' => array('isFilledInDependantOn' => array('field' => 'IsBusinessAccount', 'hasValue' => '1'))));
         }
         $backlink = '';
         if (isset($_GET['backlink'])) {
             $backlink = Convert::raw2sql($_GET['backlink']);
         }
         $formFields = array('Salutation' => array('type' => 'DropdownField', 'title' => _t('SilvercartAddress.SALUTATION'), 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), 'Frau' => _t('SilvercartAddress.MISSES'), 'Herr' => _t('SilvercartAddress.MISTER')), 'checkRequirements' => array('isFilledIn' => true)), 'AcademicTitle' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.AcademicTitle', 'Academic title')), 'FirstName' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.FIRSTNAME', 'firstname'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Surname' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.SURNAME', 'surname'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Addition' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.ADDITION', 'Addition')), 'Street' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.STREET', 'street'), 'checkRequirements' => array('isFilledIn' => true)), 'StreetNumber' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.STREETNUMBER', 'streetnumber'), 'maxLength' => 10, 'checkRequirements' => array('isFilledIn' => true)), 'Postcode' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.POSTCODE', 'postcode'), 'maxLength' => 10, 'checkRequirements' => array('isFilledIn' => true)), 'City' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.CITY', 'city'), 'checkRequirements' => array('isFilledIn' => true)), 'Country' => array('type' => 'DropdownField', 'title' => _t('SilvercartCountry.SINGULARNAME'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartCheckoutFormStep2.EMPTYSTRING_COUNTRY')), 'checkRequirements' => array('isFilledIn' => true)), 'Email' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.EMAIL', 'email address'), 'checkRequirements' => array('isEmailAddress' => true, 'isFilledIn' => true, 'callBack' => 'doesEmailExistAlready')), 'EmailCheck' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.EMAIL_CHECK', 'email address check'), 'checkRequirements' => array('isFilledIn' => true, 'mustEqual' => 'Email')), 'PhoneAreaCode' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.PHONEAREACODE', 'phone area code'), 'checkRequirements' => array('isFilledIn' => true, 'isNumbersOnly' => true)), 'Phone' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.PHONE', 'phone'), 'checkRequirements' => array('isFilledIn' => true, 'isNumbersOnly' => true)), 'Fax' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.FAX')), 'Password' => array('type' => 'PasswordField', 'title' => _t('SilvercartPage.PASSWORD'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 6, 'mustNotEqual' => 'Email')), 'PasswordCheck' => array('type' => 'PasswordField', 'title' => _t('SilvercartPage.PASSWORD_CHECK'), 'checkRequirements' => array('isFilledIn' => true, 'mustEqual' => 'Password')), 'SubscribedToNewsletter' => array('type' => 'CheckboxField', 'title' => _t('SilvercartCheckoutFormStep.I_SUBSCRIBE_NEWSLETTER')), 'backlink' => array('type' => 'HiddenField', 'value' => $backlink));
         $this->formFields = array_merge($this->formFields, $formFields, $businessFields, $birthdayFields);
     }
     return parent::getFormFields($withUpdate);
 }
 /**
  * Returns the form fields
  * 
  * @param bool $withUpdate Execute update method of decorators?
  * 
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 09.10.2012
  */
 public function getFormFields($withUpdate = true)
 {
     if (empty($this->formFields)) {
         $address = singleton('SilvercartAddress');
         $this->formFields = array('Salutation' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('Salutation'), 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER')), 'checkRequirements' => array('isFilledIn' => true)), 'AcademicTitle' => array('type' => 'TextField', 'title' => $address->fieldLabel('AcademicTitle')), 'FirstName' => array('type' => 'TextField', 'title' => $address->fieldLabel('FirstName'), 'checkRequirements' => array('isFilledIn' => true)), 'Surname' => array('type' => 'TextField', 'title' => $address->fieldLabel('Surname'), 'checkRequirements' => array('isFilledIn' => true)), 'Addition' => array('type' => 'TextField', 'title' => $address->fieldLabel('Addition')), 'Street' => array('type' => 'TextField', 'title' => $address->fieldLabel('Street'), 'checkRequirements' => array('isFilledIn' => true)), 'StreetNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('StreetNumber'), 'checkRequirements' => array('isFilledIn' => true)), 'Postcode' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode'), 'checkRequirements' => array('isFilledIn' => true)), 'City' => array('type' => 'TextField', 'title' => $address->fieldLabel('City'), 'checkRequirements' => array('isFilledIn' => true)), 'PhoneAreaCode' => array('type' => 'TextField', 'title' => $address->fieldLabel('PhoneAreaCode'), 'checkRequirements' => array('isFilledIn' => true)), 'Phone' => array('type' => 'TextField', 'title' => $address->fieldLabel('Phone'), 'checkRequirements' => array('isFilledIn' => true)), 'Fax' => array('type' => 'TextField', 'title' => $address->fieldLabel('Fax')), 'Country' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('SilvercartCountry'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE')), 'checkRequirements' => array('isFilledIn' => true)));
         if ($this->EnableBusinessCustomers()) {
             $this->formFields = array_merge($this->formFields, array('IsBusinessAccount' => array('type' => 'CheckboxField', 'title' => $address->fieldLabel('IsBusinessAccount')), 'TaxIdNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('TaxIdNumber'), 'maxLength' => 30, 'checkRequirements' => array('isFilledInDependantOn' => array('field' => 'IsBusinessAccount', 'hasValue' => '1'))), 'Company' => array('type' => 'TextField', 'title' => $address->fieldLabel('Company'), 'maxLength' => 50, 'checkRequirements' => array('isFilledInDependantOn' => array('field' => 'IsBusinessAccount', 'hasValue' => '1')))));
         }
         if ($this->EnablePackstation()) {
             $this->formFields = array_merge($this->formFields, array('IsPackstation' => array('type' => 'OptionsetField', 'title' => $address->fieldLabel('AddressType'), 'selectedValue' => '0', 'value' => array('0' => $address->fieldLabel('UseAbsoluteAddress'), '1' => $address->fieldLabel('UsePackstation')), 'checkRequirements' => array('isFilledIn' => true)), 'PostNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('PostNumber'), 'checkRequirements' => array('isFilledIn' => true)), 'Packstation' => array('type' => 'TextField', 'title' => $address->fieldLabel('Packstation'), 'checkRequirements' => array('isFilledIn' => true))));
         } else {
             $this->formFields = array_merge($this->formFields, array('IsPackstation' => array('type' => 'HiddenField', 'title' => $address->fieldLabel('AddressType'), 'value' => '0')));
         }
     }
     return parent::getFormFields($withUpdate);
 }
 /**
  * Returns a dropdown map sorted by prioritive countries
  * 
  * @param bool   $onlyActive  Search only for active coutries?
  * @param string $emptyString String to show for empty value
  * 
  * @return array
  */
 public static function getPrioritiveDropdownMap($onlyActive = true, $emptyString = null)
 {
     $key = 0;
     if ($onlyActive) {
         $key = 1;
     }
     if (!is_null($emptyString)) {
         $key .= md5($emptyString);
     }
     if (!array_key_exists($key, self::$prioritiveDropdownMap)) {
         $dropdownMap = array();
         if (!is_null($emptyString)) {
             $dropdownMap[''] = $emptyString;
         }
         if (self::getPrioritiveCountryCount() > 0) {
             $prioritiveCountries = self::getPrioritiveCountries($onlyActive);
             foreach ($prioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (self::getNonPrioritiveCountryCount() > 0) {
             if (is_null($emptyString) && count($dropdownMap) > 0 || !is_null($emptyString) && count($dropdownMap) > 1) {
                 $dropdownMap[' '] = '------------------------';
             }
             $nonPrioritiveCountries = self::getNonPrioritiveCountries($onlyActive);
             foreach ($nonPrioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (empty($dropdownMap) && SilvercartTools::isBackendEnvironment()) {
             $allCountries = SilvercartCountry::get();
             $dropdownMap = $allCountries->map()->toArray();
         }
         self::$prioritiveDropdownMap[$key] = $dropdownMap;
     }
     return self::$prioritiveDropdownMap[$key];
 }
 /**
  * customize backend fields
  *
  * @return FieldList the form fields for the backend
  * 
  * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <sdiel@πixeltricks.de>
  * @since 28.01.2013
  */
 public function getCMSFields()
 {
     $this->markAsSeen();
     $fields = SilvercartDataObject::getCMSFields($this);
     //add the shipping/invloice address fields as own tab
     $address = singleton('SilvercartAddress');
     $fields->findOrMakeTab('Root.ShippingAddressTab', $this->fieldLabel('ShippingAddressTab'));
     $fields->findOrMakeTab('Root.InvoiceAddressTab', $this->fieldLabel('InvoiceAddressTab'));
     $fields->addFieldToTab('Root.ShippingAddressTab', new LiteralField('sa__Preview', '<p>' . Convert::raw2xml($this->getShippingAddressSummary(true)) . '</p>'));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__TaxIdNumber', $address->fieldLabel('TaxIdNumber'), $this->SilvercartShippingAddress()->TaxIdNumber));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Company', $address->fieldLabel('Company'), $this->SilvercartShippingAddress()->Company));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__FirstName', $address->fieldLabel('FirstName'), $this->SilvercartShippingAddress()->FirstName));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Surname', $address->fieldLabel('Surname'), $this->SilvercartShippingAddress()->Surname));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Addition', $address->fieldLabel('Addition'), $this->SilvercartShippingAddress()->Addition));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Street', $address->fieldLabel('Street'), $this->SilvercartShippingAddress()->Street));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__StreetNumber', $address->fieldLabel('StreetNumber'), $this->SilvercartShippingAddress()->StreetNumber));
     $fields->addFieldToTab('Root.ShippingAddressTab', new CheckboxField('sa__IsPackstation', $address->fieldLabel('IsPackstation'), $this->SilvercartShippingAddress()->IsPackstation));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__PostNumber', $address->fieldLabel('PostNumber'), $this->SilvercartShippingAddress()->PostNumber));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Packstation', $address->fieldLabel('PackstationPlain'), $this->SilvercartShippingAddress()->Packstation));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Postcode', $address->fieldLabel('Postcode'), $this->SilvercartShippingAddress()->Postcode));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__City', $address->fieldLabel('City'), $this->SilvercartShippingAddress()->City));
     $fields->addFieldToTab('Root.ShippingAddressTab', new DropdownField('sa__Country', $address->fieldLabel('Country'), SilvercartCountry::get_active()->map()->toArray(), $this->SilvercartShippingAddress()->SilvercartCountry()->ID));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__PhoneAreaCode', $address->fieldLabel('PhoneAreaCode'), $this->SilvercartShippingAddress()->PhoneAreaCode));
     $fields->addFieldToTab('Root.ShippingAddressTab', new TextField('sa__Phone', $address->fieldLabel('Phone'), $this->SilvercartShippingAddress()->Phone));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new LiteralField('ia__Preview', '<p>' . Convert::raw2xml($this->getInvoiceAddressSummary(true)) . '</p>'));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__TaxIdNumber', $address->fieldLabel('TaxIdNumber'), $this->SilvercartInvoiceAddress()->TaxIdNumber));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Company', $address->fieldLabel('Company'), $this->SilvercartInvoiceAddress()->Company));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__FirstName', $address->fieldLabel('FirstName'), $this->SilvercartInvoiceAddress()->FirstName));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Surname', $address->fieldLabel('Surname'), $this->SilvercartInvoiceAddress()->Surname));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Addition', $address->fieldLabel('Addition'), $this->SilvercartInvoiceAddress()->Addition));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Street', $address->fieldLabel('Street'), $this->SilvercartInvoiceAddress()->Street));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__StreetNumber', $address->fieldLabel('StreetNumber'), $this->SilvercartInvoiceAddress()->StreetNumber));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new CheckboxField('ia__IsPackstation', $address->fieldLabel('IsPackstation'), $this->SilvercartInvoiceAddress()->IsPackstation));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__PostNumber', $address->fieldLabel('PostNumber'), $this->SilvercartInvoiceAddress()->PostNumber));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Packstation', $address->fieldLabel('PackstationPlain'), $this->SilvercartInvoiceAddress()->Packstation));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Postcode', $address->fieldLabel('Postcode'), $this->SilvercartInvoiceAddress()->Postcode));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__City', $address->fieldLabel('City'), $this->SilvercartInvoiceAddress()->City));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new DropdownField('ia__Country', $address->fieldLabel('Country'), SilvercartCountry::get_active()->map()->toArray(), $this->SilvercartInvoiceAddress()->SilvercartCountry()->ID));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__PhoneAreaCode', $address->fieldLabel('PhoneAreaCode'), $this->SilvercartInvoiceAddress()->PhoneAreaCode));
     $fields->addFieldToTab('Root.InvoiceAddressTab', new TextField('ia__Phone', $address->fieldLabel('Phone'), $this->SilvercartInvoiceAddress()->Phone));
     //add print preview
     $fields->findOrMakeTab('Root.PrintPreviewTab', $this->fieldLabel('PrintPreview'));
     $printPreviewField = new LiteralField('PrintPreviewField', sprintf('<iframe width="100%%" height="100%%" border="0" src="%s" class="print-preview"></iframe>', SilvercartPrint::getPrintInlineURL($this)));
     $fields->addFieldToTab('Root.PrintPreviewTab', $printPreviewField);
     return $fields;
 }
 /**
  * CMS fields for this object
  * 
  * @param array $params Scaffolding parameters
  * 
  * @return FieldList
  */
 public function getCMSFields($params = null)
 {
     $fields = SilvercartDataObject::getCMSFields($this);
     if ($fields->dataFieldByName('SilvercartCountryID')) {
         $countryDropdown = new DropdownField('SilvercartCountryID', $this->fieldLabel('Country'), SilvercartCountry::getPrioritiveDropdownMap());
         $fields->replaceField('SilvercartCountryID', $countryDropdown);
     }
     return $fields;
 }
// write country ZM
if (!SilvercartCountry::get()->filter("ISO2", "ZM")->exists()) {
    $country = new SilvercartCountry();
    $country->ISO2 = "ZM";
    $country->ISO3 = "ZMB";
    $country->FIPS = "ZA";
    $country->ISON = "894";
    $country->Title = _t("SilvercartCountry.TITLE_ZM");
    $country->Continent = "AF";
    $country->Currency = "ZMK";
    $country->Locale = Translatable::get_current_locale();
    $country->write();
}
// write country ZW
if (!SilvercartCountry::get()->filter("ISO2", "ZW")->exists()) {
    $country = new SilvercartCountry();
    $country->ISO2 = "ZW";
    $country->ISO3 = "ZWE";
    $country->FIPS = "ZI";
    $country->ISON = "716";
    $country->Title = _t("SilvercartCountry.TITLE_ZW");
    $country->Continent = "AF";
    $country->Currency = "ZWL";
    $country->Locale = Translatable::get_current_locale();
    $country->write();
}
$translatorsByPrio = i18n::get_translators();
foreach ($translatorsByPrio as $priority => $translators) {
    foreach ($translators as $name => $translator) {
        $adapter = $translator->getAdapter();
        $languages = $adapter->getList();
 /**
  * Set initial form values
  *
  * @return void
  *
  * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 07.12.2012
  */
 protected function fillInFieldValues()
 {
     // --------------------------------------------------------------------
     // Set i18n labels
     // --------------------------------------------------------------------
     $this->formFields['InvoiceAddressAsShippingAddress']['title'] = _t('SilvercartAddress.InvoiceAddressAsShippingAddress');
     $this->formFields['Invoice_Salutation']['title'] = _t('SilvercartAddress.SALUTATION', 'salutation');
     $this->formFields['Invoice_Salutation']['value'] = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES', 'misses'), "Herr" => _t('SilvercartAddress.MISTER', 'mister'));
     $this->formFields['Invoice_AcademicTitle']['title'] = _t('SilvercartAddress.AcademicTitle', 'Academic title');
     $this->formFields['Invoice_FirstName']['title'] = _t('SilvercartAddress.FIRSTNAME', 'firstname');
     $this->formFields['Invoice_Surname']['title'] = _t('SilvercartAddress.SURNAME', 'surname');
     $this->formFields['Invoice_Addition']['title'] = _t('SilvercartAddress.ADDITION', 'addition');
     $this->formFields['Invoice_Street']['title'] = _t('SilvercartAddress.STREET', 'street');
     $this->formFields['Invoice_StreetNumber']['title'] = _t('SilvercartAddress.STREETNUMBER', 'streetnumber');
     $this->formFields['Invoice_Postcode']['title'] = _t('SilvercartAddress.POSTCODE', 'postcode');
     $this->formFields['Invoice_City']['title'] = _t('SilvercartAddress.CITY', 'city');
     $this->formFields['Invoice_Phone']['title'] = _t('SilvercartAddress.PHONE', 'phone');
     $this->formFields['Invoice_PhoneAreaCode']['title'] = _t('SilvercartAddress.PHONEAREACODE', 'phone area code');
     $this->formFields['Invoice_Country']['title'] = _t('SilvercartCountry.SINGULARNAME');
     $this->formFields['Shipping_Salutation']['title'] = _t('SilvercartAddress.SALUTATION');
     $this->formFields['Shipping_Salutation']['value'] = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER'));
     $this->formFields['Shipping_AcademicTitle']['title'] = _t('SilvercartAddress.AcademicTitle');
     $this->formFields['Shipping_FirstName']['title'] = _t('SilvercartAddress.FIRSTNAME');
     $this->formFields['Shipping_Surname']['title'] = _t('SilvercartAddress.SURNAME');
     $this->formFields['Shipping_Addition']['title'] = _t('SilvercartAddress.ADDITION');
     $this->formFields['Shipping_Street']['title'] = _t('SilvercartAddress.STREET');
     $this->formFields['Shipping_StreetNumber']['title'] = _t('SilvercartAddress.STREETNUMBER');
     $this->formFields['Shipping_Postcode']['title'] = _t('SilvercartAddress.POSTCODE');
     $this->formFields['Shipping_City']['title'] = _t('SilvercartAddress.CITY');
     $this->formFields['Shipping_Phone']['title'] = _t('SilvercartAddress.PHONE');
     $this->formFields['Shipping_PhoneAreaCode']['title'] = _t('SilvercartAddress.PHONEAREACODE');
     $this->formFields['Shipping_Country']['title'] = _t('SilvercartCountry.SINGULARNAME');
     $countries = SilvercartCountry::get()->filter('Active', 1);
     if ($countries->exists()) {
         $this->formFields['Shipping_Country']['value'] = SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartCheckoutFormStep2.EMPTYSTRING_COUNTRY'));
         $this->formFields['Invoice_Country']['value'] = SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartCheckoutFormStep2.EMPTYSTRING_COUNTRY'));
     }
     // --------------------------------------------------------------------
     // Insert values from previous entries the customer has made
     // --------------------------------------------------------------------
     $this->controller->fillFormFields($this->formFields);
     if ($this->formFields['InvoiceAddressAsShippingAddress']['value'] == '1') {
         $this->controller->addJavascriptOnloadSnippet(array('deactivateShippingAddressValidation();
                 $(\'#ShippingAddressFields\').css(\'display\', \'none\');', 'loadInTheEnd'));
     }
 }
 /**
  * Returns the form fields
  * 
  * @param bool $withUpdate Execute update method of decorators?
  * 
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function getFormFields($withUpdate = true)
 {
     if (empty($this->formFields)) {
         if (Member::currentUserID() > 0) {
             $member = SilvercartCustomer::currentUser();
         } else {
             $member = singleton('Member');
         }
         $address = singleton('SilvercartAddress');
         $this->formFields = array('Salutation' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('Salutation'), 'selectedValue' => $member->Salutation, 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER')), 'checkRequirements' => array('isFilledIn' => true)), 'FirstName' => array('type' => 'TextField', 'title' => $address->fieldLabel('FirstName'), 'value' => $member->FirstName, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Surname' => array('type' => 'TextField', 'title' => $address->fieldLabel('Surname'), 'value' => $member->Surname, 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)), 'Email' => array('type' => 'TextField', 'title' => $member->fieldLabel('Email'), 'value' => $member->Email, 'checkRequirements' => array('isFilledIn' => true, 'isEmailAddress' => true)), 'Message' => array('type' => 'TextareaField', 'title' => _t('SilvercartPage.MESSAGE', 'message'), 'checkRequirements' => array('isFilledIn' => true, 'hasMinLength' => 3)));
         if ($this->EnableStreet()) {
             $requirements = array();
             if ($this->StreetIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Street' => array('type' => 'TextField', 'title' => $address->fieldLabel('Street') . ' / ' . $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements), 'StreetNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('StreetNumber'), 'checkRequirements' => $requirements)));
         }
         if ($this->EnableCity()) {
             $requirements = array();
             if ($this->CityIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Postcode' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode'), 'checkRequirements' => $requirements), 'City' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode') . ' - ' . $address->fieldLabel('City'), 'checkRequirements' => $requirements)));
         }
         if ($this->EnableCountry()) {
             $requirements = array();
             if ($this->CountryIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('SilvercartCountryID' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('SilvercartCountry'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE')), 'checkRequirements' => $requirements)));
         }
         if ($this->EnablePhoneNumber()) {
             $requirements = array();
             if ($this->PhoneNumberIsRequired()) {
                 $requirements = array('isFilledIn' => true);
             }
             $this->formFields = array_merge($this->formFields, array('Phone' => array('type' => 'TextField', 'title' => $address->fieldLabel('Phone'), 'checkRequirements' => $requirements)));
         }
     }
     return parent::getFormFields($withUpdate);
 }
 /**
  * creates test configuration data on /dev/build or by adding test
  * configuration in ModelAdmin.
  *
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 02.07.2011
  */
 public static function createTestConfiguration()
 {
     if (self::$enableTestData === true) {
         //create a carrier and an associated zone and shipping method
         $carrier = SilvercartCarrier::get()->first();
         if (!$carrier) {
             self::createTestTaxRates();
             $carrier = new SilvercartCarrier();
             $carrier->Title = 'DHL';
             $carrier->FullTitle = 'DHL International GmbH';
             $carrier->write();
             $carrierLanguages = array('en_GB' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'en_US' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'de_DE' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'));
             $locales = array('de_DE', 'en_GB', 'en_US');
             $fallbackLocale = false;
             if (!in_array(Translatable::get_current_locale(), $locales)) {
                 $locales[] = Translatable::get_current_locale();
                 $fallbackLocale = Translatable::get_current_locale();
             }
             if ($fallbackLocale !== false) {
                 $carrierLanguages[$fallbackLocale] = $carrierLanguages['en_US'];
             }
             foreach ($carrierLanguages as $locale => $attributes) {
                 $languageObj = SilvercartCarrierLanguage::get()->filter(array('SilvercartCarrierID' => $carrier->ID, 'Locale' => $locale))->first();
                 if (!$languageObj) {
                     $languageObj = new SilvercartCarrierLanguage();
                     $languageObj->Locale = $locale;
                     $languageObj->SilvercartCarrierID = $carrier->ID;
                 }
                 foreach ($attributes as $attribute => $value) {
                     $languageObj->{$attribute} = $value;
                 }
                 $languageObj->write();
             }
             //relate carrier to zones
             $zoneDomestic = SilvercartZone::get()->first();
             if (!$zoneDomestic) {
                 $zones = array(array('en_GB' => 'Domestic', 'en_US' => 'Domestic', 'de_DE' => 'Inland'), array('en_GB' => 'EU', 'en_US' => 'European Union', 'de_DE' => 'EU'));
                 $locales = array('de_DE', 'en_GB', 'en_US');
                 $fallbackLocale = false;
                 if (!in_array(Translatable::get_current_locale(), $locales)) {
                     $locales[] = Translatable::get_current_locale();
                     $fallbackLocale = Translatable::get_current_locale();
                 }
                 if ($fallbackLocale !== false) {
                     $zones[0][$fallbackLocale] = $zones[0]['en_US'];
                     $zones[1][$fallbackLocale] = $zones[1]['en_US'];
                 }
                 foreach ($zones as $zone) {
                     $zoneObj = new SilvercartZone();
                     $zoneObj->write();
                     $zoneObj->SilvercartCarriers()->add($carrier);
                     $zoneObj->write();
                     foreach ($zone as $locale => $title) {
                         $zoneLanguage = SilvercartZoneLanguage::get()->filter(array('SilvercartZoneID' => $zoneObj->ID, 'Locale' => $locale))->first();
                         if (!$zoneLanguage) {
                             $zoneLanguage = new SilvercartZoneLanguage();
                             $zoneLanguage->SilvercartZoneID = $zoneObj->ID;
                             $zoneLanguage->Locale = $locale;
                         }
                         $zoneLanguage->Title = $title;
                         $zoneLanguage->write();
                     }
                 }
             }
             //Retrieve the active country if exists
             $country = SilvercartCountry::get()->filter('Active', '1')->first();
             if (!$country) {
                 //Retrieve the country dynamically depending on the installation language
                 $installationLanguage = i18n::get_locale();
                 $ISO2 = substr($installationLanguage, -2);
                 $country = SilvercartCountry::get()->filter('ISO2', $ISO2)->first();
                 if (!$country) {
                     $country = new SilvercartCountry();
                     $country->Title = 'Testcountry';
                     $country->ISO2 = $ISO2;
                     $country->ISO3 = $ISO2;
                 }
                 $country->Active = true;
                 $country->write();
             }
             $zoneDomestic = DataObject::get_by_id('SilvercartZone', 1);
             $zoneDomestic->SilvercartCountries()->add($country);
             // create if not exists, activate and relate payment method
             $paymentMethod = SilvercartPaymentPrepayment::get()->first();
             if (!$paymentMethod) {
                 $paymentMethodHandler = new SilvercartPaymentMethod();
                 $paymentMethodHandler->requireDefaultRecords();
             }
             $paymentMethod = SilvercartPaymentPrepayment::get()->first();
             $paymentMethod->isActive = true;
             $orderStatusPending = SilvercartOrderStatus::get()->filter('Code', 'pending')->first();
             if ($orderStatusPending) {
                 $paymentMethod->orderStatus = $orderStatusPending->Code;
             }
             $paymentMethod->write();
             $country->SilvercartPaymentMethods()->add($paymentMethod);
             // create a shipping method
             $shippingMethod = SilvercartShippingMethod::get()->first();
             if (!$shippingMethod) {
                 $shippingMethod = new SilvercartShippingMethod();
                 //relate shipping method to carrier
                 $shippingMethod->SilvercartCarrierID = $carrier->ID;
             }
             $shippingMethod->isActive = 1;
             $shippingMethod->write();
             $shippingMethod->SilvercartZones()->add($zoneDomestic);
             //create the language objects for the shipping method
             $shippingMethodTranslations = array('de_DE' => 'Paket', 'en_GB' => 'Package', 'en_US' => 'Package');
             $locales = array('de_DE', 'en_GB', 'en_US');
             $fallbackLocale = false;
             if (!in_array(Translatable::get_current_locale(), $locales)) {
                 $locales[] = Translatable::get_current_locale();
                 $fallbackLocale = Translatable::get_current_locale();
             }
             if ($fallbackLocale !== false) {
                 $shippingMethodTranslations[$fallbackLocale] = $shippingMethodTranslations['en_US'];
             }
             foreach ($shippingMethodTranslations as $locale => $title) {
                 $shippingMethodLanguage = SilvercartShippingMethodLanguage::get()->filter(array('Locale' => $locale, 'SilvercartShippingMethodID' => $shippingMethod->ID))->first();
                 if (!$shippingMethodLanguage) {
                     $shippingMethodLanguage = new SilvercartShippingMethodLanguage();
                     $shippingMethodLanguage->Locale = $locale;
                     $shippingMethodLanguage->SilvercartShippingMethodID = $shippingMethod->ID;
                 }
                 $shippingMethodLanguage->Title = $title;
                 $shippingMethodLanguage->write();
             }
             // create a shipping fee and relate it to zone, tax and shipping method
             $shippingFee = SilvercartShippingFee::get()->first();
             if (!$shippingFee) {
                 $shippingFee = new SilvercartShippingFee();
                 $shippingFee->MaximumWeight = '100000';
                 $shippingFee->UnlimitedWeight = true;
                 $shippingFee->Price = new Money();
                 $shippingFee->Price->setAmount('3.9');
                 $shippingFee->Price->setCurrency('EUR');
             }
             $shippingFee->SilvercartShippingMethodID = $shippingMethod->ID;
             $shippingFee->SilvercartZoneID = $zoneDomestic->ID;
             $higherTaxRate = SilvercartTax::get()->filter('Rate', '19')->first();
             $shippingFee->SilvercartTaxID = $higherTaxRate->ID;
             $shippingFee->write();
             return true;
         }
     }
     return false;
 }
 /**
  * Returns the form fields
  * 
  * @param bool $withUpdate Execute update method of decorators?
  * 
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 05.06.2014
  */
 public function getFormFields($withUpdate = true)
 {
     if (empty($this->formFields)) {
         $email = '';
         $orderDate = '';
         $orderNumber = '';
         $orderPositions = '';
         $orderID = '';
         $customer = SilvercartCustomer::currentRegisteredCustomer();
         if ($customer instanceof Member) {
             $email = $customer->Email;
             $address = $customer->SilvercartInvoiceAddress();
             $existingOrder = array('type' => 'DropdownField', 'title' => _t('SilvercartRevocationForm.OrderHistory'), 'value' => $customer->SilvercartOrder()->map('ID', 'Title', ' '));
             if (array_key_exists('ExistingOrder', $_POST)) {
                 $orderID = $_POST['ExistingOrder'];
             } elseif (array_key_exists('o', $_GET)) {
                 $orderID = $_GET['o'];
                 if (!is_numeric($orderID)) {
                     $orderID = '';
                 }
             }
             if (!empty($orderID)) {
                 $order = $customer->SilvercartOrder()->find('ID', $orderID);
                 if ($order instanceof SilvercartOrder && $order->exists()) {
                     $existingOrder['selectedValue'] = $orderID;
                     $address = $order->SilvercartInvoiceAddress();
                     $orderDate = date(_t('Silvercart.DATEFORMAT'), strtotime($order->Created));
                     $orderNumber = $order->OrderNumber;
                     $orderPositions = $order->getPositionsAsString(false, true);
                 }
             }
         } else {
             $address = singleton('SilvercartAddress');
             $existingOrder = array();
         }
         $this->formFields = array('RevocationOrderData' => array('type' => 'TextareaField', 'title' => _t('SilvercartRevocationForm.RevocationOrderData'), 'value' => $orderPositions), 'Email' => array('type' => 'TextField', 'title' => _t('SilvercartAddress.EMAIL'), 'value' => $email, 'checkRequirements' => array('isFilledIn' => true)), 'OrderDate' => array('type' => 'TextField', 'title' => _t('SilvercartRevocationForm.OrderDate'), 'value' => $orderDate), 'OrderNumber' => array('type' => 'TextField', 'title' => _t('SilvercartRevocationForm.OrderNumber'), 'value' => $orderNumber), 'Salutation' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('Salutation'), 'value' => array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER')), 'selectedValue' => $address->Salutation), 'FirstName' => array('type' => 'TextField', 'title' => $address->fieldLabel('FirstName'), 'value' => $address->FirstName, 'checkRequirements' => array('isFilledIn' => true)), 'Surname' => array('type' => 'TextField', 'title' => $address->fieldLabel('Surname'), 'value' => $address->Surname, 'checkRequirements' => array('isFilledIn' => true)), 'Addition' => array('type' => 'TextField', 'title' => $address->fieldLabel('Addition'), 'value' => $address->Addition), 'Street' => array('type' => 'TextField', 'title' => $address->fieldLabel('Street'), 'value' => $address->Street), 'StreetNumber' => array('type' => 'TextField', 'title' => $address->fieldLabel('StreetNumber'), 'value' => $address->StreetNumber), 'Postcode' => array('type' => 'TextField', 'title' => $address->fieldLabel('Postcode'), 'value' => $address->Postcode), 'City' => array('type' => 'TextField', 'title' => $address->fieldLabel('City'), 'value' => $address->City), 'Country' => array('type' => 'DropdownField', 'title' => $address->fieldLabel('SilvercartCountry'), 'value' => SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE')), 'selectedValue' => $address->SilvercartCountryID));
         if (!empty($existingOrder)) {
             $this->formFields['ExistingOrder'] = $existingOrder;
         }
     }
     return parent::getFormFields($withUpdate);
 }
 /**
  * Returns whether this zone is related to all active countries
  *
  * @return boolean 
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 08.06.2012
  */
 public function hasAllCountries()
 {
     /* @var $countries ArrayList */
     $countries = $this->SilvercartCountries();
     $availableCountries = SilvercartCountry::get()->filter("Active", 1);
     $hasAllCountries = true;
     foreach ($availableCountries as $availableCountry) {
         if (!$countries->find('ID', $availableCountry->ID)) {
             $hasAllCountries = false;
             break;
         }
     }
     return $hasAllCountries;
 }
 /**
  * Creates an address using the given checkout data and prefix.
  * 
  * @param array  $checkoutData Checkout data
  * @param string $prefix       Prefix
  * 
  * @return SilvercartAddress
  */
 public function getAddressByCheckoutData($checkoutData, $prefix = 'Invoice')
 {
     $db = Config::inst()->get('SilvercartAddress', 'db');
     $has_one = Config::inst()->get('SilvercartAddress', 'has_one');
     $address = new SilvercartAddress();
     foreach (array_keys($db) as $fieldname) {
         if (array_key_exists($prefix . '_' . $fieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $fieldname];
         }
     }
     foreach (array_keys($has_one) as $relationname) {
         $fieldname = $relationname . 'ID';
         $plainFieldname = str_replace('Silvercart', '', $fieldname);
         $plainRelationname = str_replace('Silvercart', '', $relationname);
         if (array_key_exists($prefix . '_' . $relationname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $relationname];
         } elseif (array_key_exists($prefix . '_' . $fieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $fieldname];
         } elseif (array_key_exists($prefix . '_' . $plainRelationname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $plainRelationname];
         } elseif (array_key_exists($prefix . '_' . $plainFieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $plainFieldname];
         }
         if (!is_null($address->{$fieldname})) {
             $address->{$plainFieldname} = $address->{$fieldname};
         }
     }
     if (is_null($address->IsPackstation) || $prefix == 'Invoice') {
         $address->IsPackstation = false;
     }
     $address->Country = SilvercartCountry::get()->byID($address->SilvercartCountryID);
     return $address;
 }
 /**
  * Returns the current shipping country
  *
  * @return SilvercartCountry
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function ShippingCountry()
 {
     $customer = SilvercartCustomer::currentUser();
     $shippingCountry = null;
     if ($customer) {
         $shippingCountry = $customer->SilvercartShippingAddress()->SilvercartCountry();
     }
     if (is_null($shippingCountry) || $shippingCountry->ID == 0) {
         $shippingCountry = SilvercartCountry::get()->filter(array('ISO2' => substr(Translatable::get_current_locale(), 3), 'Active' => 1))->first();
     }
     return $shippingCountry;
 }
 /**
  * Defines additional searchable fields.
  *
  * @param array &$fields The searchable fields from the decorated object
  * 
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 25.06.2014
  */
 public function updateSearchableFields(&$fields)
 {
     $address = singleton('SilvercartAddress');
     $addressesCountryFilter = array('SilvercartAddresses.SilvercartCountryID' => array('title' => $address->fieldLabel('SilvercartCountry'), 'filter' => 'ExactMatchFilter', 'field' => new DropdownField('SilvercartAddresses.SilvercartCountryID', $address->fieldLabel('SilvercartCountry'), SilvercartCountry::getPrioritiveDropdownMap(false, ''))));
     $fields = array_merge($fields, array('CustomerNumber' => array('title' => $this->owner->fieldLabel('CustomerNumber'), 'filter' => 'PartialMatchFilter'), 'FirstName' => array('title' => $this->owner->fieldLabel('FirstName'), 'filter' => 'PartialMatchFilter'), 'Groups.ID' => array('title' => $this->owner->fieldLabel('GroupNames'), 'filter' => 'ExactMatchFilter'), 'SubscribedToNewsletter' => array('title' => $this->owner->fieldLabel('SubscribedToNewsletter'), 'filter' => 'ExactMatchFilter'), 'SilvercartAddresses.FirstName' => array('title' => $address->fieldLabel('FirstName'), 'filter' => 'PartialMatchFilter'), 'SilvercartAddresses.Surname' => array('title' => $address->fieldLabel('Surname'), 'filter' => 'PartialMatchFilter'), 'SilvercartAddresses.Street' => array('title' => $address->fieldLabel('Street'), 'filter' => 'PartialMatchFilter'), 'SilvercartAddresses.StreetNumber' => array('title' => $address->fieldLabel('StreetNumber'), 'filter' => 'PartialMatchFilter'), 'SilvercartAddresses.Postcode' => array('title' => $address->fieldLabel('Postcode'), 'filter' => 'PartialMatchFilter'), 'SilvercartAddresses.City' => array('title' => $address->fieldLabel('City'), 'filter' => 'PartialMatchFilter')), $addressesCountryFilter, array('SilvercartInvoiceAddress.FirstName' => array('title' => $address->fieldLabel('FirstName'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.Surname' => array('title' => $address->fieldLabel('Surname'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.Street' => array('title' => $address->fieldLabel('Street'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.StreetNumber' => array('title' => $address->fieldLabel('StreetNumber'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.Postcode' => array('title' => $address->fieldLabel('Postcode'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.City' => array('title' => $address->fieldLabel('City'), 'filter' => 'PartialMatchFilter'), 'SilvercartInvoiceAddress.SilvercartCountry.ID' => array('title' => $address->fieldLabel('SilvercartCountry'), 'filter' => 'ExactMatchFilter'), 'SilvercartShippingAddress.FirstName' => array('title' => $address->fieldLabel('FirstName'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.Surname' => array('title' => $address->fieldLabel('Surname'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.Street' => array('title' => $address->fieldLabel('Street'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.StreetNumber' => array('title' => $address->fieldLabel('StreetNumber'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.Postcode' => array('title' => $address->fieldLabel('Postcode'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.City' => array('title' => $address->fieldLabel('City'), 'filter' => 'PartialMatchFilter'), 'SilvercartShippingAddress.SilvercartCountry.ID' => array('title' => $address->fieldLabel('SilvercartCountry'), 'filter' => 'ExactMatchFilter')));
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $member = SilvercartCustomer::currentUser();
     $id = $formData['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $address = SilvercartAddress::get()->filter($filter)->first();
         if ($address->canEdit()) {
             $address->castedUpdate($formData);
             $country = SilvercartCountry::get()->byID($formData['Country']);
             if ($country) {
                 $address->SilvercartCountryID = $country->ID;
             }
             $address->write();
         }
         $this->submitSuccess = true;
         if (Session::get("redirect")) {
             $this->controller->redirect(Session::get("redirect"));
             Session::clear("redirect");
         } else {
             $addressHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartAddressHolder");
             $this->controller->redirect($addressHolder->RelativeLink());
         }
     }
 }
 /**
  * Returns the free of shipping costs from value if specified.
  * 
  * @param SilvercartCountry $shippingCountry Shipping country
  *
  * @return Money
  *
  * @author Sascha Koehler <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 17.07.2013
  */
 public static function FreeOfShippingCostsFrom($shippingCountry = null)
 {
     self::$freeOfShippingCostsFrom = self::getConfig()->freeOfShippingCostsFrom;
     if (!$shippingCountry instanceof SilvercartCountry && Controller::curr()->hasMethod('getCombinedStepData')) {
         $checkoutData = Controller::curr()->getCombinedStepData();
         if (array_key_exists('Shipping_Country', $checkoutData)) {
             $shippingCountryID = $checkoutData['Shipping_Country'];
             $shippingCountry = SilvercartCountry::get()->byID($shippingCountryID);
         }
     }
     if ($shippingCountry && !is_null($shippingCountry->freeOfShippingCostsFrom->getAmount()) && is_numeric($shippingCountry->freeOfShippingCostsFrom->getAmount())) {
         $shippingCountry->freeOfShippingCostsFrom->getAmount();
         self::$freeOfShippingCostsFrom = $shippingCountry->freeOfShippingCostsFrom;
     }
     return self::$freeOfShippingCostsFrom;
 }
 /**
  * Checks, whether an activated country exists or not.
  *
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 18.04.2011
  */
 public function checkActiveCountries()
 {
     $hasActiveCountries = false;
     /*
      * We have to bypass DataObject::get_one() because it would ignore active
      * countries without a translation of the current locale
      */
     $items = SilvercartCountry::get()->filter(array("Active" => 1));
     if ($items->count() > 0) {
         $hasActiveCountries = true;
     }
     return array('status' => $hasActiveCountries, 'message' => sprintf(_t('SilvercartConfig.ERROR_MESSAGE_NO_ACTIVATED_COUNTRY', 'No activated country found. Please <a href="%s/admin/settings/">log in</a> and choose "SilverCart Configuration -> countries" to activate a country.'), Director::baseURL()));
 }