Ejemplo n.º 1
0
 function testSetDefaultCountry()
 {
     Geoip::set_default_country_code('DE');
     Geoip::set_enabled(false);
     $this->assertEquals('DE', Geoip::visitor_country());
     $this->assertEquals('DE', Geoip::get_default_country_code());
 }
Ejemplo n.º 2
0
 function __construct($name, $title, $value = '')
 {
     if (!$value) {
         $value = Geoip::visitor_country();
     }
     parent::__construct($name, $title, Geoip::getCountryDropDown(), $value);
 }
 function Field()
 {
     $source = $this->getSource();
     if ($this->defaultToVisitorCountry && !$this->value || !isset($source[$this->value])) {
         $this->value = ($vc = Geoip::visitor_country()) ? $vc : Geoip::$default_country_code;
     }
     return parent::Field();
 }
 /**
  *
  * @return String (Country Code - e.g. NZ, AU, or AF)
  */
 public function getCountry()
 {
     if (class_exists("Geoip")) {
         return Geoip::visitor_country();
     } else {
         return Config::inst()->get("EcommerceCountry", "default_country_code");
     }
 }
 /**
  * Calculates the extra charges from the order based on the weight attribute of a product
  * ASSUMPTION -> weight in grams
  */
 function LiveAmount()
 {
     $order = $this->Order();
     $orderItems = $order->Items();
     // Calculate the total weight of the order
     if ($orderItems) {
         foreach ($orderItems as $orderItem) {
             $totalWeight += $orderItem->Weight * $orderItem->quantity;
         }
     }
     // Check if UseShippingAddress is true and if ShippingCountry exists and use that if it does
     if ($order->UseShippingAddress && $order->ShippingCountry) {
         $shippingCountry = $order->ShippingCountry;
     }
     // if there is a shipping country then check whether it is national or international
     if ($shippingCountry) {
         if ($shippingCountry == 'NZ') {
             return $this->nationalCost($totalWeight);
         } else {
             return $this->internationalCost($totalWeight, $shippingCountry);
         }
     } else {
         if ($order->MemberID && ($member = DataObject::get_by_id('Member', $order->MemberID))) {
             if ($member->Country) {
                 $country = $member->Country;
             } else {
                 $country = Geoip::visitor_country();
             }
         }
         if (!$country) {
             $country = 'NZ';
         }
         if ($country == 'NZ') {
             return $this->nationalCost($totalWeight);
         } else {
             return $this->internationalCost($totalWeight, $country);
         }
     }
 }
 /**
  * Find the member's country.
  *
  * If there is no member logged in, try to resolve
  * their IP address to a country.
  *
  * @return string Found country of member
  */
 static function findCountry()
 {
     $member = Member::currentUser();
     if ($member && $member->Country) {
         $country = $member->Country;
     } else {
         // HACK Avoid CLI tests from breaking (GeoIP gets in the way of unbiased tests!)
         // @todo Introduce a better way of disabling GeoIP as needed (Geoip::disable() ?)
         if (Director::is_cli()) {
             $country = null;
         } else {
             $country = Geoip::visitor_country();
         }
     }
     return $country;
 }
 /**
  * Attempt to find out the country from a user who
  * is not logged into the website using GeoIP.
  * 
  * @return string
  */
 public function findCountry()
 {
     return Geoip::visitor_country();
 }
 /**
  * This function works out the most likely country for the current order
  * @return String - Country Code - e.g. NZ
  **/
 public static function get_country()
 {
     $countryCode = '';
     //1. fixed country is first
     $countryCode = self::get_fixed_country_code();
     if (!$countryCode) {
         //2. check shipping address
         if ($o = ShoppingCart::current_order()) {
             $countryCode = $o->Country();
         }
         //3. check GEOIP information
         if (!$countryCode) {
             $countryCode = @Geoip::visitor_country();
             //4 check default country set in GEO IP....
             if (!$countryCode) {
                 $countryCode = Geoip::$default_country_code;
                 //5. take the FIRST country from the get_allowed_country_codes
                 if (!$countryCode) {
                     $countryArray = self::list_of_allowed_entries_for_dropdown();
                     if (is_array($countryArray) && count($countryArray)) {
                         foreach ($countryArray as $countryCode => $countryName) {
                             //we stop at the first one... as we have no idea which one is the best.
                             break;
                         }
                     }
                 }
             }
         }
     }
     return $countryCode;
 }