Ali Samie Posted April 16, 2022 Share Posted April 16, 2022 (edited) Update note: Hi community members. We have come to a solution for our problem. Actually I can not share the module due to our clients restriction. Because we have been paid to develop this module. But I want to share the idea and design for this module. If you are a developer you can create this module pretty easy. What is the need? Imagine you need to hide some products for some countries. For example we have a product100 And we have a shop which is open to all countries in the world But we want product100 to be available to order only in Canada and no where else We also have another product called product200 We want to sell this product in any country except Germany and USA What was our Idea? Set custom feature to product Custom feature indicates that this product is hidden in some coutnries Set ISO code of countries as the custom value of product feature How to filter products? In order to filter products and remove some from listing, use this hook: filterProductSearch How to identify the country of visitor? There are a lot of ways to translate visitor's IP address into ISO code of the country We have used MaxMind database Edited June 16, 2022 by stifler97 (see edit history) Link to comment Share on other sites More sharing options...
Nickz Posted April 16, 2022 Share Posted April 16, 2022 I don't think there is. You'll need a developer. Link to comment Share on other sites More sharing options...
Ali Samie Posted April 16, 2022 Author Share Posted April 16, 2022 There is also this module. But this one does not hide, it shows the product but it prevents from shoping that product Link to comment Share on other sites More sharing options...
idnovate.com Posted April 20, 2022 Share Posted April 20, 2022 This module do what you need: https://www.idnovate.com/en/1418-hide-or-show-products-by-stock-by-price-by-geoip.html Link to comment Share on other sites More sharing options...
Ali Samie Posted May 8, 2022 Author Share Posted May 8, 2022 On 4/20/2022 at 4:58 PM, idnovate.com said: This module do what you need: https://www.idnovate.com/en/1418-hide-or-show-products-by-stock-by-price-by-geoip.html Hi. I checked this module demo. This is not practical because our client has more than 40,000 products. And a lot of customers. But in this module there is only one box of products and customers without any search option. So we had to figure this out by our self. Thanks for your reply. Link to comment Share on other sites More sharing options...
Ali Samie Posted May 8, 2022 Author Share Posted May 8, 2022 On 5/3/2022 at 5:54 PM, Keshva thakur. said: i think you need this module https://www.modulesprestshop.com/home/disable-hide-products-per-countries.html This is not helpful because there is no demo to check if it suits my needs. Link to comment Share on other sites More sharing options...
Ali Samie Posted May 8, 2022 Author Share Posted May 8, 2022 On 4/17/2022 at 7:57 PM, ndiaga said: Hi, I can help customize that one to hide product. It should be a big issue since they did the most important part of the job. We needed some ideas. We had figured it out. I will upload module here. Link to comment Share on other sites More sharing options...
Ali Samie Posted May 8, 2022 Author Share Posted May 8, 2022 I and my teammate created one module which works with this hook: filterProductSearch And a function to translate ip address of visitor to country iso code which you can find on stackoverflow. This is the function <?php function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } ?> This is how we use it echo ip_info("Visitor", "Country Code"); // IN And thats it. There are some bugs in the module and we are going to add some new features. After all i will upload it here. Link to comment Share on other sites More sharing options...
Ali Samie Posted May 8, 2022 Author Share Posted May 8, 2022 3 minutes ago, ndiaga said: Witch module? Is it your own code or paid module's code? Don't share people's paid module codes here. It is not a paid module. It is a custom module which we developed. 1 Link to comment Share on other sites More sharing options...
El Patron Posted May 8, 2022 Share Posted May 8, 2022 We wrote a product by country a few years ago. It is very feature rich, contact me via our website at prestaheroes.com for more information. Link to comment Share on other sites More sharing options...
idnovate.com Posted May 10, 2022 Share Posted May 10, 2022 On 5/8/2022 at 6:28 PM, stifler97 said: Hi. I checked this module demo. This is not practical because our client has more than 40,000 products. And a lot of customers. But in this module there is only one box of products and customers without any search option. So we had to figure this out by our self. Thanks for your reply. There was a bug in some browsers 😅 It's fixed now: 1 Link to comment Share on other sites More sharing options...
idnovate.com Posted May 10, 2022 Share Posted May 10, 2022 On 5/8/2022 at 6:34 PM, stifler97 said: I and my teammate created one module which works with this hook: filterProductSearch And a function to translate ip address of visitor to country iso code which you can find on stackoverflow. This is the function <?php function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } ?> This is how we use it echo ip_info("Visitor", "Country Code"); // IN And thats it. There are some bugs in the module and we are going to add some new features. After all i will upload it here. The problem when using this hook is that all not the modules use it, so you will find these "hidden" products in some places. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now