Jump to content

error 500 during creating an order via web service


atwebmaster

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 :

<?php
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';
 
             $i=0;
             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];
                        $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';
              }
            else
              {
              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 ?

Link to comment
Share on other sites

  • 3 years later...

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

Link to comment
Share on other sites

  • 10 months later...
On 7/5/2016 at 5:54 PM, atwebmaster said:

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 :


<?php
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';
 
             $i=0;
             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];
                        $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';
              }
            else
              {
              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 ?

If you are still interested in solve this issue, what did you passed to the id_cart ? If you send it an empty cart without data you will get error 500.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...