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.

Adding Links to Your Resource

Adding Links to Your Resource

Warning: Before you begin

This tutorial assumes you have created the terms and conditions resource in Writing Your First Resource.

Links are a powerful way to enhance a resource's capability without having to change the resource's code. For example, to create an enhancement for the carts resource, you can create a new resource to provide this functionality and then attached a link on the carts resource that links to your new resource. Cortex uses links in many of its resources, items links to itemdefinitions where item descriptions are, carts link to totals where the total costs for the carts are, and so on.

In this tutorial, you will learn how to:
  • Add a link from one resource to another.

This tutorial enhances the terms and conditions resource you created in Writing Your First Resource by linking to it from the orders resource. After completing the tutorial, you can view the terms and conditions resource by following the link on the orders resource.

Linking from Orders to Terms and Conditions

We will add a link on the orders resource that links to the terms and conditions resource, so a client application can retrieve the terms and conditions for an order by following or zooming into the link. The order representation with the link should look as follows:
{
  "self": {
    "type": "elasticpath.orders.order",
    "uri": "/commerce-legacy/orders/{scope}/{order-id}",
    "href": "http://localhost:9080/cortex/orders/mobee/<an-order-id>"
  },
  "links": [
    ...
    {
        "rel":"terms",
        "type":"elasticpath.terms.terms-and-conditions",
        "uri":"/commerce-legacy/terms/id=",
        "href":"http://localhost:9080/cortex/terms/id="
    },
    ...
  ]
}