I am new to Magento Web-Service and should extend it. The Webservice shell can log in with the client, give me a session cookie so that I can redirect the cookie that sets the cookie again, redirect me, and I can see my cart and proceed to checkout in the Magento store.
Problem: Magento creates a cookie (which contains a session ID or something else, ive tried to set this guide for cookies and logging in) instead of setting up a session when a user logs in. I tried for several hours now to get this cookie set by magento on my magento web service. Cookie does not seem to be set when I call
$session = Mage::getSingleton('customer/session'); return $session->getCookie()->get('frontend');
Here is my complete code: Magento Webservice Api:
<?php class Customapi_Model_Core_Api { public function __construct() { } public function checkout($user, $cart) { $ret['cookie'] = $this->login($user); //$coreCookie = Mage::getSingleton('core/cookie'); //$ret['cookie'] = $_COOKIE['frontend']; return $ret; } function login($user) { Mage::getSingleton('core/session', array('name'=>'frontend')); $session = Mage::getSingleton('customer/session'); try { $session->loginById($user['id']); } catch (Exception $e) { } return $session->getCookie()->get('frontend'); } } ?>
Heres my Api Call in Php:
<?php $teambook_path = 'http://localhost/magento/'; $soap = new SoapClient('http://localhost/magento/api/?wsdl'); $soap->startSession(); $sessionId = $soap->login('ApiUser', 'ApiKey'); $userSession = $soap->call( $sessionId, 'customapi.checkout', array( array( 'id' => 1, 'username' => ' Ruf_Michael@gmx.de ', 'password' => '***' ), array( ) ) ); echo '<pre>'; var_dump($userSession)."\n"; if(isset($userSession['sid'])) echo '<a href="'.$teambook_path.'session.php?sid='.$userSession['sid'].'" target="_blank">'.$userSession['sid'].'</a>'."\n"; echo '</pre>'; $soap->endSession($sessionId); ?>
Thanks for the help! CPM
Sorry to write the answer, but the comment box has forbidden me to write more than ... letters.
I tried both the codes you sent, and all I get is an empty array or a Bool false. I wrote a static function:
private static $cookie = array(); public static function cookie($key, $value) { if($key == 'frontend') { self::$cookie['key'] = $key; self::$cookie['value'] = $value; } }
which is called in Mage_Core_Model_Session_Abstract_Varien :: start, and I got a cookie value for frontend:
Customapi_Model_Core_Api::cookie($sessionName, $this->getSessionId());
on line 125.
But this did not solve my main problem: The session created in the Api call cannot be restored, although it is set to the correct value.
Thank you for your help!