prestashop 1.6从购物车webservice删除项目

时间:2016-02-20 04:45:16

标签: web-services prestashop-1.6

我试图通过采用在prestashop 1.4中运行的代码在prestashop 1.6中删除购物车中的商品

我可以创建产品,并使用网络服务将产品添加到购物车。

然后我尝试通过从cart_rows中删除产品来删除它,这是xml

<?xml version="1.0" encoding="UTF-8"?>
            <prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<cart>
    <id>21</id>
    <id_address_delivery>0</id_address_delivery>
    <id_address_invoice>0</id_address_invoice>
    <id_currency>1</id_currency>
    <id_customer>0</id_customer>
    <id_guest>0</id_guest>
    <id_lang>1</id_lang>
    <id_shop_group>1</id_shop_group>
    <id_shop>1</id_shop>
    <id_carrier>0</id_carrier>
    <recyclable>0</recyclable>
    <gift>0</gift>
    <gift_message/>
    <mobile_theme>0</mobile_theme>
    <delivery_option/>
    <secure_key/>
    <allow_seperated_package>0</allow_seperated_package>
<associations>
<cart_rows>
    <cart_row>
    </cart_row>
</cart_rows>
</associations>
</cart>
</prestashop>

这会返回以下异常

  

&#39; PrestaShopWebserviceException&#39;有消息&#39;这次致电PrestaShop   Web服务失败并返回HTTP状态500.这意味着:   内部服务器错误。&#39;

但实际上产品已从购物车中删除了!

所以我可以忽略这个异常并继续前进,但我想知道如何使用WS从购物车中删除产品而不会出现异常

1 个答案:

答案 0 :(得分:0)

我觉得发布这个黑客很不舒服,但它是我发现的最好的

解决方案用于网络服务请求

  1. 将数量设置为0:

    <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <cart>
        <id>21</id>
        <id_address_delivery>0</id_address_delivery>
        <id_address_invoice>0</id_address_invoice>
        <id_currency xlink:href="http://localhost:8889/api/currencies/1">1</id_currency>
        <id_customer>0</id_customer>
        <id_guest>0</id_guest>
        <id_lang xlink:href="http://localhost:8889/api/languages/1">1</id_lang>
        <id_shop_group>1</id_shop_group>
        <id_shop>1</id_shop>
        <id_carrier>0</id_carrier>
        <recyclable>0</recyclable>
        <gift>0</gift>
        <gift_message/>
        <mobile_theme>0</mobile_theme>
        <delivery_option/>
        <secure_key/>
        <allow_seperated_package>0</allow_seperated_package>
        <date_add>2016-02-19 23:35:58</date_add>
        <date_upd>2016-02-19 23:35:58</date_upd> <associations> <cart_rows nodeType="cart_row" virtualEntity="true"> <cart_row> 
    <id_product>3</id_product><id_product_attribute>1</id_product_attribute>
    <quantity>0</quantity> 
    </cart_row> </cart_rows> </associations> </cart> </prestashop>
    
  2. 从请求中删除产品

    <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <cart>
        <id>21</id>
        <id_address_delivery>0</id_address_delivery>
        <id_address_invoice>0</id_address_invoice>
        <id_currency xlink:href="http://localhost:8889/api/currencies/1">1</id_currency>
        <id_customer>0</id_customer>
        <id_guest>0</id_guest>
        <id_lang xlink:href="http://localhost:8889/api/languages/1">1</id_lang>
        <id_shop_group>1</id_shop_group>
        <id_shop>1</id_shop>
        <id_carrier>0</id_carrier>
        <recyclable>0</recyclable>
        <gift>0</gift>
        <gift_message/>
        <mobile_theme>0</mobile_theme>
        <delivery_option/>
        <secure_key/>
        <allow_seperated_package>0</allow_seperated_package>
        <date_add>2016-02-19 23:35:58</date_add>
        <date_upd>2016-02-19 23:35:58</date_upd> <associations> <cart_rows nodeType="cart_row" virtualEntity="true"> <cart_row> 
    </cart_row> </cart_rows> </associations> </cart> </prestashop>