我正在尝试使用Magento SOAP API v1创建订单,并在将捆绑产品添加到购物车时遇到问题.我能够通过正确的简单产品获得订单,但我对添加捆绑产品感到困惑.
// The Products Array with Bundle
$products = array(
array(
"product_id" => "38914",
"qty" => "1",
"bundle_option" => array(
"18194" => "20360",
),
"related_product" => null,
"bundle_qty" => array("20360" => "1"),
"options" => array(
"0" => array(
"key" => "3328",
"value" => "4494",
),
"1" => array(
"key" => "3329",
"value" => null,
),
"2" => array(
"key" => "3339",
"value" => null,
),
)
)
);
// Get an API session
$client = new \SoapClient('magentoinstallation/index.php/api/soap/?wsdl');
$session = $client->login('user', 'password');
//Create the Cart
$cart = $client->call( $session, 'cart.create');
// add the products
$resultCartProductsAdd = $client->call( $session, "cart_product.add", array( $cart, $products ) );
Run Code Online (Sandbox Code Playgroud)
我尝试了很多不同的格式并且遇到了错误
Selected required options are not available
Please specify product option(s).
Run Code Online (Sandbox Code Playgroud)
任何帮助或建议将不胜感激.
我想出了一种通过SOAP将捆绑产品添加到购物车的方法.
密钥中的值bundle_option必须是选项(捆绑/选择)的模型的ID(而不是产品ID).键必须是选项的ID(我假设在您的示例中已经正确)
$products = array(
array(
"product_id" => "38914",
"qty" => "1",
"bundle_option" => array(
"18194" => "20360", // <-- THE VALUE MUST BE THE ID OF THE CORRESPONDING "bundle/selection" MODEL, INSTEAD OF THE PRODUCT'S ID
),
// ...
);
Run Code Online (Sandbox Code Playgroud)
还在为包数量的关键应该是bundle_option_qty代替bundle_qty.
捆绑产品的可用性将会影响您的流程,因此请确保产品全部可销售.
我用magento和这个片段的示例数据成功地尝试了它
$client = new \SoapClient('magentoinstallation/index.php/api/soap/?wsdl');
$session = $client->login('testuser', 'password');
$products = array(
array(
"product_id" => 158,
"qty" => "1",
"bundle_option" => array(
1 => 2, // 1 is the option id, 2 is the bundle/selection id
),
)
);
$cart = $client->call($session, 'cart.create', array('default'));
$resultCartProductsAdd = $client->call($session, "cart_product.add", array($cart, $products));
Run Code Online (Sandbox Code Playgroud)
我重复了我的回答,发现了重要的一点.
选择商店 ;-)
只是用
$cart = $client->call($session, 'cart.create', array('default'));
代替
$cart = $client->call($session, 'cart.create');
(有关详细信息,请查看API规范:http://www.magentocommerce.com/api/soap/checkout/cart/cart.create.html)
更改后,添加任何捆绑产品很简单,如上所述
| 归档时间: |
|
| 查看次数: |
1691 次 |
| 最近记录: |