public function updateFields($fields)
 {
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript('swipestripe-addresses/javascript/Addresses_OrderForm.js');
     $shippingAddressFields = CompositeField::create(HeaderField::create(_t('CheckoutPage.SHIPPING_ADDRESS', "Shipping Address"), 3), TextField::create('ShippingFirstName', _t('CheckoutPage.FIRSTNAME', "First Name"))->addExtraClass('shipping-firstname')->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_FIRSTNAME', "Please enter a first name.")), TextField::create('ShippingSurname', _t('CheckoutPage.SURNAME', "Surname"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_SURNAME', "Please enter a surname.")), TextField::create('ShippingCompany', _t('CheckoutPage.COMPANY', "Company")), TextField::create('ShippingAddress', _t('CheckoutPage.ADDRESS', "Address"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_ADDRESS', "Please enter an address."))->addExtraClass('address-break'), TextField::create('ShippingAddressLine2', ' '), TextField::create('ShippingCity', _t('CheckoutPage.CITY', "City"))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_CITY', "Please enter a city.")), TextField::create('ShippingPostalCode', _t('CheckoutPage.POSTAL_CODE', "Zip / Postal Code")), TextField::create('ShippingState', _t('CheckoutPage.STATE', "State / Province"))->addExtraClass('address-break'), DropdownField::create('ShippingCountryCode', _t('CheckoutPage.COUNTRY', "Country"), Country_Shipping::get()->map('Code', 'Title')->toArray())->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_COUNTRY', "Please enter a country."))->addExtraClass('country-code'))->setID('ShippingAddress')->setName('ShippingAddress');
     $billingAddressFields = CompositeField::create(HeaderField::create(_t('CheckoutPage.BILLINGADDRESS', "Billing Address"), 3), $checkbox = CheckboxField::create('BillToShippingAddress', _t('CheckoutPage.SAME_ADDRESS', "same as shipping address?"))->addExtraClass('shipping-same-address'), TextField::create('BillingFirstName', _t('CheckoutPage.FIRSTNAME', "First Name"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURFIRSTNAME', "Please enter your first name."))->addExtraClass('address-break'), TextField::create('BillingSurname', _t('CheckoutPage.SURNAME', "Surname"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURSURNAME', "Please enter your surname.")), TextField::create('BillingCompany', _t('CheckoutPage.COMPANY', "Company")), TextField::create('BillingAddress', _t('CheckoutPage.ADDRESS', "Address"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURADDRESS', "Please enter your address."))->addExtraClass('address-break'), TextField::create('BillingAddressLine2', ' '), TextField::create('BillingCity', _t('CheckoutPage.CITY', "City"))->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURCITY', "Please enter your city")), TextField::create('BillingPostalCode', _t('CheckoutPage.POSTALCODE', "Zip / Postal Code")), TextField::create('BillingState', _t('CheckoutPage.STATE', "State / Province"))->addExtraClass('address-break'), DropdownField::create('BillingCountryCode', _t('CheckoutPage.COUNTRY', "Country"), Country_Billing::get()->map('Code', 'Title')->toArray())->setCustomValidationMessage(_t('CheckoutPage.PLEASEENTERYOURCOUNTRY', "Please enter your country.")))->setID('BillingAddress')->setName('BillingAddress');
     $fields->push($shippingAddressFields);
     $fields->push($billingAddressFields);
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $code = $this->CountryCode;
     $country = Country_Billing::get()->where("\"Code\" = '{$code}'")->first();
     if ($country && $country->exists()) {
         $this->CountryName = $country->Title;
         $this->CountryID = $country->ID;
     }
 }
 /**
  * Build default list of billing countries
  * 
  * @see Country::$iso_3166_countryCodes
  * @see DataObject::requireDefaultRecords()
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('Country_Billing')) {
         foreach (self::$iso_3166_countryCodes as $code => $title) {
             $country = new Country_Billing();
             $country->Code = $code;
             $country->Title = $title;
             $country->write();
         }
         DB::alteration_message('Billing countries created', 'created');
     }
 }
 /**
  * Build default list of billing countries
  * 
  * @see Country::$iso_3166_countryCodes
  * @see DataObject::requireDefaultRecords()
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('Country_Billing')) {
         $shopConfig = ShopConfig::current_shop_config();
         if (isset($shopConfig->ID)) {
             foreach (self::$iso_3166_countryCodes as $code => $title) {
                 $country = new Country_Billing();
                 $country->Code = $code;
                 $country->Title = $title;
                 $country->ShopConfigID = $shopConfig->ID;
                 $country->write();
             }
             DB::alteration_message('Billing countries created', 'created');
         } else {
             DB::alteration_message('Billing countries not created, please re-run /dev/build', 'error');
         }
     }
 }