상속: extends DataObject
 /**
  * Prevent empty defaults
  */
 function onBeforeWrite()
 {
     foreach (self::$defaults as $field => $value) {
         if (empty($this->{$field})) {
             $this->{$field} = $value;
         }
     }
     parent::onBeforeWrite();
 }
 function getRate($address = null)
 {
     if (!$address) {
         $address = singleton('Address');
     }
     $where = array("\"TaxRate\".\"TaxClassID\" = {$this->ID}", RegionRestriction::address_filter($address));
     $sort = implode(', ', array(RegionRestriction::wildcard_sort("PostalCode"), RegionRestriction::wildcard_sort("City"), RegionRestriction::wildcard_sort("State"), RegionRestriction::wildcard_sort("Country"), "\"Rate\" ASC"));
     if ($rate = DataObject::get_one("TaxRate", "(" . implode(") AND (", $where) . ")", true, $sort)) {
         return $rate->Rate;
     }
     return 0;
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fieldList = array("Country" => "Country", "State" => "State", "City" => "City", "PostalCode" => "PostCode", "WeightMin" => "WeightMin", "WeightMax" => "WeightMax", "VolumeMin" => "VolumeMin", "VolumeMax" => "VolumeMax", "ValueMin" => "ValueMin", "ValueMax" => "ValueMax", "QuantityMin" => "QuantityMin", "QuantityMax" => "QuantityMax", "Rate" => "Rate");
     $fieldTypes = array_merge(RegionRestriction::get_table_field_types(), array("WeightMin" => "TextField", "WeightMax" => "TextField", "VolumeMin" => "TextField", "VolumeMax" => "TextField", "ValueMin" => "TextField", "ValueMax" => "TextField", "QuantityMin" => "TextField", "QuantityMax" => "TextField", "Rate" => "TextField"));
     $fields->fieldByName('Root')->removeByName("Rates");
     if ($this->isInDB()) {
         $tablefield = new TableField("Rates", "TableShippingRate", $fieldList, $fieldTypes);
         $tablefield->setCustomSourceItems($this->Rates());
         $fields->addFieldToTab("Root.Main", $tablefield);
     }
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('ShippingMethodID');
     return $fields;
 }
예제 #5
0
 public static function get_zones_for_address(Address $address)
 {
     $where = RegionRestriction::address_filter($address);
     return self::get()->where($where)->sort('PostalCode DESC, City DESC, State DESC, Country DESC')->innerJoin("ZoneRegion", "\"Zone\".\"ID\" = \"ZoneRegion\".\"ZoneID\"")->innerJoin("RegionRestriction", "\"ZoneRegion\".\"ID\" = \"RegionRestriction\".\"ID\"");
 }
 public function getRate(Address $address)
 {
     $where = RegionRestriction::address_filter($address);
     return DataObject::get_one("RegionRestriction_RateTest", $where, true, "Rate ASC");
 }