Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Enhancing Resource to Read From Other (RFO)

Enhancing Resource to Read From Other (RFO)

Warning: Before you begin

This tutorial assumes you have created the terms and conditions resource in the Writing Your First Resource section and linked to it from the orders resource in Adding Links to Your Resource.

Read From Other (RFO) is a powerful Cortex capability that enables your custom resource to read data from another resource. Using RFOs, you can re-use another resource's functionality, instead of building that functionality from scratch. The totals resource is a good example of an RFO. totals uses an RFO to read a cart's lineitems, so it can process those lineitems and surface up the total cost of the items in the cart.

In this tutorial, you will learn how to:
  • Create an RFO to read data from another resource.

This tutorial enhances the terms and conditions resource you built in Writing Your First Resource to retrieve orders entity information using an RFO. After completing this tutorial, you can follow a link on the orders resource and see the terms and conditions resource, which will display the Order ID that was read from the orders resource.

Retrieving Order Information from Terms

We will add an RFO to the terms-and-conditions resource to read the Order ID from the orders resource. When you retrieve the terms and conditions resource, the Order ID will display in the message field.

The order representation with a link to the terms and conditions resource:
{
  "self": {
    "type": "elasticpath.orders.order",
    "uri": "/commerce-legacy/orders/{scope}/{order-id}",
    "href": "http://localhost:9080/cortex/orders/{scope}/{order-id}"
  },
  "links": [
    ...
    {
        "rel":"terms",
        "type":"{vendor}.terms.terms-and-conditions",
        "uri":"/commerce-legacy/terms/orders/{scope}/{order-id}",
        "href":"http://localhost:9080/cortex/terms/orders/{scope}/{order-id}"
    },
    ...
  ]
}
terms and conditions resource with Order ID in the message field:
{
   self: {
      type: "{vendor}.terms.terms-and-conditions",
      uri: "/commerce-legacy/terms/orders/{scope}/{order-id}",
      href: "http://localhost:9080/cortex/terms/orders/{scope}/{order-id}",
   },
   message: "An example terms and conditions string for order {order-id}",
   links: [ ]
}