繁体   English   中英

Magento如何从Lest Fpc启用GeoIP扩展

[英]Magento how to enable with GeoIP extension from Lest 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>

我已将国​​家或地区代码的块名称“ 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的代码。 在此页面上,我没有国家代码

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

有了这个代码,我将随机获得国家代码。 有时代码无法获取。
请帮忙。
将不胜感激。
希望能受到青睐。

将块名称添加到动态块后,只需在顶部的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>

原因是您的header.phtml中的代码一旦被缓存在FPC中就不会执行。 因此,每次将此代码块添加到动态代码块时,都将执行将geo ip代码放入confirm_country.phtml中。

暂无
暂无

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

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