Version: current

     1 <?php
     2
     3 /**
     4  *
     5  *
     6  * @package cart_shipping
     7  * @author menedem
     8  */
     9 class ShippingSiteConfig extends SiteConfigDecorator {
    10
    11     function extraStatics() {
    12         return array(
    13             'db' => array(
    14                 'AllowedCountries' => 'Text',
    15             ),
    16         );
    17     }
    18
    19     function populateDefaults() {
    20         $this->owner->AllowedCountries = Geoip::visitor_country();
    21     }
    22
    23     function updateCMSFields($fields) {
    24         $tab = WebylonSiteConfig::get_config_tab($fields, 'Shipping');
    25         $tab->push(new CheckboxSetField('AllowedCountries', $this->owner->fieldLabel('AllowedCountries'), Geoip::getCountryDropDown()));
    26     }
    27
    28     /**
    29      * Get list of allowed countries
    30      * @param boolean $prefixisocode - prefix the country code
    31      * @return array
    32      */
    33     function getCountriesList($prefixisocode = false) {
    34         $countries = Geoip::getCountryDropDown();
    35         if ($allowed = $this->owner->AllowedCountries) {
    36             $allowed = explode(",",$allowed);
    37             if (count($allowed > 0))
    38                 $countries = array_intersect_key($countries, array_flip($allowed));
    39         }
    40
    41         if ($prefixisocode) {
    42             foreach ($countries as $key => $value) {
    43                 $countries[$key] = "$key - $value";
    44             }
    45         }
    46         return $countries;
    47     }
    48 }

[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. -