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

Can't add order? #372

Open SparkyRih opened 5 years ago

SparkyRih commented 5 years ago

I'm running PrestaShop 1.6, and I'm trying to add an order... I started with creating the cart, and that seems to be fine now (I do get back a cart_id, however, I do not see any carts in my PrestaShop back-end)... Next I make the order, I did not know which fields of the order object were required, so I worked with trial-and-error, but after I added the Payment property string, I'm only getting a NullReferencException from the Entity object...

Below you find a snippet of my code, all the IDs (and the secure_key) I use are valid:

`cart cartToSubmit = new cart() { id_currency = currencyId, id_lang = languageId, id_customer = customerId, id_address_delivery = customerAddressId, id_address_invoice = customerAddressId };

        foreach (CartItem item in shoppingCart)
        {
            cart_row row = new cart_row()
            {
                id_product = item.ProductID,                    
                id_product_attribute = item.AttributeId,
                id_address_delivery = customerAddressId,
                quantity = item.Amount
            };
            cartToSubmit.associations.cart_rows.Add(row);
        }

        cartToSubmit = cartFactory.Add(cartToSubmit);

        order orderToSubmit = new order()
        {
            id_cart = cartToSubmit.id,
            id_customer = customerId,
            id_address_delivery = customerAddressId,
            id_address_invoice = customerAddressId,
            id_currency = currencyId,
            id_lang = languageId,
            id_carrier = carrierId,
            module = "swmterminal",
            payment = "pin",
            total_paid = 0,
            current_state = 2,                
            secure_key = customer.secure_key

        };
        orderToSubmit = orderFactory.Add(orderToSubmit);`