donglin6659 2017-11-02 03:08
浏览 52
已采纳

Prestashop Webservice:多个购物车行

I am working with prestashop 1.6 and have a fully working setup with the webservice(api) and prest5ashop but I have a slightly issue with the cart adding mechanism.

Basically I go to create my cart but when I do each subsequent item I add (cart_row) under (cart_rows) seems to be malformed and thus does not get added.

My code is:

$product_list = array(
"1" => array("id_product" => "219", "quantity" => "1"),
"2" => array("id_product" => "219", "quantity" => "1"),
"3" => array("id_product" => "219", "quantity" => "3")   
);
            $i = 0;
            foreach ($product_list as $product) {
                $xml->cart->associations->cart_rows->cart_row[$i]->id_product = $product['id_product'];
                $xml->cart->associations->cart_rows->cart_row[$i]->quantity = $product['quantity'];
                $i++;
            }

$opt = array('resource' => 'carts');
$opt['postXml'] = $xml->asXML();
echo '<pre>'; print_r($opt); echo '</pre>';
$xml = $webService->add($opt);
$id['cart'] = $xml->cart->id; // ID of created cart

So basically in the above example, product 1 gets added but 2 and 3 do not. When I look at the XML response from Prestashop I notice this:

<associations>
<cart_rows>
        <cart_row>
        <id_product>219</id_product>
        <id_product_attribute/>
        <id_address_delivery/>
        <quantity>1</quantity>
        </cart_row>
<cart_row><id_product>219</id_product><quantity>1</quantity></cart_row><cart_row><id_product>219</id_product><quantity>3</quantity></cart_row></cart_rows>
</associations>

I can see the second and third products added seem malformed, but I do not understand why. Can anybody help out?

Thanks!

  • 写回答

1条回答 默认 最新

  • dthh5038 2017-11-02 03:33
    关注

    Why id product are same? Same id product with different quantity will not be accepted in multiple cart rows. It should be added before sending. Please use there different id product and share the result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog