簡體   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