2016-01-23 114 views
1

我已經配置了Magento SOAP API以將其與我的Android應用程序連接,客戶可以從Android應用程序登錄到magento。我面臨的問題是當我發送請求時,它顯示錯誤 - 「會話過期」。Magento SOAP登錄錯誤

這是我的API.php文件

<?php 

// app/code/local/Anaqa/Customapimodule/Model/Login/Api.php 
class Anaqa_Customapimodule_Model_Customerlogin_Api extends Mage_Api_Model_Resource_Abstract { 

    public function customerEntry($email) {   
     #Mage::app()->setCurrentStore($website); 
     #  // Init a Magento session. This is super ultra important 
     #Mage::getSingleton('core/session'); 

     // $customer Mage_Customer_Model_Customer 
     // We get an instance of the customer model for the actual website 
     $customer = Mage::getModel('customer/customer') 
       ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 

     // Load the client with the appropriate email 
     $customer->loadByEmail($email); 
     return $customer; 
    } 
     /* 
     ini_set("soap.wsdl_cache_enabled", "0"); 
     $client = new SoapClient('http://magentohost/api/soap/?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE)); 
     $session = $client->login('apiUser', 'apiKey'); 
     $result = $client->call($session, 'product.list'); 
     $client->endSession($session); 


     Mage::app()->setCurrentStore($website); 
     // Init a Magento session. This is super ultra important 
     Mage::getSingleton('core/session'); 

     // $customer Mage_Customer_Model_Customer 
     // We get an instance of the customer model for the actual website 
     $customer = Mage::getModel('customer/customer') 
       ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 

     // Load the client with the appropriate email 
     $customer->loadByEmail($email); 

     // Get a customer session 
     $session = Mage::getSingleton('customer/session'); 

     $session->loginById($customer->getId()); 
     if ($session->isLoggedIn()) { 
      return $session->getSessionId(); 
     } else { 
      return null; 
     } 
    } */ 

} 

回答

0

我會用客戶/會話模型來訪問客戶。

$sessionCustomer = Mage::getSingleton('customer/session'); 
     if($sessionCustomer->isLoggedIn()) { 
      $customer = Mage::getSingleton('customer/session')->getCustomer(); 

的皺紋這裏是爲了讓Magento的訪問它需要知道客戶登錄會話數據,否則你將無法與會話數據返回客戶數據。