简体   繁体   中英

Magento how to enable with GeoIP extension from Lest Fpc

I am using Unirgy_GeoIP extension with this Lesti Fpc. The problem is, when FPC is turned on GeoIp randomly changes country flags. However, everything works fine if FPC is disabled. How do I solve this? What i have to do for getting country code using Lesti Fpc?

Issue In Details:

I have set block in page.xml : Layout Code:

<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.

<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).

<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. 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

<?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.

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. So placing geo ip code in confirm_country.phtml will execute every time as this block added to dynamic blocks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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