Hallo Zusammen
ich versuche gerade für unseren Shop ein GeoIP Plugin zu basteln, leider bis jetzt nicht so erfolgreich.
Ziel des Plugins: Erkennung der Herkunft (Land), Wenn Land = CH dann soll eine Modalbox erscheinen mit der Empfehlung auf den Schweizer Shop zu wechseln.
Leider funktioniert das ganze aktuell nicht, daher poste ich mal meinen Code, vlt. kann mir jemand von euch weiterhelfen und mir sagen wo ich den/die Fehler hab. Danke im Voraus.
Bootstrap.php:
View()->setTemplate(); // Disable output
define("_auth",true);
include(dirname( __PATH__ )."/geoip.inc");
// GeoIP Abfrage
$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);
$countrycode = geoip_country_code_by_addr($gi, $ipAddress);
geoip_close($gi);
}
}
$ipAddress = $_SERVER['REMOTE_ADDR'];
$cookie = $_GET["cookie"];
if ($cookie == "0") {
setcookie("country", $cookie, time()-3600);
header ("Location: http://".$_SERVER["SERVER_NAME"]);
exit;
}
if ($cookie == "1") {
setcookie("country", $cookie, time()+3600);
header ("Location:http://".$_SERVER["SERVER_NAME"]);
exit;
}
class Shopware_Plugins_Frontend_wfcountry_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
public function install()
{
$this->subscribeEvent(
'Enlight_Controller_Action_PostDispatchSecure_Frontend',
'onFrontendPostDispatch'
);
$this->createConfig();
return true;
}
private function createConfig()
{ }
public function getVersion()
{
return '1.0.0';
}
public function getLabel()
{
return 'GeoIP Country Modalbox';
}
/**
* Return some information about this plugin.
*
* @return array
*/
public function getInfo()
{
return array(
'label' => $this->getLabel(),
'description' => $this->getLabel(),
'source' => 'Local',
'support' => 'info@domain.ch',
'link' => 'http://www.domain.ch/',
'autor' => 'Company GmbH',
'license' => 'proprietary',
'copyright' => 'Copyright ' . date('Y') . ', Company GmbH',
'version' => $this->getVersion()
);
}
public function onFrontendPostDispatch(Enlight_Event_EventArgs $args)
{
/** @var \Enlight_Controller_Action $controller */
$controller = $args->get('subject');
$view = $controller->View();
$view->addTemplateDir(
__DIR__. '/Views'
);
if (isset($_COOKIE['country'])) { }
else {
if ($countrycode == "CH") {
$view->wfcountry = "yes";
$view->wfdomain = $_SERVER["SERVER_NAME"];
}
}
}
}
header.tpl
{extends file="parent:frontend/index/header.tpl"}
{block name='frontend_index_header_javascript' append}
{if $wfcountry == "yes"}
{literal}
var modal = (function(){
var
method = {},
$overlay,
$modal,
$content,
$close;
// Zentrieren der MODAL BOX
method.center = function () {
var top, left;
top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
$modal.css({
top:top + $(window).scrollTop(),
left:left + $(window).scrollLeft()
});
};
// Open MODAL BOX
method.open = function (settings) {
$content.empty().append(settings.content);
$modal.css({
width: settings.width || 'auto',
height: settings.height || 'auto'
});
method.center();
$(window).bind('resize.modal', method.center);
$modal.show();
$overlay.show();
};
// Close MODAL BOX
method.close = function () {
$modal.hide();
$overlay.hide();
$content.empty();
$(window).unbind('resize.modal');
};
// Generiert HTML
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="//{$wfdomain}/index.php?cookie=1">close</a>');
$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function(){
$('body').append($overlay, $modal);
});
$close.click(function(e){
e.preventDefault();
method.close();
});
return method;
}());
// Warten bis Seite geladen wurde
$(document).ready(function(){
$.get('../../../../switzerland.html', function(data){
modal.open({content: data});
});
});
{/literal}
{/if}
{/block}
{block name="frontend_index_header_css_screen"}
{/block}