Version: current

     1 <?php
     2
     3 /**
     4  * Способ оплаты на основе веса посылки
     5  *
     6  * @package cart_shipping
     7  * @author menedem
     8  */
     9 class WeightTableShippingMethod extends TableShippingMethod {
    10
    11     static $has_many = array(
    12         "Rates" => "WeightTableShippingRate"
    13     );
    14
    15     function getConstraints() {
    16         return array('Weight');
    17     }
    18
    19     function getCMSFields(){
    20         $fields = parent::getCMSFields();
    21
    22         $rate = new WeightTableShippingRate();
    23         $fieldList = array(
    24             "Country" => $rate->fieldLabel('Country'),
    25             "State" => $rate->fieldLabel('State'),
    26             "City" => $rate->fieldLabel('City'),
    27             "PostalCode" => $rate->fieldLabel('PostalCode'),
    28             "WeightMin" => $rate->fieldLabel('WeightMin'),
    29             "WeightMax" => $rate->fieldLabel('WeightMax'),
    30             "Rate" => $rate->fieldLabel('Rate'),
    31         );
    32
    33         $fieldTypes = array_merge(RegionRestriction::get_table_field_types(),array(
    34             "WeightMin" => "TextField",
    35             "WeightMax" => "TextField",
    36             "Rate" => "TextField"
    37         ));
    38
    39         $fields->fieldByName('Root')->removeByName("Rates");
    40         if($this->isInDB()){
    41             $tablefield = new TableField("Rates", "WeightTableShippingRate", $fieldList, $fieldTypes);
    42             $tablefield->setCustomSourceItems($this->Rates());
    43             $fields->addFieldToTab("Root.Main", $tablefield);
    44         }
    45         return $fields;
    46     }
    47 }
    48
    49 /**
    50  * Adds extra metric ranges to restrict with, rather than just region.
    51  */
    52 class WeightTableShippingRate extends TableShippingRate{
    53
    54     static $db = array(
    55         "WeightMin" => "Decimal(8,2)",
    56         "WeightMax" => "Decimal(8,2)",
    57     );
    58
    59     static $has_one = array(
    60         "ShippingMethod" => "WeightTableShippingMethod"
    61     );
    62
    63     static $summary_fields = array(
    64         'Country',
    65         'State',
    66         'City',
    67         'PostalCode',
    68         'WeightMin',
    69         'WeightMax',
    70         'Rate'
    71     );
    72
    73 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -