Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
155 stars 153 forks source link

Exception when adding order #408

Closed enesbehlul closed 4 years ago

enesbehlul commented 4 years ago

I am using prestasharp v1.2.8 and prestashop v1.7.6.8

trying to add order to order factory by using default pre created products

No problem with,

  1. creating user,
  2. creating address for user,
  3. creating cart,
  4. creating order only if ID of the product in the cart is 1 (Hummingbird printed t-shirt)

when i try to add new order with a different product, prestasharp returns exception (different product is also a default product)

debug mode exception : Object reference not set to an instance of an object. null reference exception debug off exception : Prestashop failed to serve XML response instead got text: HttpStatusCode: InternalServerError Bukimedia.PrestaSharp.PrestaSharpException"

oromand commented 4 years ago

I believe you had some sort of similar code while creating your order. In case not, this is a working sample of mine. It's true that current version of prestasharp isn't of much help when dealing with error.

var order = await orderFactory.AddAsync(new order()
                {
                    id_cart = cart.id,
                    id_address_delivery = cart.id_address_delivery,
                    id_address_invoice = cart.id_address_invoice,
                    id_currency = euroCurrency.id,
                    id_customer = cart.id_customer,
                    id_lang = languageFr.id,
                    id_carrier = defaultCarrier.id,

                    total_paid = input.TotalTTC,
                    total_products_wt = input.TotalTTC,
                    total_shipping_tax_incl = input.TotalShippingTTC,

                    payment = "TPE",
                    module = "ps_wirepayment",
                    //state
                });
enesbehlul commented 4 years ago

@oromand i tried this way but i got same result. thanks anyway

enesbehlul commented 4 years ago

I found my problem, it was about creating cart actually. when i was adding a product to cart, in cart_rows list, i gave product_attribute_id = 1 for every product. that was the problem. it should be zero.