我正在尝试使用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 ) );
我尝试了许多不同的格式并遇到错误
Selected required options are not available
Please specify product option(s).
任何帮助或建议,将不胜感激。
我想出了一种通过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
),
// ...
);
捆绑数量的密钥也应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));
我重试了答案,发现了一个重要的认识点。
选择一个商店;-)
只需使用
$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)
更改此设置后,很容易添加任何捆绑产品,如上所述
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句