Magento SOAP登录错误

时间:2016-01-23 17:27:29

标签: magento soap

我已经配置Magento SOAP api将它连接到我的Android应用程序,客户可以从Android应用程序登录到magento。我面临的问题是,当我发送请求时,它显示错误 - “会话已过期”。

这是我的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;
        } 
    } */

}

1 个答案:

答案 0 :(得分:0)

我会使用客户/会话模型来访问客户。

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

这里的皱纹是为了让magento访问需要知道客户登录的会话数据,否则您将无法使用会话数据返回客户数据。