Jump to content

Create order with rest api


Rockers23

Recommended Posts

I use web service api prestashop and after having tried some solutions on the net the error message is : "This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error."

this is my code :

$psXML = <<<XML

<prestashop>
<order>
<id_address_delivery>11</id_address_delivery>
<id_address_invoice>11</id_address_invoice>
<id_cart xlink:href="http://localhost/prestashop/api/carts/29">29</id_cart>
<id_currency>1</id_currency>
<id_lang>1</id_lang>
<id_customer>4</id_customer>
<id_carrier>2</id_carrier>
<current_state/>
<module>paypal</module>
<invoice_number/>
<invoice_date/>
<delivery_number/>
<delivery_date/>
<valid/>
<date_add/>
<date_upd/>
<shipping_number/>
<id_shop_group/>
<id_shop/>
<secure_key/>
<payment>paypal</payment>
<recyclable/>
<gift/>
<gift_message/>
<mobile_theme/>
<total_discounts/>
<total_discounts_tax_incl/>
<total_discounts_tax_excl/>
<total_paid>19.680000</total_paid>
<total_paid_tax_incl/>
<total_paid_tax_excl/>
<total_paid_real>19.680000</total_paid_real>
<total_products>19.680000</total_products>
<total_products_wt>19.680000</total_products_wt>
<total_shipping/>
<total_shipping_tax_incl/>
<total_shipping_tax_excl/>
<carrier_tax_rate/>
<total_wrapping/>
<total_wrapping_tax_incl/>
<total_wrapping_tax_excl/>
<round_mode/>
<conversion_rate>1.0</conversion_rate>
<reference/>
<associations>
<order_rows>
<order_row>
<id/>
<product_id>7</product_id>
<product_attribute_id>34</product_attribute_id>
<product_quantity>1</product_quantity>
<product_name/>
<product_reference/>
<product_ean13/>
<product_upc/>
<product_price/>
<unit_price_tax_incl/>
<unit_price_tax_excl/>
</order_row>
</order_rows>
</associations>
</order>
</prestashop>

XML;



try {

$webService = new PrestaShopWebservice($serverUrl, $serverApiKey, true);

$xml = new SimpleXMLElement($psXML);

$opt = array( 'resource' => 'orders' );

$opt['postXml'] = $xml->asXML();

$xml = $webService->add( $opt );

}

catch (PrestaShopWebserviceException $ex)

{

echo 'Other error: <br />' . $ex->getMessage();

}
Link to comment
Share on other sites

  • 4 months later...

Also same problem

This is my xml

 

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <order>
        <id></id>
        <id_address_delivery>5047</id_address_delivery>
        <id_address_invoice>5047</id_address_invoice>
        <id_cart>35</id_cart>
        <id_currency>1</id_currency>
        <id_lang>1</id_lang>
        <id_customer>34</id_customer>
        <id_carrier>60</id_carrier>
        <current_state>59</current_state>
        <module>bca</module>
        <invoice_number></invoice_number>
        <invoice_date></invoice_date>
        <delivery_number></delivery_number>
        <delivery_date></delivery_date>
        <valid></valid>
        <date_add></date_add>
        <date_upd></date_upd>
        <shipping_number></shipping_number>
        <id_shop_group>1</id_shop_group>
        <id_shop>1</id_shop>
        <secure_key></secure_key>
        <payment>BCA</payment>
        <recyclable></recyclable>
        <gift></gift>
        <gift_message></gift_message>
        <mobile_theme></mobile_theme>
        <total_discounts></total_discounts>
        <total_discounts_tax_incl></total_discounts_tax_incl>
        <total_discounts_tax_excl></total_discounts_tax_excl>
        <total_paid>196000</total_paid>
        <total_paid_tax_incl></total_paid_tax_incl>
        <total_paid_tax_excl></total_paid_tax_excl>
        <total_paid_real>196000</total_paid_real>
        <total_products>196000</total_products>
        <total_products_wt>196000</total_products_wt>
        <total_shipping></total_shipping>
        <total_shipping_tax_incl></total_shipping_tax_incl>
        <total_shipping_tax_excl></total_shipping_tax_excl>
        <carrier_tax_rate></carrier_tax_rate>
        <total_wrapping></total_wrapping>
        <total_wrapping_tax_incl></total_wrapping_tax_incl>
        <total_wrapping_tax_excl></total_wrapping_tax_excl>
        <round_mode></round_mode>
        <round_type></round_type>
        <conversion_rate>1</conversion_rate>
        <reference></reference>
        <associations>
            <order_rows>
                <order_row>
                    <product_id>3</product_id>
                    <product_attribute_id>0</product_attribute_id>
                    <product_quantity>4</product_quantity>
                </order_row>
                <order_row>
                    <product_id>6</product_id>
                    <product_attribute_id>0</product_attribute_id>
                    <product_quantity>4</product_quantity>
                </order_row>
            </order_rows>
        </associations>
    </order>
