Villaing Posted May 19, 2020 Share Posted May 19, 2020 Hi, I'm trying to create an order via the webservices. All seems fine, but when I check the order list in the PrestaShop dashboard, the state of the order is, in my case, "Payment failed". It seems that it grabs the last item from the order_states. But why is it ignoring the value I'm sending with the order? I already tried to create an override file for the Order class, but this seems like too much a hassle for something that should work. Thanks in advance! Link to comment Share on other sites More sharing options...
Villaing Posted May 20, 2020 Author Share Posted May 20, 2020 I'm not sure if this is a bug. In the synopsis it shows that current_state is addable, but it simply gets ignored unless it has an ID. This is not desirable since it could get a state which will generate an invoice. Or in my case, give an error state which notifies the supplier and customer. How should this be done? Link to comment Share on other sites More sharing options...
gusman126 Posted May 20, 2020 Share Posted May 20, 2020 try use : $xml->order->current_state = $id_status; Link to comment Share on other sites More sharing options...
Villaing Posted May 22, 2020 Author Share Posted May 22, 2020 Thank you @gusman126. I kind of am using the same way. In the PrestaShop Order class, it seems it ignores the current set state if there is no ID in the setWsCurrentState function. It looks like there is another way to set the current state for new orders which is not in the documentation of the webservice. Do you or anyone else know? Link to comment Share on other sites More sharing options...
gusman126 Posted May 22, 2020 Share Posted May 22, 2020 Well, I don't know for sure. I read the empty XML and the schema using this command $webService->get(array('url' => $url .'api/orders/?schema=blank')); Link to comment Share on other sites More sharing options...
Villaing Posted May 26, 2020 Author Share Posted May 26, 2020 It simply seems the webservice just ignores the current_state variable for new orders. For now, I simply changed the order of the current states (since it always takes the last one in the list) so it will take a custom "Webservice pending" state. After the order is created I update it with the correct state. This is definitely not a nice way to do it, but for now my only solutions. In my eyes this still seems like a malfunction in PrestaShop's webservice, or a case of bad documentation! I hope this will be "fixed" in the future.. Link to comment Share on other sites More sharing options...
Stepel Posted June 23, 2020 Share Posted June 23, 2020 Hi, did you find the solution ? I have the same problem. current_state is ingored and I think that because of that id_carrier and total_shipping is ingored also, that's why the result is payment failed.. Link to comment Share on other sites More sharing options...
gusman126 Posted June 24, 2020 Share Posted June 24, 2020 hace 12 horas, Stepel dijo: Hi, did you find the solution ? I have the same problem. current_state is ingored and I think that because of that id_carrier and total_shipping is ingored also, that's why the result is payment failed.. Solution for state order : $xmlres = $webService->add( $opt ); // Add order webservice $id_original = $xmlres->order->id; // Read id order webservice $webService = new PrestaShopWebservice($url, $api, false); $xml = $webService->get(array('url' => $url .'api/order_histories/?schema=blank')); $xml->order_history->id_order = $id_original; // id order webservice $xml->order_history->date_add = $date; $xml->order_history->id_order_state = 2; $xml->order_history->id_employee = 1; $opt = array( 'resource' => 'order_histories' ); $opt['postXml'] = $xml->asXML(); $xmloc = $webService->add( $opt ); Solution for carrier and cost $webService = new PrestaShopWebservice($url, $api, false); $xml = $webService->get(array('url' => $url .'api/order_carriers/?schema=blank')); $xml->order_carrier->id_order = $id_original; // id order webservice $xml->order_carrier->id_carrier = 4; // id carrier $xml->order_carrier->shipping_cost_tax_excl = $total_shipping_tax_excl; $xml->order_carrier->shipping_cost_tax_incl = $total_shipping_tax_incl; $xml->order_carrier->tracking_number = ''; $xml->order_carrier->date_add = $date; $opt = array( 'resource' => 'order_carriers' ); $opt['postXml'] = $xml->asXML(); $xmloc = $webService->add( $opt ); Link to comment Share on other sites More sharing options...
Stepel Posted June 24, 2020 Share Posted June 24, 2020 Hi @gusman126, thanks for your reply. Hm i think that it will happen the same if I edit order by webservice. The problem is that new order created by webservice has set first current state totaly independent exactyly in this moment: $xmlres = $webService->add( $opt ); // Add order webservice The worst thing is that first state is "payment error" and customer get mail that there is something wrong with his/her order what is not true. I think that the problem is because on my cart there is no shipping cost even I send delivery_options as {"id_address":"id_carrier,"}. Maybe i need to send something more. Becasue of that there is different bitween total_paid and total amount from cart I spent a lot of hours on tests.. and still I have problem with that. Link to comment Share on other sites More sharing options...
gusman126 Posted June 24, 2020 Share Posted June 24, 2020 I use this code : $xml = $webService->get(array('url' => $url .'api/orders/?schema=blank')); /* $xmld =$xml->asXML(); $logfile = fopen(dirname(__FILE__).'/resp/pedidobn_.xml', "w"); fwrite($logfile, $xmld); */ $xml->order->id = ''; // Customer address $xml->order->id_address_delivery = $id_address; // Customer address $xml->order->id_address_invoice = $id_address; $xml->order->id_cart = $id_cart; $xml->order->id_currency = 1; $xml->order->id_lang = 1; $xml->order->id_customer = $id_customer; $xml->order->id_carrier = 4; $xml->order->current_state = 2; $xml->order->module = 'ps_wirepayment'; $xml->order->invoice_number = ''; $xml->order->invoice_date = ''; $xml->order->delivery_number = ''; $xml->order->delivery_date = ''; $xml->order->id_shop_group = ''; $xml->order->id_shop = ''; $xml->order->secure_key = ''; $xml->order->recyclable = ''; $xml->order->gift = ''; $xml->order->gift_message = ''; $xml->order->mobile_theme = ''; $xml->order->valid = 1; $xml->order->date_add = $date; $xml->order->date_upd = $date; $xml->order->shipping_number = ''; $xml->order->payment = $payment; $xml->order->total_discounts = $total_discounts ; $xml->order->total_discounts_tax_incl = $total_discounts_tax_incl; $xml->order->total_discounts_tax_excl = $total_discounts_tax_excl; $xml->order->total_paid = $total_paid; $xml->order->total_paid_tax_incl = $total_paid_tax_incl ; $xml->order->total_paid_tax_excl = $total_paid_tax_excl ; $xml->order->total_paid_real = $total_paid_real; $xml->order->total_products = $total_products; $xml->order->total_products_wt = $total_products_wt; $xml->order->total_shipping = $total_shipping; $xml->order->total_shipping_tax_incl = $total_shipping_tax_incl; $xml->order->total_shipping_tax_excl = $total_shipping_tax_excl; $xml->order->carrier_tax_rate = ''; $xml->order->total_wrapping = $order->total_wrapping; $xml->order->total_wrapping_tax_incl = $order->total_wrapping_tax_incl; $xml->order->total_wrapping_tax_excl = $order->total_wrapping_tax_excl; $xml->order->round_mode = $order->round_mode; $xml->order->round_type = $order->round_type; $xml->order->conversion_rate = 1; $xml->order->reference = $order->reference; $lin = 0; foreach($pros as $pro){ $xml->order->associations->order_rows->order_row[$lin]->id = $lin; $xml->order->associations->order_rows->order_row[$lin]->product_id = $pro['id_product']; $xml->order->associations->order_rows->order_row[$lin]->product_attribute_id = $pro['id_product_attribute']; $xml->order->associations->order_rows->order_row[$lin]->product_quantity = $pro['quantity']; $xml->order->associations->order_rows->order_row[$lin]->product_name = $pro['product_name']; $xml->order->associations->order_rows->order_row[$lin]->product_reference = $pro['product_reference']; $xml->order->associations->order_rows->order_row[$lin]->product_ean13= $pro['product_ean13']; $xml->order->associations->order_rows->order_row[$lin]->product_isbn = ''; $xml->order->associations->order_rows->order_row[$lin]->product_upc = ''; $xml->order->associations->order_rows->order_row[$lin]->product_price = $pro['original_price']; $xml->order->associations->order_rows->order_row[$lin]->unit_price_tax_incl = $pro['unit_price_tax_incl']; $xml->order->associations->order_rows->order_row[$lin]->unit_price_tax_excl = $pro['unit_price_tax_excl']; $lin++; } $opt = array( 'resource' => 'orders' ); $opt['postXml'] = $xml->asXML(); Link to comment Share on other sites More sharing options...
Stepel Posted June 24, 2020 Share Posted June 24, 2020 I understand all but i think in my case there is some problem with relation bitween carrier and cart and order.. 😕 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now