Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

The 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:

  1. User is logged into EthosCE
  2. User adds a product, or products, to cart
  3. User navigates to their cart, and clicks check out
  4. User is redirected to external cart
  5. External cart queries EthosCE web services to obtain the list of products in the user's cart
  6. User completes check out on external cart
  7. External cart enrolls user in purchased courses via EthosCE web services
  8. External cart deletes products from cart via EthosCE web services

The steps which require interaction with EthosCE are:

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.

Adding a uc_cart_item
<?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, 'DELETE');
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"));
$curl = curl_init("http://74.localhost/uc_cart_item/37");
$json = curl_exec($curl);
$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

  • No labels