Jump to content

Create Orders from Another Site Using Prestashop 1.5 API


Recommended Posts

How to create orders from external web sites using the latest Prestashop API?

 

I have seen questions like this on Google but have not seen a workable answer.

 

Scenario:

Prestashop members currently in another site that is not a shopping cart as such, but allows the members of both sites to order and/or purchase products that have been extracted from the Prestashop using web services. These extracted products are displayed in the other site with a quantity selector and an add to cart button followed by a submit button. For some people the second site may be a cut down mobile site or a membership site.

 

SSL would naturally be used to link the sites for some security.

 

Can/How do we create a Prestashop shopping cart and possibly process it from the second site using web services.

 

If it can't be all done yet, apart from listing the products via the web services, what can be done towards this scenario?

 

Thanks

  • Like 2
Link to comment
Share on other sites

  • 4 months later...

I too am looking for a solution to this. The documentation does not provide any examples of this process or what is necessary to successfully submit a new order.

  1. Are auto-incremented values automatically set?
  2. Should a new cart object be built and then submitted with a new order object?
  3. Which fields are required?
  4. Is there a sample script similar to the one that describes creating a new customer?

Link to comment
Share on other sites

Hi,

First of all, I strongly advice you know A LOT of Prestashop's architecture before trying something like this. I never tried such a thing, but I know the software architecture, and i can say that you would need *at least* one "bridge" file between your app and Prestashop. Due to its nature, Prestashop will deny this kind of process, since it requires the basic cofiguration files to be embedded in the code before doing anything (you can try it yourself, anything without the proper configuration will be killed if called within a module/page, like an ajax request.

 

Therefore, I suggest.

1- Study the order controller

2- Study the cart controller

3- Study the authentication controller

 

After this, you should know how to create a new cart with the proper cookie setting. BUT of course it's not over. You'll need all the data prestashop creates and assigns to a cart cookie.

This to create the cart.

 

As for processing the cart itself... well. Basically, in 1.5, you only need 1 function call to create an order, this:

 

$this->module->validateOrder($cart->id, Configuration::get('PS_OS_GOLDENPAY'), $total, $this->module->displayName, NULL, $extraVars, (int)$currency->id, false, $customer->secure_key);

 

But as you can see, it's created for every payment module.An you also want the customer to put in its data, and add it to the database (that's why i told you about the authentication controller), and select shipping. Of course, you also have to deal with currencies....geez, I'm getting lost.

 

 

I suggest you give up ;D Prestashop has too tight security measures to allow this.

Of course, it's just my opinion, and someone who knows the software better than me may have a different idea.

 

Cheers!

Link to comment
Share on other sites

Thanks for the response. I have managed to build a new cart via the API, submit it, and it adds to my sandbox store just fine.

 

My problem is that I'm getting the error:

 

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' => 1, )), )

 

I've seen some other users having this same issue, but I have not found a resolution to this.

Link to comment
Share on other sites

Still not sure, but this looks like it's working now. I used `cheque` for the required module node (not sure what this node is supposed to be for), and the orders are being submitted now (despite receiving an HTTP500 error after running the script).

Link to comment
Share on other sites

Uh...I'm so Dumb. Actually, I've never dived into the RESTful API actually, since I don't like the fact that it outputs XML. But thinking about it, yes, you can definitely create new carts. Actually, I'm looking into it right now, I'll update you as soon as i manage to do it corerctly (so that a full cart can be created, and also assigned to the correct customer if needed)

Link to comment
Share on other sites

Hi pspahn,

 

I'm triing to do quiet the same thing as you : add some product to the cart from an other website, using the api.

 

When the product is add to the cart, it will go back to the prestashop website, and follow the normal processus.

 

I can't found any documentation about this. Did you found some documentation about this, or can you help me ?

 

Thank's for your help, and sorry for my por english...

Edited by EnergieZ (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 2 months later...
  • 2 years later...

Still nothing solution?
 
This is my xml, but return bad parameter given.

<?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>5296</invoice_number>
        <invoice_date>2015-09-01 10:24:07</invoice_date>
        <delivery_number>4441</delivery_number>
        <delivery_date>2015-09-01 10:25:10</delivery_date>
        <valid>1</valid>
        <date_add>2015-09-01 10:24:05</date_add>
        <date_upd>2015-09-01 10:25:12</date_upd>
        <shipping_number></shipping_number>
        <id_shop_group>1</id_shop_group>
        <id_shop>1</id_shop>
        <secure_key>e4c36136722e79f90b80ae87492dad91</secure_key>
        <payment>BCA</payment>
        <recyclable>0</recyclable>
        <gift>0</gift>
        <gift_message>0</gift_message>
        <mobile_theme>0</mobile_theme>
        <total_discounts>0</total_discounts>
        <total_discounts_tax_incl>0</total_discounts_tax_incl>
        <total_discounts_tax_excl>0</total_discounts_tax_excl>
        <total_paid>196000</total_paid>
        <total_paid_tax_incl>196000</total_paid_tax_incl>
        <total_paid_tax_excl>196000</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>0</total_shipping>
        <total_shipping_tax_incl>0</total_shipping_tax_incl>
        <total_shipping_tax_excl>0</total_shipping_tax_excl>
        <carrier_tax_rate>0</carrier_tax_rate>
        <total_wrapping>0</total_wrapping>
        <total_wrapping_tax_incl>0</total_wrapping_tax_incl>
        <total_wrapping_tax_excl>0</total_wrapping_tax_excl>
        <round_mode>2</round_mode>
        <round_type>2</round_type>
        <conversion_rate>1</conversion_rate>
        <reference>JCOMFUHYZ</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"}

Anyone help?

Thank you

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