简体   繁体   English

Magento如何从Lest Fpc启用GeoIP扩展

[英]Magento how to enable with GeoIP extension from Lest Fpc

I am using Unirgy_GeoIP extension with this Lesti Fpc. 我正在将此Lesti Fpc使用Unirgy_GeoIP扩展。 The problem is, when FPC is turned on GeoIp randomly changes country flags. 问题是,打开FPC时,GeoIp会随机更改国家/地区标志。 However, everything works fine if FPC is disabled. 但是,如果禁用了FPC,一切正常。 How do I solve this? 我该如何解决? What i have to do for getting country code using Lesti Fpc? 我要使用Lesti Fpc获取国家/地区代码需要做什么?

Issue In Details: 详细问题:

I have set block in page.xml : Layout Code: 我在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>

I have put block-name "confirmCountry" of country code in dynamic or lazy block. 我已将国​​家或地区代码的块名称“ confirmCountry”放入动态或惰性块中。

<block type="core/template" name="confirmCountry" as="confirmCountry" template="page/html/confirm_country.phtml"/>

when i put block name in dynamic or lazy block, i am not getting country code. 当我将块名称放入动态或惰性块时,我没有得到国家代码。 from this code image is blank only with image path .gif (.gif). 此代码中的图像仅在图像路径为.gif(.gif)时为空白。

<img src="<?php echo $this->getSkinUrl(); ?>images/flags/<?php echo strtolower($countryCode); ?>.gif" alt="<?php echo $countryName;?>" width="31" height="22"/>

here code of confirm_country.phtml. 这是Confirm_country.phtml的代码。 On this page i am not getting 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>

template code: (header.phtml) Using Unirgy_GeoIP Extension set country code in header.phtml 模板代码:(header.phtml)使用Unirgy_GeoIP Extension在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);
   }
?>

With this code i am getting randomly country code. 有了这个代码,我将随机获得国家代码。 Sometime code not getting. 有时代码无法获取。
Please help. 请帮忙。
Will appreciate any help. 将不胜感激。
Hoping to be favoured. 希望能受到青睐。

After adding block name to dynamic blocks you just have to add geo ip code in your confirm_country.phtml at top. 将块名称添加到动态块后,只需在顶部的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"/>&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>

The reason is your code in header.phtml not executing once get cached in FPC. 原因是您的header.phtml中的代码一旦被缓存在FPC中就不会执行。 So placing geo ip code in confirm_country.phtml will execute every time as this block added to dynamic blocks. 因此,每次将此代码块添加到动态代码块时,都将执行将geo ip代码放入confirm_country.phtml中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM