2016-11-23 56 views
0

我正在使用此Lesti Fpc的Unirgy_GeoIP擴展。 問題是,當FPC打開時,GeoIp會隨機更改國家/地區標誌。 但是,如果FPC被禁用,一切正常。 我該如何解決這個問題? 爲了使用Lesti Fpc獲取國家/地區代碼,我需要做些什麼?Magento如何使用來自Lect Fpc的GeoIP擴展啓用

問題具體爲:在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"/> 

here code of 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"/>&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擴展設置國家代碼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); 
    } 
?> 

有了這個代碼,我很隨機獲得國家代碼。有時代碼沒有得到。
請幫忙。
將不勝感激任何幫助。
希望受到青睞。

回答

1

將塊名稱添加到動態塊後,您只需在您的confirm_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中緩存。因此,在將此塊添加到動態塊時,將每次都將執行將confirm_country.phtml中的geo ip代碼。

+0

它爲我工作。 – Keshar