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.

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

报告相同问题?