public function updateFields(FieldList $fields)
 {
     /** @var CompositeField $shippingAddressFields */
     if ($shippingAddressFields = $fields->fieldByName('ShippingAddress')) {
         /** @var DropdownField $countryCodeField */
         if ($countryCodeField = $shippingAddressFields->fieldByName('ShippingCountryCode')) {
             $countryCodeField->setReadonly(true);
             $shippingAddressFields->insertBefore(DropdownField::create('ShippingRegionCode', _t('CheckoutPage.REGION', 'Region'), Region_Shipping::get()->map('Code', 'Title')->toArray())->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_REGION', "Please enter a shipping region."))->addExtraClass('region-code'), 'ShippingCountryCode');
         }
     }
 }
 /**
  * Retrieve map of shipping regions including Country code
  * 
  * @return Array 
  */
 public static function shipping_map()
 {
     $countryRegions = array();
     $regions = Region_Shipping::get();
     if ($regions && $regions->exists()) {
         foreach ($regions as $region) {
             $country = $region->Country();
             $countryRegions[$country->Code][$region->Code] = $region->Title;
         }
     }
     return $countryRegions;
 }
 /**
  * Provide editable columns for a related instance of the extended model where the 'parent' record needs a hidden
  * ID.
  *
  * @param $relatedModelClass
  * @param $relatedID
  * @param array $fieldSpecs
  * @return mixed|void
  */
 public function provideRelatedEditableColumns($relatedModelClass, $relatedID, array &$fieldSpecs)
 {
     $regions = Region_Shipping::get()->map()->toArray();
     $fieldSpecs += array('RegionID' => array('title' => 'Region', 'callback' => function ($record, $col) use($regions) {
         return new Select2Field('RegionID', '', $regions, $record ? $record->{$col} : null);
     }), 'Price' => array('title' => 'Shipping Price', 'callback' => function ($record, $col) {
         return new PriceField('Price', '', $record ? $record->{$col} : null);
     }), 'ShippableID' => array('callback' => function ($record, $col) use($relatedID) {
         return new HiddenField('ShippableID', '', $relatedID);
     }), 'ID' => array('callback' => function ($record, $col) {
         return new HiddenField('ID', '', $record ? $record->{$col} : null);
     }));
 }
 public function onBeforeWrite()
 {
     //Update address names
     $country = Country_Shipping::get()->where("\"Code\" = '{$this->owner->ShippingCountryCode}'")->first();
     if ($country && $country->exists()) {
         $this->owner->ShippingCountryName = $country->Title;
     }
     $region = Region_Shipping::get()->where("\"Code\" = '{$this->owner->ShippingRegionCode}'")->first();
     if ($region && $region->exists()) {
         $this->owner->ShippingRegionName = $region->Title;
     }
     $country = Country_Billing::get()->where("\"Code\" = '{$this->owner->BillingCountryCode}'")->first();
     if ($country && $country->exists()) {
         $this->owner->BillingCountryName = $country->Title;
     }
 }
 /**
  * Called when a grid sheet is displaying a model related to another model. e.g. as a grid for a models ItemEditForm
  * in ModelAdmin.
  *
  * @param $relatedModelClass
  * @param $relatedID
  * @param array $fieldSpecs
  * @return mixed
  */
 public function provideRelatedEditableColumns($relatedModelClass, $relatedID, array &$fieldSpecs)
 {
     if (static::RelatedModelClass == $relatedModelClass) {
         $shippingRegions = Region_Shipping::get()->map()->toArray();
         $fieldSpecs += array('RegionID' => array('title' => 'Region', 'callback' => function ($record, $col) use($shippingRegions) {
             $field = new Select2Field('RegionID', '', $shippingRegions, $record ? $record->{$col} : null);
             return $field;
         }), 'Price' => array('title' => 'Price', 'callback' => function ($record, $col) {
             return new NumericField($col, $col, $record ? $record->{$col} : null);
         }), 'ShippableID' => array('callback' => function ($record) use($relatedID) {
             return new HiddenField('ShippableID', '', $relatedID);
         }));
         return true;
     }
     return false;
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $code = $this->CountryCode;
     $country = Country_Shipping::get()->where("\"Code\" = '{$code}'")->first();
     if ($country && $country->exists()) {
         $this->CountryName = $country->Title;
         $this->CountryID = $country->ID;
     }
     $code = $this->RegionCode;
     $region = Region_Shipping::get()->where("\"Code\" = '{$code}'")->first();
     if ($region && $region->exists()) {
         $this->RegionName = $region->Title;
         $this->RegionID = $region->ID;
     }
 }
 protected function shippingRegionID($code)
 {
     if ($region = Region_Shipping::get()->filter('Code', $code)->first()) {
         return $region->ID;
     }
 }
 public function Regions()
 {
     return Region_Shipping::get()->where("\"CountryID\" = " . $this->ID);
 }
Beispiel #9
0
 public function updateOrderEditForm(FieldList $fields)
 {
     $fields->push(new Select2Field('ShippingRegionCode', 'Shipping Region', Region_Shipping::get()->map('Code', 'Title'), $this->owner->ShippingRegionCode));
 }