How to set up a checkout redirect on your Kreezalid online marketplace

Article by Kreezalid - 30 Nov 2021 - 4 minute read

Learn how to set up a checkout redirect on your Kreezalid online marketplace

Build your online marketplace today!

Benefit from a 7-day free trial, with no obligation or payment card

Important point: at the moment, it is mandatory to make a request to Kreezalid to integrate the script on its site.

Forwarding to a delivery service when checkout an order is possible on a kreezalid marketplace.

This redirection is done through a script that you will have to write in the index of your site.

There are different steps to follow to set up this redirection.

PS: The examples shown in this article show how to create a redirect to the Mondial Relay delivery service, but this works with all other delivery services.

The steps in this procedure will make you add PHP code directly to your index.

(If you start this procedure, please let us know so that we can act in case of problems.) -> not sure about this one

Step 1: Configuration

First, you will need to define variables essential to this redirection. Here is the list of these variables:
-API_KEY
-API_SECRET
-API_BASE_URL
-MONDIAL_RELAY_ID (to be changed by the delivery system you wish to integrate)
-MONDIAL_RELAY_BRAND (same as above)


Step 2: Extract the id from the commands

In this step, you will need to write the code that will allow you to retrieve the id(s) of the different orders from your site’s shopping cart.


Step 3: Connect to the Kreezalid API

In this step, you will connect to our API using the elements you have initiated in the first step. Here is an example of this connection:

$kreezalidApiClient = new Kreezalid KreezalidApi();
$kreezalidApiClient->Config->setApiSecret(API_SECRET);
$kreezalidApiClient->Config->setApiKey(API_KEY);
$kreezalidApiClient->Config->setApiUrl(API_BASE_URL);


Step 4: Retrieve Order Information

In this step, you will need to retrieve the command information using the id you extracted in step 2. This extraction can be done using the following for each loop:

$orders = [ ];
foreach ($orderIDs as $_orderID) {
$orders[ ] = $kreezalidApiClient->Orders->get($_orderID);
}

 

unset($orderIDs);

 

Note that we empty our $order_ID after retrieving the order information from a newly created array.


Step 5: Check if the delivery method chosen is the one you are setting up (Mondial Relay for our example)

In this step, you will need to verify that the delivery system is the one to which the customer has been redirected. To do this, you will have to again use a loop for each that will scan the command information you retrieved in the previous step. Here is an example of the code required for this step:

 
foreach ($orders as $order) {
    if(is_array($order->shippings) && !empty($order->shippings)) {
        if($order->status === 'draft' && $order->shippings['id'] === MONDIAL_RELAY_ID) {
            $ordersWithMondialRelay[] = $order;
            if(
                    isset($order->shippings['address'])
                    && !empty($order->shippings['address'])
                    && isset($order->shippings['address']['postcode'])
            ) {
                $defaultPostCode = $order->shippings['address']['postcode'];
            }
        }
    }
}

unset($orders);


Step 6: Display the map that allows you to choose your relay point

In this step, you will need to check if there is at least one order that uses the delivery system to whom you want to redirect your customers. If this is the case, you will need to make sure to display the map showing the available relay points.


Step 7: Save the selected relay point and verification in the metadata

In this step, you will have to make sure to save the relay point chosen by the user and store the information of this point in the metadata of your site.


Step 8: Redirecting to checkout

In this step, you will configure the redirection to the checkout page by adding this piece of code to your index:

header('Location: ' . $redirect_url);
exit;

Do not forget to load the elements necessary for this redirection (Jquery, Leaflet and the widget of your delivery method) in your code.

Kreezalid
About Kreezalid

Discover the best tools and marketing tips to manage and grow your online marketplace