我正在使用这个Lesti Fpc的Unirgy_GeoIP扩展。 问题是,当FPC打开时,GeoIp会随机更改国家标志。 但是,如果禁用FPC,一切正常。 我该如何解决这个问题? 使用Lesti Fpc获取国家/地区代码需要做些什么?
问题详情:
我在page.xml中设置了块: 布局代码:
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="core/template" name="confirmCountry" as="confirmCountry" template="page/html/confirm_country.phtml"/>
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
<block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
</block>
</block>
<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
<label>Page Header</label>
<action method="setElementClass"><value>top-container</value></action
</block>
<block type="page/html_welcome" name="welcome" as="welcome"/>
</block>
我已将国家/地区代码的块名“confirmCountry”放入动态或惰性块中。
<block type="core/template" name="confirmCountry" as="confirmCountry" template="page/html/confirm_country.phtml"/>
当我将块名称放在动态或惰性块中时,我没有得到国家/地区代码。 从此代码图像只有图像路径.gif(.gif)。
<img src="<?php echo $this->getSkinUrl(); ?>images/flags/<?php echo strtolower($countryCode); ?>.gif" alt="<?php echo $countryName;?>" width="31" height="22"/>
这里是confirm_country.phtml的代码。在这个页面上我没有得到countryCode
<?php
$countryCode = Mage::getSingleton('core/session')->getCountryCode();
//$countryName = Mage::app()->getLocale()->getCountryTranslation($countryCode);
if($countryCode){
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
$countryName = $country->getIso3Code();
}
?>
<div class="language">
<a id="confrm_country" href="#confrm_country_container"><?php echo $countryName;?><img src="<?php echo $this->getSkinUrl(); ?>images/flags/<?php echo strtolower($countryCode); ?>.gif" alt="<?php echo $countryName;?>" width="31" height="22"/> </a>
<div class="arrowwrap"><span></span></div>
<div class="languagebox">
<div class="formlist">
<h2><?php echo $this->__('Confirm Your Location') ?></h2>
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false); ?>
<?php if (count($_countries) > 0): ?>
<form id="form_confrm_country" action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
<div class="arrowstyle">
<select name="country" id="top-country">
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>" <?php if($countryCode==$_country['value']):?> selected<?php endif;?>>
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
</div>
</form>
<a href="#" onclick="document.getElementById('form_confrm_country').submit();"><?php echo $this->__('Confirm'); ?></a>
<?php endif; ?>
</div>
</div>
</div>
模板代码:(header.phtml)在header.phtml中使用Unirgy_GeoIP Extension设置国家/地区代码
<?php
if (!Mage::getSingleton('core/session')->getCountryCode()) {
Mage::helper('ugeoip')->getGeoInstance('GeoIP');
$geoIp = Mage::helper('ugeoip')->getGeoLocation(true);
$geoCountryCode = $geoIp->getData('countryCode');
$geoContinentCode = $geoIp->getData('countryContinent');
Mage::getSingleton('core/session')->setCountryCode($geoCountryCode);
Mage::getSingleton('core/session')->setContinentCode($geoContinentCode);
}
?>
使用此代码,我随机获得国家/地区代码。有时代码没有得到。
请帮忙。
将不胜感激任何帮助
希望受到青睐。
答案 0 :(得分:1)
将块名称添加到动态块后,您只需在顶部的confirm_country.phtml中添加地理IP代码。
if (!Mage::getSingleton('core/session')->getCountryCode()) {
Mage::helper('ugeoip')->getGeoInstance('GeoIP');
$geoIp = Mage::helper('ugeoip')->getGeoLocation(true);
$geoCountryCode = $geoIp->getData('countryCode');
$geoContinentCode = $geoIp->getData('countryContinent');
Mage::getSingleton('core/session')->setCountryCode($geoCountryCode);
Mage::getSingleton('core/session')->setContinentCode($geoContinentCode);
}
<?php
$countryCode = Mage::getSingleton('core/session')->getCountryCode();
//$countryName = Mage::app()->getLocale()->getCountryTranslation($countryCode);
if($countryCode){
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
$countryName = $country->getIso3Code();
}
?>
<div class="language">
<a id="confrm_country" href="#confrm_country_container"><?php echo $countryName;?><img src="<?php echo $this->getSkinUrl(); ?>images/flags/<?php echo strtolower($countryCode); ?>.gif" alt="<?php echo $countryName;?>" width="31" height="22"/> </a>
<div class="arrowwrap"><span></span></div>
<div class="languagebox">
<div class="formlist">
<h2><?php echo $this->__('Confirm Your Location') ?></h2>
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false); ?>
<?php if (count($_countries) > 0): ?>
<form id="form_confrm_country" action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
<div class="arrowstyle">
<select name="country" id="top-country">
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>" <?php if($countryCode==$_country['value']):?> selected<?php endif;?>>
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
</div>
</form>
<a href="#" onclick="document.getElementById('form_confrm_country').submit();"><?php echo $this->__('Confirm'); ?></a>
<?php endif; ?>
</div>
</div>
</div>
原因是header.phtml中的代码一旦在FPC中缓存就不会执行。因此,每次将此块添加到动态块时,都会在confirm_country.phtml中放置geo ip代码。