【问题标题】:Prestashop Webservice: Multiple cart RowsPrestashop Webservice:多个购物车行
【发布时间】:2017-11-02 11:33:41
【问题描述】:

我正在使用 prestashop 1.6 并使用 webservice(api) 和 prest5ashop 进行了完整的设置,但我对购物车添加机制有一点问题。

基本上我会创建我的购物车,但是当我执行每个后续项目时,我在 (cart_rows) 下添加的 (cart_row) 似乎格式不正确,因此不会被添加。

我的代码是:

$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

所以基本上在上面的示例中,添加了产品 1,但没有添加产品 2 和 3。当我查看 Prestashop 的 XML 响应时,我注意到了这一点:

<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>

我可以看到添加的第二个和第三个产品格式不正确,但我不明白为什么。有人可以帮忙吗?

谢谢!

【问题讨论】:

    标签: php web-services prestashop prestashop-1.6


    【解决方案1】:

    为什么 id 产品是一样的?多个购物车行将不接受具有不同数量的相同 id 产品。它应该在发送之前添加。请使用不同的id产品并分享结果。

    【讨论】:

    • 这正是问题所在,非常感谢。即使 Web 服务没有返回有效错误,问题仍然是产品 ID 重复。如果 ID 重复或无效,prestashop 网络服务将不会添加产品,即使启用了调试,它也不会将其作为错误返回。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多