<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/country-specific/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/country-specific/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Wed, 09 Nov 2011 11:53:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Magento Create a Customer Product Pop Up Message Based on Location / IP Address</title>
		<link>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/</link>
					<comments>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 09 Nov 2011 11:16:03 +0000</pubDate>
				<category><![CDATA[Country Specific]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Product Popup]]></category>
		<category><![CDATA[jquery]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=576</guid>

					<description><![CDATA[I had the requirement this week to provide a popup message to customers from a particular country viewing a particular product page in a Magento store. I initially thought of...<a class="more-link" href="https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="hang-2-column     alignnone" title="Magento Country Specific Product Popup" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup1.jpg" alt="Magento Country Specific Product Popup" width="247" height="186" />I had the requirement this week to provide a popup message to customers from a particular country viewing a particular product page in a Magento store.</p>
<p>I initially thought of detecting the browser language or using available PHP Geo IP tools. Detecting the browser language is a simple solution but does not necessarily mean the customer is physically in the country that the browser language is set to. I also thought that using a full blown Geo database would be overkill and too much of an overhead when performing lookups.</p>
<p>The simple solution was to match the customers IP address against the IP Allocation for the required country and create the Popup message when both product and IP Allocation match.</p>
<p>I used an <a href="http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/ " target="_blank">existing PHP function</a> capable of taking an array IP addresses in various formats and returning a true / false match against supplied address, and a simple Growl type jquery popup box function called <a href="http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/ " target="_blank">Gritter</a>..</p>
<p>First determine the IP addresses allocated to the country you want to target, you can obtain these from various websites e.g. <a href="http://www.ipaddresslocation.org/">http://www.ipaddresslocation.org</a></p>
<p>Download the PHP and Gritter jQuery files <a href="https://blog.gaiterjones.com/dev/extension.php?id=c4a40fd9c157a7ca9de7cc0852482ce1">here </a>and copy the Gritter folder to your magento /js folder.</p>
<p>Copy the php files to a suitable location on your system, they will be included from Magento. Open ip_allocation.php and paste in the range of addresses you want to use in the the array.</p>
<pre class="brush:php">&lt;?php

/*
 * ip__allocation.php
 *
 */

	$MyClient=FALSE;
	if (isset($_SERVER['REMOTE_ADDR']))
	{
		include 'ip_in_range.php';
		$clientIP=$_SERVER["REMOTE_ADDR"];
		$IPAllocation = array(
			'192.168.1.0-192.168.1.255',
			'192.168.2.0-192.168.2.255',
		);

			foreach ($IPAllocation as $addressRange) {

				if (ip_in_range($clientIP, $addressRange))
				{
					$MyClient=TRUE;
					break;
				}
			}
	}
?&gt;</pre>
<p>In the example our address ranges are 192.168.1.0-192.168.1.255 and 192.168.2.0-192.168.2.255. When you download the range of addresses from <a href="http://www.ipaddresslocation.org/">www.ipaddresslocation.org</a> you will have a list of perhaps hundreds of address ranges. Open them in Excel so that you can format them correctly for our PHP script. I.e. remove any unwanted spaces and add the quotes and comma so that you can just paste the addresses straight into the php array correctly formatted. i.e. <strong>&#8216;192.168.3.0-192.168.3.255&#8217;,</strong></p>
<p>Save the PHP file.</p>
<p>In Magento edit the head.phtml template file and add the following at the beginning of the file modifying the include path to point to the path and folder where you have save the files.</p>
<pre class="brush:applescript">// detect if client is from specific country based on IP and show popup on specific product page.
if (Mage::registry('current_product') &amp;&amp; Mage::registry('current_product')-&gt;getId() === "XXXX")
{
	include '/home/www/php/ip_allocation.php';
}
?&gt;</pre>
<p>This code will include our IP allocation PHP scripts if the current page is a product page and the product ID matches XXX, enter your product ID here for the product or products you want to match.</p>
<p>Further down in head.phtml we need to add the Gritter jQuery code. If you already are <a title="Automatic jQuery Translator for Magento" href="https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/">using jQuery in your Magento shop</a> this should come after the getIncludes statement and you should remove the javascript links to the google jQuery source.</p>
<pre class="brush:php">&lt;?php if (Mage::registry('current_product')) : ?&gt;
&lt;?php if(Mage::registry('current_product')-&gt;getId() === "XXX"):?&gt;
&lt;?php if($MyClient): ?&gt;
&lt;link rel="stylesheet" type="text/css" href="/js/gritter/css/jquery.gritter.css" /&gt;
&lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;google.load('jquery', '1.5');&lt;/script&gt;
&lt;script type="text/javascript" src="/js/gritter/js/jquery.gritter.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
jQuery(document).ready(function($){
	 $.gritter.add({
		// (string | mandatory) the heading of the notification
		title: '&lt;br /&gt;Are you a customer&lt;br /&gt;from the United Kingdom?&lt;br /&gt;',
		// (string | mandatory) the text inside the notification
		text: '&lt;br /&gt;&lt;br /&gt;You can save shipping costs and order our &lt;?php echo trim(Mage::registry('current_product')-&gt;getName())?&gt; directly from one of our partners, click &lt;a href="/partners?utm_source=Country&amp;utm_medium=Partners&amp;utm_campaign=MyCampaign"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt; for more information.&lt;br /&gt;&lt;br /&gt;',
		// (string | optional) the image to display on the left
		image: '/js/gritter/images/uk-flag.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: true
	 });}
 )
//]]&gt;
&lt;/script&gt;
&lt;?php endif ?&gt;
&lt;?php endif ?&gt;
&lt;?php endif ?&gt;</pre>
<p>Again we are checking for a match on a product page, and our specific product as well as a TRUE value for our IP address check returned by the variable $MyClient. When true, the Gritter jQeury code will be added to the page to create the popup box. You can see we are displaying a message for UK customers including a custom image.</p>
<p>Refresh your store cache and browse to the defined product page to test the code. You will need to add an entry for your current IP address in the allocation array to ensure a match if you are not in the country you are targeting!</p>
<figure id="attachment_584" aria-describedby="caption-attachment-584" style="width: 620px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" class="size-large wp-image-584" title="Magento Country Specific Product Popup" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-620x343.jpg" alt="Magento Country Specific Product Popup" width="620" height="343" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-620x343.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-440x243.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2.jpg 844w" sizes="(max-width: 620px) 100vw, 620px" /><figcaption id="caption-attachment-584" class="wp-caption-text">Magento Country Specific Product Popup</figcaption></figure>
<p>&nbsp;</p>
<p>The Gritter example code is linking to a relatively old version of jQuery, in a Magento 1.3 shop this was no problem, in 1.6.1 I had to use a newer version.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
	</channel>
</rss>
