Magento如何使用GeoIP扩展从FPC启用



我正在使用此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>

我在动态或懒惰的块中放置了国家代码的"确认"。

<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"/>

这里的代码excield_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"/>&nbsp;</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)使用unirgy_geoip扩展设置国家代码in header.phtml

<?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);
   }
?>

使用此代码,我将获得随机的国家代码。有时代码不会得到。
请帮助。
会感谢任何帮助。
希望受到青睐。

在动态块中添加块名称后,您只需要在post的corject_country.phtml中添加geo 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"/>&nbsp;</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中被缓存。因此,将GEO IP代码放在enckern_country.phtml中,随着该块添加到动态块中,每次都将执行。

最新更新