您能告诉我如何使用 magento v2_soap api 创建订单吗?
问问题
2619 次
2 回答
1
默认单个 api 是不可能的,您需要创建自己的自定义 api
或者
您需要调用多个 api 来下订单,如下所示 -
$proxy = new SoapClient('http://mywebside.com/api/v2_soap/?wsdl');
$sessionId = $proxy->login($user, $password);
$cartId = $proxy->shoppingCartCreate($sessionId, 1);
// load the customer list and select the first customer from the list
//$customerList = $proxy->customerCustomerList($sessionId, array());
//$customer = (array) $customerList[188];
//Do not change this credentials
$customer['customer_id'] = 199; // customer id
$customer['created_at'] = '2016-02-03 19:24:41';
$customer['updated_at'] = '2016-04-22 03:33:33';
$customer['store_id'] = 1;
$customer['website_id'] = 1;
$customer['created_in'] = 'Default Store View';
$customer['email'] = 'test@gmail.com';
$customer['firstname'] = 'test';
$customer['lastname'] = 'test';
$customer['group_id'] = 1;
$customer['password_hash'] = 'assassaXXXXO';
$customer['mode'] = 'customer';
$proxy->shoppingCartCustomerSet($sessionId, $cartId, $customer);
// load the product list and select the first product from the list
//$productList = $proxy->catalogProductList($sessionId);
// $product = (array) $productList[0];
$product= array(array(
'product_id' => '43001',
'sku' => 'SKU420',
'qty' => '2',
),
array(
'product_id' => '43002',
'sku' => 'SKUZ42B2',
'qty' => '1',
));
try{
$proxy->shoppingCartProductAdd($sessionId, $cartId, $product);
} catch (SoapFault $e) {
$error['product'] = $e->getMessage();
}
$address = array(
array(
'mode' => 'shipping',
'firstname' => $customer['firstname'],
'lastname' => $customer['lastname'],
'street' => 'street address',
'city' => 'city',
'region' => 'region',
'telephone' => 'phone number',
'postcode' => '',
'country_id' => 'country ID',
'is_default_shipping' => 0,
'is_default_billing' => 0
),
array(
'mode' => 'billing',
'firstname' => $customer['firstname'],
'lastname' => $customer['lastname'],
'street' => 'street address',
'city' => 'city',
'region' => 'region',
'telephone' => 'phone number',
'postcode' => '',
'country_id' => 'country ID',
'is_default_shipping' => 0,
'is_default_billing' => 0
),
);
// add customer address
try{
$proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address);
} catch (SoapFault $e) {
$error['shipping'] = $e->getMessage();
}
try{
// add shipping method
$proxy->shoppingCartShippingMethod($sessionId, $cartId, 'freeshipping_freeshipping');
} catch (SoapFault $e) {
$result = $e->getMessage();
}
// add payment method
enter code here
$paymentMethod = array(
'method' => 'cashondelivery'
);
$proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod);
// place the order
$orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null);
于 2016-06-07T13:01:53.800 回答
0
有一个cart
对象可以附加客户和产品。
有关cart_product.add
(SOAP v1) 或shoppingCartProductAdd
(SOAP v2) 的信息在 Magento API 文档中
http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html
于 2013-08-30T12:58:40.690 回答