wakabayashi Posted September 26, 2016 Share Posted September 26, 2016 (edited) Hello I have found a php Code, which works nicely, but I don't know how to make this to a module. I need a module, since in prestashop I can't use {php} tags. $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr()); $country = $xml->geoplugin_countryName ; if($country != "Switzerland") { $werbung=="yes"; } else { $werbung=="no"; } //For getting IP Address function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } This is my Code. Only thing I need, is to bring $werbung variable to smarty template. I would like to use this variable for example on cms page. I want to do this: {if $werbung =="yes"}Show something{/if} should be very easy or not? Would be very thankful if you could help me! Edited September 26, 2016 by wakabayashi (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted September 26, 2016 Share Posted September 26, 2016 where you want to use this: {if $werbung =="yes"}Show something{/if} ? everything depends on it Link to comment Share on other sites More sharing options...
wakabayashi Posted September 26, 2016 Author Share Posted September 26, 2016 Oh maybe I should say, what I want to achieve. Basically I have a blog, where I show Google Adsense. My customers are 99% from switzerland. I want to have a module, which only shows Adsense, if the visitor is NOT from switzerland. Actually best solution for me is, to have a own module, which adds a block to the right_column. This way I can use it in my blog and on cms pages. Thanks for your help! Link to comment Share on other sites More sharing options...
vekia Posted September 26, 2016 Share Posted September 26, 2016 it can be done without module, you can use FrontController modification / override , at the end (inside class) put this: public static function CheckGuestCountry($country_to_check) { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip); $country = $xml->geoplugin_countryName ; if($country != $country_to_check) { return false; } else { return true; } } then in your theme .tpl file you can use this: {if FrontController::CheckGuestCountry('Switzerland')} Customer from switzerland {else} Customer from somewhere else {/if} if you really need module for this, you can put the same function to the module, use public function hookRightColumn($params) to show .tpl file and then in .tpl file of the module that is called in hookRightColumn use this: {if ModuleName::CheckGuestCountry('Switzerland')} Customer from switzerland {else} Customer from somewhere else {/if} where ModuleName is the name of your module 1 Link to comment Share on other sites More sharing options...
wakabayashi Posted September 27, 2016 Author Share Posted September 27, 2016 Thanks Vekia! I did it without a module. It works like a charme! Link to comment Share on other sites More sharing options...
wakabayashi Posted September 27, 2016 Author Share Posted September 27, 2016 Yes you are right. But I couldn't manage to make the module, since I have no experience with it. Even after reading your tutorial it isn't clear to me... 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