Jump to content

error 500 during creating an order via web service

Recommended Posts

Hi people,


I'm having an error(500) when i'm creating a order via web service 

I have fill th xml object with all the required field .

This is my code :

ini_set('display_errors', 1);
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://...');
define('PS_WS_AUTH_KEY', '...');
require_once 'PSWebServiceLibrary.php';

function xml2array($xmlObject, $out = array()) {
      foreach ((array) $xmlObject as $index => $node) {
            $out[$index] = (is_object($node)) ? xml2array($node) : $node;

      return $out;

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

// Here we set the option array for the Webservice : we want customers resources
$id_address = $_POST['id_address'];
$total_paid  = $_POST['amount'];
//$products = $_POST["products"];
$id_cart  = $_POST["id_cart"];
$id_currency = $_POST['id_currency'];
$id_customer = $_POST['id_customer'];
$id_carrier = $_POST['id_carrier'];
$product_id = $_POST['product_id'];
$totalproducts = sizeof($product_id);
$product_attribute_id = $_POST['product_attribute_id'];
$product_quantity = $_POST['product_quantity'];
$id_lang = $_POST['id_lang'];
$channel = $_POST['channel']; 
         // CREATE Order

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank'));
            $xml->order->id_customer = $id_customer;
            $xml->order->id_address_delivery = $id_address;
            $xml->order->id_address_invoice = $id_address;
            $xml->order->id_cart = $id_cart;
            $xml->order->id_currency = $id_currency;
            $xml->order->id_lang = $id_lang;
            $xml->order->id_carrier = $id_carrier;
            //$xml->order->current_state = 3;
            //$xml->order->valid = 0;
            $xml->order->payment = 'Cash on delivery';;
            $xml->order->module = 'cashondelivery';
            $xml->order->total_paid = $total_paid;
            // $xml->order->total_paid_tax_incl = $total_paid;
            // $xml->order->total_paid_tax_excl = $total_paid;
            $xml->order->total_paid_real = $total_paid;
            $xml->order->total_products = $totalproducts;
            $xml->order->total_products_wt = $totalproducts;
            $xml->order->conversion_rate = '1';
             foreach ($product_id as $value) {
                        $xml->order->associations->order_rows->order_row[$i]->product_id = $value;
                        $xml->order->associations->order_rows->order_row[$i]->product_attribute_id = $product_attribute_id[$i];
                        $xml->order->associations->order_rows->order_row[$i]->product_quantity = $product_quantity[$i];

             try {
            $opt = array('resource' => 'orders');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
            $result = $xml;
            $id['order'] = $xml->order->id;
            $id['secure_key'] = $xml->order->secure_key;
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/order_histories?schema=blank'));
            $xml->order_history->id_order = $id['order'];
            $xml->order_history->id_order_state = '3';
            $opt = array('resource' => 'order_histories');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);

            echo json_encode($result);
            catch(PrestaShopWebserviceException $ex)
            $trace = $ex->getTrace();
            $errorCode = $trace[0]['args'][0];
            if ($errorCode==401)
              echo 'Mauvaise cle authentification curl';
              echo 'Autre erreur : <br />';
              echo $ex->getMessage().'<br />';
              echo 'Code : '.$ex->getCode().'<br />';
              echo 'Trace : '.print_r($ex->getTrace()).'<br />';
              echo $ex->getFile().'<br />';
              echo $ex->getLine().'<br />';
this is the error report that im getting :
</div>Autre erreur :
<br />This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.
<br />Code : 0
<br />Array
    [0] => Array
            [file] => /home/zackrymf/public_html/mobile/customwebservices/PSWebServiceLibrary.php
            [line] => 241
            [function] => checkStatusCode
            [class] => PrestaShopWebservice
            [type] => ->
            [args] => Array
                    [0] => 500
    [1] => Array
            [file] => /home/zackrymf/public_html/mobile/customwebservices/createOrder.php
            [line] => 71
            [function] => add
            [class] => PrestaShopWebservice
            [type] => ->
            [args] => Array
                    [0] => Array
                            [resource] => orders
                            [postXml] =>


any help regarding this ?

Share this post

Link to post
Share on other sites

Try to turn on dev mode in prestashop. I noticed sometimes it dies to 500 when it's disabled, without apparent reason. See if this is the case

  • Like 1

Share this post

Link to post
Share on other sites

Hello, I also have a problem when i try to create an order. I am using Prestashop web services. I am able to create a customer, an address and a cart, after that i am trying to create an order but it return an error 500. In the php_error log i can see:

"PHP Fatal error:  Uncaught Error: Call to a member function get() on null in /Applications/MAMP/htdocs/myshop/classes/Tools.php:801"

I can successfully create an order by using the prestashop front end, but if i try to do it from my application then it creates an order which has no state(current_state:0), i also notice that the delivery option is not created either and i also get the above error in the php_error.log.  I am really new to prestashop. I would appreciate your help very much.

Thanks in advance

Share this post

Link to post
Share on other sites

What's your PrestaShop version? It looks like there is no object being called.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More