V1.6 Import product to woocommerce from Prestashop

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
Hello friends,

There is a task to import products from a prestashop, but I have never worked with the api of this system, so I would be grateful for any advice.

Thank you.
 

d-shilko

Well-known member
☆☆ Special ☆☆
☆ Pro ☆
Joined
Jun 10, 2021
Messages
2,538
Reaction score
1,530
Points
113
NullCash
4,422

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
Use parsing tools. Easy to parse all goods to CVS
I tried to parse information using services, but they do not collect all the necessary information. Specifically, I need a product ID; Subsequently, when buying a product on the Woocommerce website, I will need to create an order on the Presta by API website using the product ID.
This is dropshipping
 

d-shilko

Well-known member
☆☆ Special ☆☆
☆ Pro ☆
Joined
Jun 10, 2021
Messages
2,538
Reaction score
1,530
Points
113
NullCash
4,422
I tried to parse information using services, but they do not collect all the necessary information. Specifically, I need a product ID; Subsequently, when buying a product on the Woocommerce website, I will need to create an order on the Presta by API website using the product ID.
This is dropshipping
But in API presta U can use reference of product to make an order. have goods reference number?
 

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
But in API presta U can use reference of product to make an order. have goods reference number?
Interesting.
I did not know about it. Yes, there is a link to the product. Could you tell me how to place an order using it?
 

d-shilko

Well-known member
☆☆ Special ☆☆
☆ Pro ☆
Joined
Jun 10, 2021
Messages
2,538
Reaction score
1,530
Points
113
NullCash
4,422
1) create Customer (opt.)

2) create Address (opt.)

3) check Products availibility (this is really better...)

4) create Cart with order_rows and with product id's and quantities

5) create Order with this

in all cases required tags should by filled- see /api/object?schema=synopsis

FULL EXAMPLE IN TEXT FILE
 

Attachments

  • apicreateorder.php.txt
    5.5 KB · Views: 4

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
1) create Customer (opt.)

2) create Address (opt.)

3) check Products availibility (this is really better...)

4) create Cart with order_rows and with product id's and quantities

5) create Order with this

in all cases required tags should by filled- see /api/object?schema=synopsis

FULL EXAMPLE IN TEXT FILE

Thank you very much for the instruction. But I did not understand a little how to refer to the desired product. That is, when a user on the woocommerce site buys a product, the order should be automatically purchased by me on the supplier's(presta) site. How to do it?
 

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
1) create Customer (opt.)

2) create Address (opt.)

3) check Products availibility (this is really better...)

4) create Cart with order_rows and with product id's and quantities

5) create Order with this

in all cases required tags should by filled- see /api/object?schema=synopsis

FULL EXAMPLE IN TEXT FILE
also when using functions like Product :: getPriceStatic I get a critical error. Perhaps I should include any libraries?
 

d-shilko

Well-known member
☆☆ Special ☆☆
☆ Pro ☆
Joined
Jun 10, 2021
Messages
2,538
Reaction score
1,530
Points
113
NullCash
4,422
OK. Shortly.

Accessing the webservice use our PHP library

You will need the latest version of the PSWebServiceLibrary.php file, which can be found on our code repository: https://github.com/PrestaShop/PrestaShop-webservice-lib/blob/master/PSWebServiceLibrary.php
To download the file:

Click here to view the raw file: https://raw.github.com/PrestaShop/PrestaShop-webservice-lib/master/PSWebServiceLibrary.php
Copy/paste the file into an empty text local file, using for instance Notepad.
Save the file as PSWebServiceLibrary.php.
You can also directly download a zip archive of all the files in this repository, including the example files, by clicking here: https://github.com/PrestaShop/PrestaShop-webservice-lib/archive/master.zip

Put PSWebServiceLibrary.php at the root of your web server, and add this line at the beginning of any PHP file that needs to use your store's webservice.

Then, you must create an instance of the PrestaShopWebservice object, which takes 3 parameters in its constructor:

The store's root path (ex: http://example.com/ ).
The authentication key (ex: UCCLLQ9N2ARSHWCXLT74KUKSSK34BFKX).
A boolean value, indicating whether the webservice must use its debug mode.
Here's how you create a webservice call:

$webService = new PrestaShopWebservice('http://example.com/', 'UCCLLQ9N2ARSHWCXLT74KUKSSK34BFKX', false);



. Use hook of order confirmation in WordPress that named "woocommerce_thankyou"

// add classes to work with API
require_once(__ROOT__.'/PrestaShopWebservice.php');

$webService = new PrestaShopWebservice('http://your.site/', 'UCCLLQ9N2ARSHWCXLT74KUKSSK34BFKX', false);


add_action('woocommerce_thankyou', 'enroll_student', 10, 1);
function enroll_student( $order_id ) {
if ( ! $order_id )
return;

// Allow code execution only once
if( ! get_post_meta( $order_id, '_thankyou_action_done', true ) ) {

// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );

// Get the order key
$order_key = $order->get_order_key();

// Get the order number
$order_key = $order->get_order_number();

if($order->is_paid())
$paid = __('yes');
else
$paid = __('no');

//WooCommerce: Get Order Info (total, items, etc)
// https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/
//
// HERE getting customer and address from $order and put to $webService xml
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers/?schema=synopsis'));
// fill data to xml by $order
....
.....
....


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


// Loop through order items
foreach ( $order->get_items() as $item_id => $item ) {

// Get the product object
$product = $item->get_product();

// Get the product Id
$product_id = $product->get_id();

// Get the product name
$product_id = $item->get_name();

//here fill product to cart
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank'));
// fill data to xml
.....
.....
.....
}

// Output some data
echo '<p>Order ID: '. $order_id . ' — Order Status: ' . $order->get_status() . ' — Order is paid: ' . $paid . '</p>';

// Flag the action as done (to avoid repetitions on reload for example)
$order->update_meta_data( '_thankyou_action_done', true );
$order->save();

// CREATE Order
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank'));
}
}
Post automatically merged:

https://github.com/PrestaShop/PrestaShop-webservice-lib/archive/master.zip
There is U can see examples presta API
 
Last edited:

Vadim-1705

New member
XNullUser
Joined
Oct 7, 2021
Messages
9
Reaction score
0
Points
1
NullCash
23
Thanks!
I am able to create a shopping cart, but when creating an order, I get a fatal error. All required fields are filled in, I cannot understand what the problem is.
 

d-shilko

Well-known member
☆☆ Special ☆☆
☆ Pro ☆
Joined
Jun 10, 2021
Messages
2,538
Reaction score
1,530
Points
113
NullCash
4,422
Thanks!
I am able to create a shopping cart, but when creating an order, I get a fatal error. All required fields are filled in, I cannot understand what the problem is.
Maybe it is on Presta side. Perhaps overrides in Classes. Testing you code. Create subdomain on your hosting. Install PS version of PS on other site and with demo data. Test you code. But first ask owner of Prestashop regarding folder "override". Ask of archive of folder in question.

And add descript of error.
 

mare27

New member
XNullUser
Joined
Jul 25, 2022
Messages
5
Reaction score
0
Points
1
NullCash
3
thank you if the script will work with prestashop 1.7
 
Top