Jus*_*tin 7 api xml-rpc magento
我正在尝试使用Magento Enterprise 1.10 XML-RPC API来处理Magento安装之外的购物车/目录功能.我遇到的问题是当我加入购物车时.我可以很好地连接到API端点,登录和检索数据.以下是我用来发现Magento API工作原理的代码.
<?php
require $_SERVER['DOCUMENT_ROOT'].'/Zend/XmlRpc/Client.php';
$url = 'http://mymagento.com/api/xmlrpc';
$user = 'apiuser';
$pass = 'apipass';
$proxy = new Zend_XmlRpc_Client( $url );
$sess = $proxy->call( 'login', array( $user, $pass ) );
$cartId = $proxy->call( 'call', array( $sess, 'cart.create', array( 1 ) ) );
$pList = $proxy->call( 'call', array( $sess, 'product.list', array() ) );
$cList = $proxy->call( 'call', array( $sess, 'customer.list', array() ) );
$cList[0]['mode'] = 'customer';
$setCart = $proxy->call( 'call', array( $sess,
'cart_customer.set',
array( $cartId, $cList[0] ) ) );
foreach( $pList as $prod)
{
if( $prod['product_id'] == 5 )
{
$prod['qty'] = 5;
$addCart = $proxy->call( 'call', array( $sess,
'cart_product.add',
array( $cartId, $pAdd ) ) );
}
}
$cList = $proxy->call( 'call', array( $sess, 'cart.info', array( $cartId ) ) );
print_r( $cList );
Run Code Online (Sandbox Code Playgroud)
输出:
[store_id] => 1
[created_at] => 2011-05-27 13:30:57
[updated_at] => 2011-05-27 13:31:00
[converted_at] => 0000-00-00 00:00:00
[is_active] => 0
[is_virtual] => 0
[is_multi_shipping] => 0
[items_count] => 1
[items_qty] => 5.0000
[orig_order_id] => 0
[store_to_base_rate] => 1.0000
[store_to_quote_rate] => 1.0000
[base_currency_code] => USD
[store_currency_code] => USD
[quote_currency_code] => USD
[grand_total] => 0.0000
[base_grand_total] => 0.0000
[checkout_method] => customer
...
[items] => Array
(
[0] => Array
(
[item_id] => 93
[quote_id] => 119
[created_at] => 2011-05-27 13:31:00
[updated_at] => 2011-05-27 13:31:00
[product_id] => 5
[store_id] => 1
[parent_item_id] =>
[is_virtual] => 1
[sku] => product1
[name] => product
[description] =>
[applied_rule_ids] =>
[additional_data] =>
[free_shipping] => 0
[is_qty_decimal] => 0
[no_discount] => 0
[weight] =>
[qty] => 5
[price] => 0.0000
[base_price] => 0.0000
[custom_price] =>
[discount_percent] => 0.0000
[discount_amount] => 0.0000
[base_discount_amount] => 0.0000
Run Code Online (Sandbox Code Playgroud)
但是,我只是使用相同的上述会话调用以下内容
<?php
$pInfo = $proxy->call( 'call', array( $sess, 'catalog_product.info', '5' ) );
print_r( $pInfo );
Run Code Online (Sandbox Code Playgroud)
我收到有关该产品的以下信息:
[product_id] => 5
[sku] => product1
[set] => 9
[type] => virtual
[categories] => Array
(
)
[websites] => Array
(
[0] => 1
)
[type_id] => virtual
[name] => product
[description] => Test
[short_description] => Test
[news_from_date] =>
[old_id] =>
[news_to_date] =>
[status] => 1
[visibility] => 4
...
[created_at] => 2011-05-25 15:11:34
[updated_at] => 2011-05-25 15:11:34
...
[price] => 10.0000
Run Code Online (Sandbox Code Playgroud)
最后,API看到物品的价格实际上是10.00美元,但是当通过API添加到购物车时,价格没有得到正确反映.
就这样它可以是一个官方回答的问题,这里找到的解决方案,http://magentocommerce.com/boards/viewthread/227044我花了两天时间搜索这个,今天拿出一个不起眼的搜索词试图找到解决方案