The are multiple endpoints available for accessing and update the EthosCE cart.most common configuration for e-commerce integration is where EthosCE tracks and records the user's cart information, to be retrieved later by an external checkout system.
A typical workflow is as follows:
- User is logged into EthosCE
- User adds a product, or products, to cart
- User navigates to their cart, and clicks check out
- User is redirected to external cart
- External cart queries EthosCE web services to obtain the list of products in the user's cart
- User completes check out on external cart
- External cart enrolls user in purchased courses via EthosCE web services
- External cart deletes products from cart via EthosCE web services
The steps which require interaction with EthosCE are:
Table of Contents | ||||
---|---|---|---|---|
|
...
|
Checking the user's cart
A user's cart information is stored as the individual items they've placed in their cart. In EthosCE terms, it is the list of cart items currently assigned to the user's cart id (their uid). A call to the uc_cart_item endpoint, filtering by cart id will display a list of all items currently in their cart.
Code Block | ||||
---|---|---|---|---|
| ||||
<?php // Login to the site and request the access token $curl = curl_init('http://74.localhost/restws/session/token'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); // Your web service user credentials goes here. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $token = curl_exec($curl); // The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%" // Send the user creation request, via POST $data = array( 'cart_id' => 213, // The user's uid 'nid' => 70, // The product's nid 'qty' => 1, ); $curl = curl_init("http://74.localhost/uc_cart_item.json?cart_id=213"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POSTDELETE'); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); $json = curl_exec($curl); $response = json_decode($json); print_r($response); |
Creating an EthosCE order
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php // Login to the site and request the access token $curl = curl_init('"http://74.localhost/restws/session/token'); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); // Your web service user credentials goes here. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $token uc_cart_item/37"); $json = curl_exec($curl); // The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%" // Send the creation request, via POST $uc_order = array( "uid" => 213, "customer" => 213, // The user's uid "delivery_address" => array( "first_name" => "Tom", "last_name" => "Baker", "company" => "DLC", "street1" => "1520 Locust", "street2" => "Suite 1000", "city" => "Philadelphia", "postal_code" => "19102", "phone" => "215-321-1234", "email" => "webservice_user@dlcdev.com" ), "billing_address" => array( "first_name" => "WS First", "last_name" => "WS Last", "company" => "DLC", "street1" => "1520 Locust", "street2" => "Suite 1000", "city" => "Philadelphia", "postal_code" => "19102", "phone" => "215-321-1234", "email" => "webservice_user@dlcdev.com" ), "order_status" => "completed", "order_total" => 250.00, "primary_email" => "webservice_user@dlcdev.com", "payment_method" => "", "created" => 1471452801, // Unix UTC Timestamp "modified" => 1471452801, // Unix UTC Timestamp "host" => "127.0.0.1", ); $curl = curl_init("http://74.localhost/uc_order"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials goes here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($uc_order)); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); $json = curl_exec($curl); $response = json_decode($json); $response = json_decode($json); print_r($response); |
Enrolling the user in their purchased courses
A detailed explanation of enrolling a user in a course is found on the page, Enrolling a user via web service. In the context of this request, the course node ids to be used in the enrollment calls are
Clearing the cart of data
Start