xbenjii / Prestan

PrestaShop Node.js API Library [UNMAINTAINED]
MIT License
20 stars 7 forks source link

Error creating order with prestashop webservice #11

Open tundaey opened 7 years ago

tundaey commented 7 years ago

I am using the nodejs library prestan to try and create an order, but I get an error. I have been able to create customer, cart and addresses but I'm stuck here.

Here is my code

prestan.get('orders', {schema: 'blank'})
                .then(function(response) {
                    response.prestashop.order.id_address_delivery = 5;
                    response.prestashop.order.id_address_invoice = 5;
                    response.prestashop.order.id_cart =  18;
                    response.prestashop.order.id_currency = 1;
                    response.prestashop.order.current_state = 1;
                    response.prestashop.order.id_lang = 1;
                    response.prestashop.order.id_customer = 2;
                    response.prestashop.order.id_carrier = 0;
                    response.prestashop.order.module = "Bankwire";
                    response.prestashop.order.payment = "bankwire";
                    response.prestashop.order.valid = 0;
                    response.prestashop.order.total_discounts = 0;
                    response.prestashop.order.total_discounts_tax_incl = 0;
                    response.prestashop.order.total_discounts_tax_excl = 0;
                    response.prestashop.order.total_paid = 0;
                    response.prestashop.order.total_paid_tax_incl = 0;
                    response.prestashop.order.total_paid_tax_excl = 0;
                    response.prestashop.order.total_paid_real = 0;
                    response.prestashop.order.total_products = 0;
                    response.prestashop.order.total_shipping = 7;
                    response.prestashop.order.total_shipping_tax_incl = 7;
                    response.prestashop.order.total_shipping_tax_excl = 7;
                    response.prestashop.order.total_products_wt = 0;
                    response.prestashop.order.conversion_rate = 1;
                    // var order_rows =  [
                    //     {product_id: 1, product_attribute_id: 10, product_quantity:1},
                    //     ]
                    //response.prestashop.order.associations.order_rows = order_rows;
                    console.log("res", response);
                    prestan.add('orders', response).then(function(resp){
                        console.log("resp", resp);
                        res.send(resp)
                    });  
                }).catch(function(errors) {
                    console.log("ne",errors);
                    res.send(errors);
                });

I get this error Error: [StatusCodeError: 500 - ] Possibly unhandled TypeError: Cannot read property 'prestashop' of null at C:\Users\Tundaey\work\presta-server\node_modules\prestan\index.js:59:44 at tryCatcher (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\util.js:26:23) at Promise._settlePromiseFromHandler (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\promise.js:510:31) at Promise._settlePromiseAt (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\promise.js:584:18) at Promise._settlePromiseAtPostResolution (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\promise.js:248:10) at Async._drainQueue (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\async.js:128:12) at Async._drainQueues (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\async.js:133:10) at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\Tundaey\work\presta-server\node_modules\bluebird\js\main\async.js:15:14) at processImmediate [as _immediateCallback] (timers.js:368:17)