diff --git a/app/code/MyCompany/IpRestrict/Block/Product/CountryCode.php b/app/code/MyCompany/IpRestrict/Block/Product/CountryCode.php new file mode 100644 index 0000000..646b3cb --- /dev/null +++ b/app/code/MyCompany/IpRestrict/Block/Product/CountryCode.php @@ -0,0 +1,20 @@ +modelCountry = $country; + parent::__construct($context, $data); + } + public function getCountryCode() + { + return $this->modelCountry->getCountryCode();; + } +} \ No newline at end of file diff --git a/app/code/MyCompany/IpRestrict/Model/Country.php b/app/code/MyCompany/IpRestrict/Model/Country.php new file mode 100644 index 0000000..00f9a7b --- /dev/null +++ b/app/code/MyCompany/IpRestrict/Model/Country.php @@ -0,0 +1,34 @@ +get_client_ip(); + $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); + + return $ipdat; + } + + protected function get_client_ip() { + $ipaddress = ''; + if (isset($_SERVER['HTTP_CLIENT_IP'])) + $ipaddress = $_SERVER['HTTP_CLIENT_IP']; + else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) + $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; + else if(isset($_SERVER['HTTP_X_FORWARDED'])) + $ipaddress = $_SERVER['HTTP_X_FORWARDED']; + else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) + $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; + else if(isset($_SERVER['HTTP_FORWARDED'])) + $ipaddress = $_SERVER['HTTP_FORWARDED']; + else if(isset($_SERVER['REMOTE_ADDR'])) + $ipaddress = $_SERVER['REMOTE_ADDR']; + else + $ipaddress = 'UNKNOWN'; + return $ipaddress; + } +} \ No newline at end of file diff --git a/app/code/MyCompany/IpRestrict/Observer/CountryObserver.php b/app/code/MyCompany/IpRestrict/Observer/CountryObserver.php new file mode 100644 index 0000000..7973a75 --- /dev/null +++ b/app/code/MyCompany/IpRestrict/Observer/CountryObserver.php @@ -0,0 +1,27 @@ +modelCountry = $country; + } + /** + * Below is the method that will fire whenever the event runs! + * + * @param Observer $observer + */ + public function execute(\Magento\Framework\Event\Observer $observer) + { + $objCountry = $this->modelCountry->getCountryCode(); + if($objCountry->geoplugin_countryCode=='CN' || $objCountry->geoplugin_countryCode=='RU') + { + echo "