</prestashop>
 
{"status":"Other error
<br \/>Bad parameters given"}
 
Why bad parameters? All required is not empty.
 
Thank you,
Link to comment
Share on other sites

  • 3 months later...
            $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers/?schema=synopsis'));

 

            $customer = array();

            $product = array();

 

            if (!empty(Tools::getValue('c_email')))

                $customer['email'] = Tools::getValue('c_email');

            else

                $customer['email'] = '[email protected]';

 

            $customer['firstname'] = Tools::getValue('fname');

            $customer['lastname'] = Tools::getValue('lname');

            $customer['address1'] = Tools::getValue('c_address');

            $customer['city'] = Tools::getValue('c_city');

            $customer['phone'] = Tools::getValue('c_phone');

 

            $id['country'] = '165';

            $id['lang'] = '1';

            $id['currency'] = '1';

            $id['carrier'] = '3';

 

            $product['quantity'] = Tools::getValue('c_qty');

            $product['id'] = $id_product;

            $product['price'] = Product::getPriceStatic($product['id']);

            $product['name'] = Product::getProductName($product['id']);

 

            $product['total'] = $product['price'] * $product['quantity'];

 

            $xml->customer->firstname = $customer['firstname'];

            $xml->customer->lastname = $customer['lastname'];

            $xml->customer->email = $customer['email'];

            $xml->customer->newsletter = '1';

            $xml->customer->optin = '1';

            $xml->customer->active = '1';

 

 

            $opt = array('resource' => 'customers');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created customer

 

            $id['customer'] = $xml->customer->id;

 

            // CREATE Address

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/addresses?schema=synopsis'));

 

            $xml->address->id_customer = $id['customer'];

            $xml->address->firstname = $customer['firstname'];

            $xml->address->lastname = $customer['lastname'];

            $xml->address->address1 = $customer['address1'];

            $xml->address->city = $customer['city'];

            $xml->address->phone_mobile = $customer['phone'];

            $xml->address->id_country = $id['country'];

            $xml->address->alias = '-';

 

            $opt = array('resource' => 'addresses');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created address

 

            $id['address'] = $xml->address->id;

 

            // CREATE Cart

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank'));

 

            $xml->cart->id_customer = $id['customer'];

            $xml->cart->id_address_delivery = $id['address'];

            $xml->cart->id_address_invoice = $id['address'];

            $xml->cart->id_currency = $id['currency'];

            $xml->cart->id_lang = $id['lang'];

            $xml->cart->id_carrier = $id['carrier'];

 

            $xml->cart->associations->cart_rows->cart_row->id_product = $product['id'];

            $xml->cart->associations->cart_rows->cart_row->quantity = $product['quantity'];

            if(!empty(Tools::getValue('product_attr')))

                $xml->cart->associations->cart_rows->cart_row->id_product_attribute = Tools::getValue('product_attr');

 

            $opt = array('resource' => 'carts');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created cart

 

            $id['cart'] = $xml->cart->id;

 

            // 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 = 3;

            $xml->order->current_state = 3;

            $xml->order->valid = 0;

            $xml->order->payment = 'Cash on delivery';

            $xml->order->module = 'cashondelivery';

            $xml->order->total_paid = $product['total'];

            $xml->order->total_paid_tax_incl = $product['total'];

            $xml->order->total_paid_tax_excl = $product['total'];

            $xml->order->total_paid_real = '0';

            $xml->order->total_products = $product['total'];

            $xml->order->total_products_wt = $product['total'];

            $xml->order->conversion_rate = '1';

 

 

            $xml->order->associations->order_rows->order_row->product_id = $product['id'];

            $xml->order->associations->order_rows->order_row->product_quantity = $product['quantity'];

 

 

            $opt = array('resource' => 'orders');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            $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);

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...