2016-11-23 52 views
0

このLesti FpcでUnirgy_GeoIP拡張機能を使用しています。 問題は、FPCをオンにするとGeoIpが国旗をランダムに変更することです。 しかし、FPCが無効になっているとすべて正常に機能します。 これをどのように解決すればよいですか? Lesti Fpcを使って国コードを取得するにはどうすればよいですか?詳細はMagento Lest 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"/> 

ここに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

動的ブロックにブロック名を追加した後は、topのconfirm_country.phtmlにgeo ip codeを追加するだけです。

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に地理的IPコードを配置すると、毎回実行されます。

+0

私のために働いています!! – Keshar

関連する問題