/**
  * Fill the form with default values
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function fillInFieldValues()
 {
     $member = SilvercartCustomer::currentUser();
     $id = $this->customParameters['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $this->address = SilvercartAddress::get()->filter($filter)->first();
         if ($this->address) {
             $this->formFields['Salutation']['selectedValue'] = $this->address->Salutation;
             $this->formFields['AcademicTitle']['value'] = $this->address->AcademicTitle;
             $this->formFields['FirstName']['value'] = $this->address->FirstName;
             $this->formFields['Surname']['value'] = $this->address->Surname;
             $this->formFields['Addition']['value'] = $this->address->Addition;
             $this->formFields['Street']['value'] = $this->address->Street;
             $this->formFields['StreetNumber']['value'] = $this->address->StreetNumber;
             $this->formFields['Postcode']['value'] = $this->address->Postcode;
             $this->formFields['City']['value'] = $this->address->City;
             $this->formFields['PhoneAreaCode']['value'] = $this->address->PhoneAreaCode;
             $this->formFields['Phone']['value'] = $this->address->Phone;
             $this->formFields['Fax']['value'] = $this->address->Fax;
             $this->formFields['Country']['selectedValue'] = $this->address->SilvercartCountry()->ID;
             if (SilvercartConfig::enablePackstation()) {
                 $this->formFields['PostNumber']['value'] = $this->address->PostNumber;
                 $this->formFields['Packstation']['value'] = $this->address->Packstation;
                 $this->formFields['IsPackstation']['selectedValue'] = $this->address->IsPackstation;
             }
             if (SilvercartConfig::enableBusinessCustomers()) {
                 $this->formFields['Company']['value'] = $this->address->Company;
                 $this->formFields['TaxIdNumber']['value'] = $this->address->TaxIdNumber;
             }
         }
     }
 }
 /**
  * Returns handling costs for this payment method
  *
  * @return Money a money object
  */
 public function getHandlingCost()
 {
     $controller = Controller::curr();
     $member = SilvercartCustomer::currentRegisteredCustomer();
     $handlingCostToUse = false;
     if (method_exists($controller, 'getAddress')) {
         // 1) Use shipping address from checkout
         $shippingAddress = $controller->getAddress('Shipping');
     } else {
         if ($member && $member->ShippingAddressID > 0) {
             // 2) Use customer's default shipping address
             $shippingAddress = $member->ShippingAddress();
         } else {
             // 3) Generate shipping address with shop's default country
             $currentShopLocale = i18n::get_lang_from_locale(i18n::get_locale());
             $shippingAddress = new SilvercartAddress();
             $shippingAddress->SilvercartCountry = SilvercartCountry::get()->filter('ISO2', strtoupper($currentShopLocale))->first();
         }
     }
     if (!$shippingAddress) {
         return false;
     }
     $zonesDefined = false;
     foreach ($this->SilvercartHandlingCosts() as $handlingCost) {
         $zone = $handlingCost->SilvercartZone();
         if ($zone->SilvercartCountries()->find('ISO3', $shippingAddress->SilvercartCountry()->ISO3)) {
             $handlingCostToUse = $handlingCost;
             $zonesDefined = true;
             break;
         }
     }
     // Fallback if SilvercartHandlingCosts are available but no zone is defined
     if (!$zonesDefined) {
         if ($this->SilvercartHandlingCosts()->Count() > 0) {
             $handlingCostToUse = $this->SilvercartHandlingCosts()->First();
         } else {
             $silvercartTax = SilvercartTax::get()->filter('isDefault', 1)->first();
             $handlingCostToUse = new SilvercartHandlingCost();
             $handlingCostToUse->SilvercartPaymentMethod = $this;
             $handlingCostToUse->SilvercartTax = $silvercartTax;
             $handlingCostToUse->SilvercartTaxID = $silvercartTax->ID;
             $handlingCostToUse->amount = new Money();
             $handlingCostToUse->amount->setAmount(0);
             $handlingCostToUse->amount->setCurrency(SilvercartConfig::DefaultCurrency());
         }
     }
     return $handlingCostToUse;
 }