我尝试在Magento(1.5.1.0)的后端创建一个订单.
这是一些代码:
// Get the product id stored in the optionValue of the widget
$productId = $order['customIdNumber'];
// Load the product
$product = Mage::getModel('catalog/product')->load($productId);
// Check whether the product could be loaded
if($product->getId())
{
// Get the customer model
$customer = Mage::getModel('customer/customer');
// Set the website id associated with the customer
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
// Try to load the customer by email
$customer->loadByEmail($order['personAddresses'][0]['email']);
// Check whether the customer not exists
if(!$customer->getId())
{
// Create the customer
$customer->setEmail($order['personAddresses'][0]['email']);
$customer->setFirstname($order['personAddresses'][0]['firstName']);
$customer->setLastname($order['personAddresses'][0]['lastName']);
$customer->save();
}
// …Run Code Online (Sandbox Code Playgroud) 我是Magento Web-Service的新手,必须扩展它.Webservice shell能够登录客户,给我回复会话cookie,以便我可以重定向到再次设置cookie的文件,重定向我,我可以看到我的购物车并继续在Magento商店结账.
问题:Magento创建了一个cookie(包含会话ID或其他任何东西,我试图设置这个cookie手册并且他们已登录),而不是在客户登录时设置会话.我已经尝试了几个小时才能获得这个cookie由magento在我的magento web服务中设置.我打电话时似乎没有设置cookie
$session = Mage::getSingleton('customer/session');
return $session->getCookie()->get('frontend');
Run Code Online (Sandbox Code Playgroud)
继承人我的完整代码: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');
}
}
?>
Run Code Online (Sandbox Code Playgroud)
继承人在Php中的Api电话:
<?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', …Run Code Online (Sandbox Code Playgroud)