C++ 通过Web服务在Magento中填充客户购物车(使用C+;+;)
我正在通过Soap使用Magento的Webservice API版本2。我已经使用gSoap为Soap调用生成了包装器/代理类,到目前为止,一切正常。我能C++ 通过Web服务在Magento中填充客户购物车(使用C+;+;),c++,web-services,magento,soap,C++,Web Services,Magento,Soap,我正在通过Soap使用Magento的Webservice API版本2。我已经使用gSoap为Soap调用生成了包装器/代理类,到目前为止,一切正常。我能 在商店中检索产品 按ID检索客户 是否登录/注销 我能够在我的桌面应用程序中获得我需要的所有信息 我现在想做的是:我的桌面应用程序中有一个购物网站,用户可以在其中选择产品(也就是说,将其添加到购物车),并通过单击按钮(例如“购买”)确认其选择。 单击此按钮,他将被重定向到浏览器中的网店,现在应该有(可能在验证后)他的购物车,其中包含他在
- 在商店中检索产品
- 按ID检索客户
- 是否登录/注销
void SoapManager::createShoppingCart()
{
ns1__shoppingCartCreateResponse shoppingCartCreation;
int x = m_pProxy->shoppingCartCreate(m_stLoginID, "1", shoppingCartCreation);
if(x!=0)
printFaultDetails(m_pProxy->fault);
m_currentShoppingCart = shoppingCartCreation;
}
void SoapManager::setCustomerToCart(ns1__shoppingCartCustomerEntity *customer)
{
ns1__shoppingCartCustomerSetResponse customerResponse;
int x = m_pProxy->shoppingCartCustomerSet(m_stLoginID, m_currentShoppingCart.quoteId, customer, "1", customerResponse);
if(x!=0 || !customerResponse.result)
printFaultDetails(m_pProxy->fault);
}
void SoapManager::addProductToCurrentCart(shoppingCartProductEntityArray *productsToAdd)
{
ns1__shoppingCartProductAddResponse productAdded;
int x = m_pProxy->shoppingCartProductAdd(m_stLoginID, m_currentShoppingCart.quoteId, productsToAdd, "1", productAdded);
if(x!=0 || !productAdded.result)
printFaultDetails(m_pProxy->fault);
}
将现有客户设置为创建的购物车:
void SoapManager::createShoppingCart()
{
ns1__shoppingCartCreateResponse shoppingCartCreation;
int x = m_pProxy->shoppingCartCreate(m_stLoginID, "1", shoppingCartCreation);
if(x!=0)
printFaultDetails(m_pProxy->fault);
m_currentShoppingCart = shoppingCartCreation;
}
void SoapManager::setCustomerToCart(ns1__shoppingCartCustomerEntity *customer)
{
ns1__shoppingCartCustomerSetResponse customerResponse;
int x = m_pProxy->shoppingCartCustomerSet(m_stLoginID, m_currentShoppingCart.quoteId, customer, "1", customerResponse);
if(x!=0 || !customerResponse.result)
printFaultDetails(m_pProxy->fault);
}
void SoapManager::addProductToCurrentCart(shoppingCartProductEntityArray *productsToAdd)
{
ns1__shoppingCartProductAddResponse productAdded;
int x = m_pProxy->shoppingCartProductAdd(m_stLoginID, m_currentShoppingCart.quoteId, productsToAdd, "1", productAdded);
if(x!=0 || !productAdded.result)
printFaultDetails(m_pProxy->fault);
}
向购物车添加简单(示例)产品:
void SoapManager::createShoppingCart()
{
ns1__shoppingCartCreateResponse shoppingCartCreation;
int x = m_pProxy->shoppingCartCreate(m_stLoginID, "1", shoppingCartCreation);
if(x!=0)
printFaultDetails(m_pProxy->fault);
m_currentShoppingCart = shoppingCartCreation;
}
void SoapManager::setCustomerToCart(ns1__shoppingCartCustomerEntity *customer)
{
ns1__shoppingCartCustomerSetResponse customerResponse;
int x = m_pProxy->shoppingCartCustomerSet(m_stLoginID, m_currentShoppingCart.quoteId, customer, "1", customerResponse);
if(x!=0 || !customerResponse.result)
printFaultDetails(m_pProxy->fault);
}
void SoapManager::addProductToCurrentCart(shoppingCartProductEntityArray *productsToAdd)
{
ns1__shoppingCartProductAddResponse productAdded;
int x = m_pProxy->shoppingCartProductAdd(m_stLoginID, m_currentShoppingCart.quoteId, productsToAdd, "1", productAdded);
if(x!=0 || !productAdded.result)
printFaultDetails(m_pProxy->fault);
}
一般来说,仅此而已。我所期望的是,产品被附加到客户的购物车上,购物车被设置为购物车。
但是在重定向到Webshop后,购物车中没有产品,管理面板中也没有购物车
当我使用quote ID以编程方式检索购物车时,其中包含所有添加的产品,因此我认为,这可能是我的理解错误
有什么建议吗,我做错了什么
或者只有使用查询字符串才能将产品添加到(webshop-)购物车中?(如果是:如何添加多个产品?)
最好的问候和感谢提前
Jan我尝试做同样的事情(ios+SOAPV1),我认为现在不可能这样做,但解决方案是更改mageto core中的日志方法以“捕获”用户名和密码(通过GET或POST)并自动调用日志函数,然后您将拥有cart raedy
你不是唯一一个这样做的人,但是如果你已经这样做了,请告诉我怎么做?我正在尝试做同样的事情(ios+soap V1),我认为现在还不可能这样做,但解决方案是更改mageto core中的日志方法,以“捕获”用户名和密码(通过GET或POST),并自动调用日志函数,那你就有马车了
你并不是唯一一个这样做的人,但如果你已经这样做了,请告诉我是怎么做的?这已经是很久以前的事了,但我想我最终还是用了一半的知识和尝试的错误来做的;o) 除此之外,我不打算采用此解决方案,而是将magento完全集成到我的桌面应用程序中,而无需将用户重定向到浏览器 但回到第二个话题: 关于magento核心代码有一些问题,这显然有点问题,至少在使用webservice api时是这样 首先,为用户创建新购物车时,此购物车未标记为活动。 在“app/code/core/checkout/model/cart/Api.php”中,您有以下代码片段,它显然创建了一个新的购物车:
public function create($store = null)
{
$storeId = $this->_getStoreId($store);
try {
/*@var $quote Mage_Sales_Model_Quote*/
$quote = Mage::getModel('sales/quote');
//Changed is active to true in order to activate the cart when created
/*$quote->setStoreId($storeId)
->setIsActive(false)
->setIsMultiShipping(false)
->save();*/
$quote->setStoreId($storeId)
->setIsActive(true)
->setIsMultiShipping(false)
->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('create_quote_fault', $e->getMessage());
}
return (int) $quote->getId();
}
注释后的代码是原始代码,这会在默认情况下将shoppingcart设置为false,这会导致(对我来说)我无法使用它。这是对我有效的解决方案的一部分。
第二部分是关于扩展magento webservice api的自定义webservice模块:
public function getSession($customerID)
{
require_once("app/Mage.php");
Mage::app ();
umask(0);
$webSites = Mage::app()->getWebsites();
$code = $webSites[1]->getCode();
$session = Mage::getSingleton("customer/session"); // This initiates the PHP session
// The following line is the trick here. You simulate that you
// entered Magento through a website (instead of the API) so if you log in your user
// his info will be stored in the customer_your_website scope
$session->init('customer_' . $code);
$bool = $session->loginById($customerID); // Just logging in some example user
return session_id(); // this holds your session id
}
上面的代码片段模拟了通过magento网站上的正常登录过程输入的内容。在这里,我使用我的shoppage($webSites[1]->getCode();)的主网站代码/标识符初始化一个会话,并使用customerID登录用户。
之后,我将sessionId返回到我的桌面应用程序。当用户现在想要购买他选择的东西时(以与我在问题中提到的相同的方式添加),他单击一个按钮,并被重定向到浏览器的一个小php脚本,如下所示:
<?php
// Make sure you match the cookie path magento is setting
setcookie('frontend', $_GET['session'], 0, '/');
//echo $_GET['session'];
header('Location: http://yourdomain.com/magento/checkout/cart');
?>
“+sessionId”表示我从Web服务收到的会话ID。我在这里所做的就是为用户设置cookie并将其重定向到他的购物车,仅此而已。用户应该登录并查看他选择的产品。
重要的一点是,您必须将正确的目录设置为magento存储其cookies的位置(“/”)
事实上,我想给你一些非常有用的网站的链接,这些链接可以帮助我度过这个烦人的过程,但是stackoverflow不允许超过2个超链接,不幸的是,我的代码中只有上面2个。。对不起
我希望我能帮你一点忙。如果您有更多问题,请与我联系或写信给我,也许我可以帮助您:o)
致以最良好的祝愿,
Jan这是一段时间以前的事了,但我想我最终还是用了一半的知识和尝试错误的混合方法做到了这一点;o) 除此之外,我不打算采用此解决方案,而是将magento完全集成到我的桌面应用程序中,而无需将用户重定向到浏览器 但回到第二个话题: 关于magento核心代码有一些问题,这显然有点问题,至少在使用webservice api时是这样 首先,为用户创建新购物车时,此购物车未标记为活动。 在“app/code/core/checkout/model/cart/Api.php”中,您有以下代码片段,它显然创建了一个新的购物车:
public function create($store = null)
{
$storeId = $this->_getStoreId($store);
try {
/*@var $quote Mage_Sales_Model_Quote*/
$quote = Mage::getModel('sales/quote');
//Changed is active to true in order to activate the cart when created
/*$quote->setStoreId($storeId)
->setIsActive(false)
->setIsMultiShipping(false)
->save();*/
$quote->setStoreId($storeId)
->setIsActive(true)
->setIsMultiShipping(false)
->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('create_quote_fault', $e->getMessage());
}
return (int) $quote->getId();
}
注释后的代码是原始代码,这会在默认情况下将shoppingcart设置为false,这会导致(对我来说)我无法使用它。这是对我有效的解决方案的一部分。
第二部分是关于扩展magento webservice api的自定义webservice模块:
public function getSession($customerID)
{
require_once("app/Mage.php");
Mage::app ();
umask(0);
$webSites = Mage::app()->getWebsites();
$code = $webSites[1]->getCode();
$session = Mage::getSingleton("customer/session"); // This initiates the PHP session
// The following line is the trick here. You simulate that you
// entered Magento through a website (instead of the API) so if you log in your user
// his info will be stored in the customer_your_website scope
$session->init('customer_' . $code);
$bool = $session->loginById($customerID); // Just logging in some example user
return session_id(); // this holds your session id
}
上面的代码片段模拟了通过magento网站上的正常登录过程输入的内容。在这里,我使用我的shoppage($webSites[1]->getCode();)的主网站代码/标识符初始化一个会话,并记录