Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: All 1.7 versions
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Tests & Expected Results:
      N/A
    • Documentation Change:
      N/A

      Description

      Dear developers.

      For a few weeks i've stumbled upon multiple problems and bugs while creating an order through the webservice. Each time i'm getting an error and whatever i change the result in the end is always the same error as the end station. So the code i've been using for trying to add the order through the webservice is:

       

      // Creating a cart and order
      try {
                  // Vars & includes required to use the lib
                  define('DEBUG', true);
                  require_once('../PSWebServiceLibrary.php');
                  $webService = new PrestaShopWebservice($url, $key, DEBUG);
      
                  // Set the variables.
                  // Check if a customer is selected
      //            if (isset($_SESSION['user']) && $_SESSION['user'] == true) {
                  if (!empty($_SESSION['cart']['customerSelect']['id'])) {
                      $userId = $_SESSION['cart']['customerSelect']['id'];
                  } else {
                      $userId = 1;
                  }
      //            } else {
      //                echo '<script> alert("Error")';
      //            }
      
                  $id_currency = 1;
                  $id_lang = 1;
                  $total_price = $_SESSION['cart']['totalPrice'];
                  $payment_method = $_REQUEST['payment_method'];
                  $real_paid = $_REQUEST['order_paymentMethodReal'];
                  $price_excl_vat = $total_price * 0.79;
                  $cart_items = $_SESSION['cart']['totalItems'];
                  $cartDecode = json_decode($cart_encode);
                  $date = date("Y-m-d h:i:s");
      
                  // Create the cart
                  $opt = $webService->get(array(
                      'resource' => 'carts',
                  ));
      
                  $cart_id_opt = $webService->get(array(
                      'resource' => 'carts',
                      'display' => '[id]',
                      'filter[id_customer]' => $userId,
                      'filter[checkout_session_data]' => NULL,
                      'sort' => '[id_DESC]',
                      'limit' => 1
                  ));
      
                  $cart_id = json_encode($cart_id_opt);
      
                  $resource = $opt->children()->children();
                  // Adding dinamic and mandatory fields
                  // Required
                  $resource->id_currency = $id_currency;
                  $resource->id_lang = $id_lang;
      
                  // Adding the product items
                  foreach ($cartDecode as $key => $cartItem) {
                      $resource->associations->cart_rows->cart_row->id_product = $cartItem->id;
                      $resource->associations->cart_rows->cart_row->id_product_attribute = 1;
                      $resource->associations->cart_rows->cart_row->id_address_delivery = 1;
                      $resource->associations->cart_rows->cart_row->quantity = $cartItem->quantity;
                  }
      
      
                  // Others
                  $resource->id_address_delivery = 1;
                  $resource->id_address_invoice = 1;
                  $resource->id_customer = $userId;
                  $resource->secure_key = md5(uniqid(rand(), true));;
                  $resource->carrier = 1;
                  $resource->id_shop_group = 1;
                  $resource->id_carrier = 2;
      
                  $xml = $opt->asXML();
                  $update = $webService->add(array(
                          'resource' => 'carts',
                          'id_customer' => $userId,
                          'id' => $cart_id,
                          'postXml' => $xml
                      )
                  );
      
                  ///*
                  //* 4. Create the order
                  //*
                  //*/
      
                  // Generate the order reference
                  function generateRandomString($length = 9) {
                      $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                      $charactersLength = strlen($characters);
                      $randomString = '';
                      for ($i = 0; $i < $length; $i++) {
                          $randomString .= $characters[rand(0, $charactersLength - 1)];
                      }
                      return $randomString;
                  }
      
                  // CREATE Order
      
                  $optOrder = $webService->get(array('url' => $url .'/api/orders/?schema=synopsis'));
                  $resourceOrder = $optOrder->children()->children();
                  $resourceOrder->id_shop_group = 1;
                  $resourceOrder->reference = generateRandomString();
                  $resourceOrder->id_shop = 1;
                  $resourceOrder->id_carrier = 2; // Check your id_carrier
                  $resourceOrder->id_lang = $id_lang;
                  $resourceOrder->id_customer = $userId;
      //            foreach ($cart_id1 as $key => $cartID) {
      //                $resourceOrder->id_cart = $cartID->id;
      //            }
                  $resourceOrder->id_cart = 284;
                  $resourceOrder->id_currency = $id_currency;
                  $resourceOrder->id_address_delivery = 4;
                  $resourceOrder->id_address_invoice = 4;
                  $resourceOrder->current_state = 17; // order in winkel vanuit easycheckout.
                  $resourceOrder->secure_key = "cc5a1cc34cb39c2625a66e9ba24fd5ea";
                  $resourceOrder->payment = "TargetPay bank betalingen(Bancontact)";
                  $resourceOrder->conversion_rate = 1.000000;
                  $resourceOrder->module = 'ps_Easycheckout';
                  $resourceOrder->recyclable = 0;
                  $resourceOrder->gift = 0;
                  $resourceOrder->gift_message = null;
                  $resourceOrder->mobile_theme = 0;
                  $resourceOrder->shipping_number = 0;
                  $resourceOrder->total_discounts = 0;
                  $resourceOrder->total_discounts_tax_incl = 0;
                  $resourceOrder->total_discounts_tax_excl = 0;
                  $resourceOrder->total_paid = $total_price;
                  $resourceOrder->total_paid_tax_incl = $total_price;
                  $resourceOrder->total_paid_tax_excl = $price_excl_vat;
                  $resourceOrder->total_paid_real = $total_price;
                  $resourceOrder->total_products = $cart_items;
                  $resourceOrder->total_products_wt = $cart_items;
                  $resourceOrder->total_shipping = 2;
                  $resourceOrder->total_shipping_tax_incl = 2;
                  $resourceOrder->total_shipping_tax_excl = 2;
                  $resourceOrder->carrier_tax_rate = 0;
                  $resourceOrder->total_wrapping = 0;
                  $resourceOrder->total_wrapping_tax_incl = 0;
                  $resourceOrder->total_wrapping_tax_excl = 0;
                  $resourceOrder->round_mode = 0;
                  $resourceOrder->round_type = 0;
                  $resourceOrder->invoice_number = $userId;
                  $resourceOrder->delivery_number = $userId;
                  $resourceOrder->invoice_date = $date;
                  $resourceOrder->delivery_date = $date;
                  $resourceOrder->valid = 1;
                  $resourceOrder->date_add = $date;
                  $resourceOrder->date_upd = $date;
      
                  foreach ($cartDecode as $key => $cartItem) {
                      $resourceOrder->associations->order_rows->order_row->id;
                      $resourceOrder->associations->order_rows->order_row->product_id = $cartItem->id;
                      $resourceOrder->associations->order_rows->order_row->product_attribute_id = 0;
                      $resourceOrder->associations->order_rows->order_row->product_quantity = $cartItem->quantity;
                  }
      
                  $xmlOrder = $optOrder->asXML();
                  $updateOrder = $webService->add(array(
                      'resource' => 'orders',
                      'postXml' => $xmlOrder
                      )
                  );
      
      
      
                  $optOrderPayment = $webService->get(array('resource' => 'order_payments'));
                  $resourceOrderPayment = $optOrderPayment->children()->children();
                  $resourceOrderPayment->order_reference = generateRandomString();
                  $resourceOrderPayment->id_currency = 1; // Check your id_carrier
                  $resourceOrderPayment->amount = $total_price;
                  $resourceOrderPayment->payment_method = "Actieve betaling";
                  $resourceOrderPayment->conversion_rate = 1;
                  $resourceOrderPayment->date_add = $date;
      
                  $xmlOrderPayment = $optOrderPayment->asXML();
                  $updateOrderPayment = $webService->add(array(
                          'resource' => 'order_payments',
                          'id_customer' => $userId,
                          'postXml' => $xmlOrderPayment
                      )
                  );
              }
              catch (PrestaShopWebserviceException $ex) {
      
                  // Here we are dealing with errors
      
                  $trace = $ex->getTrace();
      
                  if ($trace[0]['args'][0] == 404) echo 'Bad ID';
      
                  else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
      
                  else echo 'Other error<br />' . $ex->getMessage();
              }

      The error i'm not getting around is:

      &lt;prestashop xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
      &lt;orders&gt;
      &lt;order id=&quot;1&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/1&quot;/&gt;
      &lt;order id=&quot;2&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/2&quot;/&gt;
      &lt;order id=&quot;3&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/3&quot;/&gt;
      &lt;order id=&quot;4&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/4&quot;/&gt;
      &lt;order id=&quot;5&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/5&quot;/&gt;
      &lt;order id=&quot;6&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/6&quot;/&gt;
      &lt;order id=&quot;7&quot; xlink:href=&quot;https://mydomain.com/prestademo/api/orders/7&quot;/&gt;
      &lt;order id=&quot;8&quot;
      
      xlink:href=&quot;https://mydomain.com/prestademo/api/orders/8&quot;/&gt;
      &lt;id_shop_group&gt;1&lt;/id_shop_group&gt;&lt;reference&gt;niUZBtxZN&lt;/reference&gt;&lt;id_shop&gt;1&lt;/id_shop&gt;&lt;id_carrier&gt;2&lt;/id_carrier&gt;&lt;id_lang&gt;1&lt;/id_lang&gt;&lt;id_customer&gt;1&lt;/id_customer&gt;&lt;id_cart&gt;284&lt;/id_cart&gt;&lt;id_currency&gt;1&lt;/id_currency&gt;&lt;id_address_delivery&gt;4&lt;/id_address_delivery&gt;&lt;id_address_invoice&gt;4&lt;/id_address_invoice&gt;&lt;current_state&gt;17&lt;/current_state&gt;&lt;secure_key&gt;cc5a1cc34cb39c2625a66e9ba24fd5ea&lt;/secure_key&gt;&lt;payment&gt;TargetPay bank betalingen(Bancontact)&lt;/payment&gt;&lt;conversion_rate&gt;1&lt;/conversion_rate&gt;&lt;module&gt;ps_Easycheckout&lt;/module&gt;&lt;recyclable&gt;0&lt;/recyclable&gt;&lt;gift&gt;0&lt;/gift&gt;&lt;gift_message&gt;&lt;/gift_message&gt;&lt;mobile_theme&gt;0&lt;/mobile_theme&gt;&lt;shipping_number&gt;0&lt;/shipping_number&gt;&lt;total_discounts&gt;0&lt;/total_discounts&gt;&lt;total_discounts_tax_incl&gt;0&lt;/total_discounts_tax_incl&gt;&lt;total_discounts_tax_excl&gt;0&lt;/total_discounts_tax_excl&gt;&lt;total_paid&gt;66.04&lt;/total_paid&gt;&lt;total_paid_tax_incl&gt;66.04&lt;/total_paid_tax_incl&gt;&lt;total_paid_tax_excl&gt;52.1716&lt;/total_paid_tax_excl&gt;&lt;total_paid_real&gt;66.04&lt;/total_paid_real&gt;&lt;total_products&gt;1&lt;/total_products&gt;&lt;total_products_wt&gt;1&lt;/total_products_wt&gt;&lt;total_shipping&gt;2&lt;/total_shipping&gt;&lt;total_shipping_tax_incl&gt;2&lt;/total_shipping_tax_incl&gt;&lt;total_shipping_tax_excl&gt;2&lt;/total_shipping_tax_excl&gt;&lt;carrier_tax_rate&gt;0&lt;/carrier_tax_rate&gt;&lt;total_wrapping&gt;0&lt;/total_wrapping&gt;&lt;total_wrapping_tax_incl&gt;0&lt;/total_wrapping_tax_incl&gt;&lt;total_wrapping_tax_excl&gt;0&lt;/total_wrapping_tax_excl&gt;&lt;round_mode&gt;0&lt;/round_mode&gt;&lt;round_type&gt;0&lt;/round_type&gt;&lt;invoice_number&gt;1&lt;/invoice_number&gt;&lt;delivery_number&gt;1&lt;/delivery_number&gt;&lt;invoice_date&gt;2017-12-11 04:42:26&lt;/invoice_date&gt;&lt;delivery_date&gt;2017-12-11 04:42:26&lt;/delivery_date&gt;&lt;valid&gt;1&lt;/valid&gt;&lt;date_add&gt;2017-12-11 04:42:26&lt;/date_add&gt;&lt;date_upd&gt;2017-12-11 04:42:26&lt;/date_upd&gt;&lt;associations&gt;&lt;order_rows&gt;&lt;order_row&gt;&lt;product_id&gt;1&lt;/product_id&gt;&lt;product_attribute_id&gt;0&lt;/product_attribute_id&gt;&lt;product_quantity&gt;4&lt;/product_quantity&gt;&lt;/order_row&gt;&lt;/order_rows&gt;&lt;/associations&gt;&lt;/orders&gt;
      &lt;/prestashop&gt;
      </pre></div><div style="display:table;background:#CCC;font-size:8pt;padding:7px"><h6 style="font-size:9pt;margin:0">RETURN HTTP BODY</h6><pre>
      Fatal error: Uncaught Error: Call to a member function validateOrder() on boolean in /mydomain.com/public_html/prestademo/classes/order/Order.php:1628
      Stack trace:
      #0 /mydomain.com/public_html/prestademo/classes/webservice/WebserviceRequest.php(1485): OrderCore-&gt;addWs()
      #1 /mydomain.com/public_html/prestademo/classes/webservice/WebserviceRequest.php(1299): WebserviceRequestCore-&gt;saveEntityFromXml(201)
      #2 /mydomain.com/public_html/prestademo/classes/webservice/WebserviceRequest.php(526): WebserviceRequestCore-&gt;executeEntityPost()
      #3 /mydomain.com/public_html/prestademo/webservice/dispatcher.php(87): WebserviceRequestCore-&gt;fetch('LCM3K1SRNJBK975...', 'POST', 'orders', Array, false, '&lt;?xml version=&quot;...')
      #4 {main}
      thrown in /mydomain.com/public_html/prestademo/classes/order/Order.php on line 1628
      </pre></div>Other error<br />HTTP XML response is not parsable: array (
      0 => 
      LibXMLError::__set_state(array(
      'level' => 3,
      'code' => 4,
      'column' => 1,
      'message' => 'Start tag expected, \'<\' not found
      ',
      'file' => '',
      'line' => 2,
      )),
      )
      

      As you can see the insert into the database is running but i'm missing an id on insert and i', getting many errors that have to do with ordervalidate(); i did check my modules and everything is set correctly.

      Since prestashops webservice is sincerely lacking on debugging methods and documentation i'm asking one of you if you have any solution to this or an working code sample.

      Thanks in advance

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Deathstorm Niels van Enckevort
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: