2011-12-13 10 views
1

Magento 1.5では、地域APIを呼び出しています。それは私の開発環境で正常に動作し、これを返します。Magento:地域API名= null

[{"region_id":"66","code":"AB","name":"Alberta"}, 
{"region_id":"67","code":"BC","name":"British Columbia"}, 
{"region_id":"68","code":"MB","name":"Manitoba"}, 
{"region_id":"69","code":"NL","name":"Newfoundland and Labrador"}, 
{"region_id":"70","code":"NB","name":"New Brunswick"}, 
{"region_id":"71","code":"NS","name":"Nova Scotia"}, 
{"region_id":"72","code":"NT","name":"Northwest Territories"}, 
{"region_id":"73","code":"NU","name":"Nunavut"}, 
{"region_id":"74","code":"ON","name":"Ontario"}, 
{"region_id":"75","code":"PE","name":"Prince Edward Island"}, 
{"region_id":"76","code":"QC","name":"Quebec"}, 
{"region_id":"77","code":"SK","name":"Saskatchewan"}, 
{"region_id":"78","code":"YT","name":"Yukon Territory"}] 

次に、このAPIは、私のステージング環境で呼び出されたとき、結果はすべての焦がす名を除いて同じであるidと、コードが良好な場合でも、nullです:

[{"region_id":"66","code":"AB","name":null}, 
{"region_id":"67","code":"BC","name":null}, 
{"region_id":"68","code":"MB","name":null}, 
{"region_id":"69","code":"NL","name":null}, 
{"region_id":"70","code":"NB","name":null}, 
{"region_id":"71","code":"NS","name":null}, 
{"region_id":"72","code":"NT","name":null}, 
{"region_id":"73","code":"NU","name":null}, 
{"region_id":"74","code":"ON","name":null}, 
{"region_id":"75","code":"PE","name":null}, 
{"region_id":"76","code":"QC","name":null}, 
{"region_id":"77","code":"SK","name":null}, 
{"region_id":"78","code":"YT","name":null}] 

何が原因でしょうか?

答えて

5

まだ解決策が見つかった場合はわかりませんが、同じ問題がありました。これは、magentoのコアコードのバグ(region-apiの詳細)のようです。明らかにバグが それでもここに... 3年以上まで存在している、私はそれを解決するために見つけたものです:Mage_Directory_Model_Region_Apiへ

ゴー(Magentoの1.6.2には、このファイルはアプリ/コード/コア/メイジに位置しています/Directory/Model/Region/Api.php)とは、以下の次の行を変更します。私は、コアコードを変更しないことをお勧めします

class Mage_Directory_Model_Region_Api extends Mage_Api_Model_Resource_Abstract 
{ 
    /** 
    * Retrieve regions list 
    * 
    * @param string $country 
    * @return array 
    */ 
    public function items($country) 
    { 
     try { 
      $country = Mage::getModel(’directory/country’)->loadByCode($country); 
     } catch (Mage_Core_Exception $e) { 
      $this->_fault(’country_not_exists’, $e->getMessage()); 
     } 

     if (!$country->getId()) { 
      $this->_fault(’country_not_exists’); 
     } 

     $result = array(); 
     foreach ($country->getRegions() as $region) { 
      $region->setName($region->getName()); // This is the important line to set the name 
      $result[] = $region->toArray(array(’region_id’, ‘code’, ‘name’)); 
     } 

     return $result; 
    } 
} 
1

を!修正は機能しますが、ファイルを書き直すか、少なくともローカルにコピーする方がよいでしょう。

のconfig.xmlにリライトを追加します。Module_Namespace_Model_Region_Api_Apiに

<config> 
    <modules> 
     <Module_Namespace> 
      <version>0.1.0</version> 
     </Module_Namespace> 
    </modules> 
    <global> 
     <models> 
      <directory> 
       <rewrite> 
        <region_api>Module_Namespace_Model_Region_Api_Api</region_api> 
       </rewrite> 
      </directory> 
     </models> 
    </global> 
</config> 

コピーMage_Directory_Model_Region_Apiとライン56に修正プログラムを適用:

class Module_Namespace_Model_Region_Api_Api extends Mage_Api_Model_Resource_Abstract 
{ 
    /** 
    * Retrieve regions list 
    * 
    * @param string $country 
    * @return array 
    */ 
    public function items($country) 
    { 
     try { 
      $country = Mage::getModel('directory/country')->loadByCode($country); 
     } catch (Mage_Core_Exception $e) { 
      $this->_fault('country_not_exists', $e->getMessage()); 
     } 

     if (!$country->getId()) { 
      $this->_fault('country_not_exists'); 
     } 

     $result = array(); 
     foreach ($country->getRegions() as $region) { 
      $region->setName($region->getName()); //Fix 
      $result[] = $region->toArray(array('region_id', 'code', 'name')); 
     } 

     return $result; 
    } 
} 
+0

はい、私は認める、それは代わりに、コアコードを拡張するために、常に良いでしょうそれを直接変更する - 特にMagentoバージョンを更新する場合ありがとう! –