Jump to content

Adding tracking number to order through web service


fraizor

Recommended Posts

I had been hitting my head with the wall for the previous 3 days trying to add a tracking code to an order through Prestashop webservice 

image.png.ccb5a11fb69912b539f549fae6f44308.png

 

 

i tried POST and MODIFY requests but non are working 

 

every request i try either return the need of a unrelated data, or it caused the order page to crash ! 

PUT/POST request (causes the order page in BO to crash ! )

<prestashop>\n\t<order>\n\t\t<shipping_number>123</shipping_number><id_address_delivery>12352</id_address_delivery><id_address_invoice>12352</id_address_invoice><id_cart>26565</id_cart><id_currency>3</id_currency><id_lang>1</id_lang><id_customer>14186</id_customer><id_carrier>48</id_carrier><module>codwfeeplus</module><payment>Cash on delivery with fee (COD) PLUS</payment><total_paid>0.000000</total_paid><total_paid_real>0.000000</total_paid_real><total_products>0.400000</total_products><total_products_wt>0.420000</total_products_wt><conversion_rate>1.000000</conversion_rate><id>13430</id>\n\t</order>\n</prestashop>

 

 

 

any one have a sample code of editing order's tracking code ? 

Link to comment
Share on other sites

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

@fraizor

To add a tracking number to an order using the PrestaShop web service, please review the code provided below.

Create a new PHP file and paste the below code:
 

<?php

// Configuration
define('PS_SHOP_PATH', '{{YOUR_STORE_URL}}');  // Replace with your store URL
define('PS_WS_AUTH_KEY', '{{YOUR_STORE_AUTH_KEY}}');  // Replace with your store’s API key

require_once('./PSWebServiceLibrary.php');  // Include PrestaShop Web Service Library

try {
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, false);

    // Specify the order carrier ID to update
    $orderCarrierId = {{ORDER_CARRIER_ID}};  // Replace with the actual order carrier ID
    
    // Retrieve the order carrier resource
    $opt = array(
        'resource' => 'order_carriers',
        'id' => $orderCarrierId
    );
    $xml = $webService->get($opt);

    // Update the tracking number in the XML
    $xml->order_carrier->tracking_number = {{TRACKING_NUMBER}};  // Replace with the tracking number
    
    // Send the updated XML back to the web service
    $opt = array(
        'resource' => 'order_carriers',
        'id' => $orderCarrierId,
        'putXml' => $xml->asXML()
    );
    $webService->edit($opt);

    echo "Tracking number updated successfully!";

} catch (PrestaShopWebserviceException $ex) {
    echo 'Error: '. $ex->getMessage();
}

?>


Enable the web service in the PrestaShop back office if it has not already been enabled.

This solution should help you add tracking numbers successfully!
 

  • Like 1
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...