For ATG related classes, managers, and objects, the object requests are received in chunks with a strict understanding of the expected response object. The general pattern for parsing in ATG is for the manager to

The object construction is completed with a category on NSObject which iterates over the JSON object and attempts to set any of its values into the object the Manager intends to create.

In general, parsing is performed by each model object. In the following example, getProfile is used to create the empty profile object, then, if it is not in the cache, it is fetched. When retrieving a profile object that is not already cached, this is performed:

ATGProfile *profile = (ATGProfile *)[ATGProfile objectFromDictionary:[pResponseObject objectForKey:@"profile"]];

This means CRS-IUA is constructing the new profile object from the profile object that is specified in the JSON response by key value pairs.

The NSObject+ATGRestAdditions category has the objectFromDictionary method, and this does the work of setting the values in the dictionary to their corresponding properties and members on the ATGProfile model object.

Commerce Manager Example - Fetch Cart

Use Commerce Manager to request the content of a named user’s shopping cart. A JSON object is returned back to Commerce Manager which creates a Cart with the returned JSON object if the cart is found. The transformation of JSON into a Cart object occurs within a category on NSObject which traverses the JSON response and adds properties to the object. The Cart object is returned back to the requester that made the original request to the manager, for example, the shopping cart view controller. For example:

ATGOrder *cart = (ATGOrder *)[ATGOrder objectFromDictionary:[pResponseObject objectForKey:@"order"]];

Where “order” would be:

{"order": {
  "id": "o330006",
  "containsGiftWrap": false,
  "shippingGroupCount": 1,
  "priceInfo": {
    "amount": 339.99,
    "total": 339.99,
    "shipping": 0,
    "currencyCode": "USD",
    "tax": 0,
    "rawSubtotal": 349.99,
    "discountAmount": 10,
    "adjustments": [{
      "pricingModel": "$10 off Orders over $100",
      "coupon": null
    }]
  },
  "commerceItems": [
    {
      "id": "ci2000005",
      "productDisplayName": "Leather Jacket",
      "auxiliaryData": {
        "siteId": "mobileStoreSiteUS",
        "productRef": {
          "description": "Classic and stylish.",
          "largeImageUrl": "/crsdocroot/content/images/products/large/APP_LeatherJacket_large.jpg",
          "longDescription": "This leather jacket is a must-have for cold-weather wardrobes. It's classically styled featuring 100% genuine leather, a full zip front, and a full lining with two interior pockets. Professional cleaning only!",
          "isNavigableProduct": true,
          "mediumImageUrl": "/crsdocroot/content/images/products/medium/APP_LeatherJacket_medium.jpg",
          "fullImageUrl": "/crsdocroot/content/images/products/full/APP_LeatherJacket_full.jpg",
          "displayName": "Leather Jacket",
          "repositoryId": "prod20019",
          "thumbnailImageUrl": "/crsdocroot/content/images/products/thumb/APP_LeatherJacket_thumb.jpg"
        },
        "siteName": "ATG Mobile Store",
        "catalogRef": {
          "color": "Black",
          "displayName": "Leather Jacket",
          "type": "clothing-sku",
          "colorSwatchUrl": "/crsdocroot/content/images/catalog/color-black.gif",
          "repositoryId": "sku40151",
          "size": "M"
        },
        "productId": "prod20019"
      },
      "priceInfo": {
        "amount": 349.99,
        "currencyCode": "USD",
        "listPrice": 349.99,
        "currentPriceDetailsSorted": [{
          "amount": 349.99,
          "currencyCode": "USD",
          "quantity": 1,
          "detailedUnitPrice": 349.99
        }],
        "adjustments": []
      },
      "quantity": 1,
      "catalogRefId": "sku40151",
      "productId": "prod20019"
    },
    {
      "id": "ci2000006",
      "productDisplayName": "Cashmere Scarf",
      "auxiliaryData": {
        "siteId": "mobileStoreSiteUS",
        "productRef": {
          "description": "Add sophistication to your cold-weather look.",
          "largeImageUrl": "/crsdocroot/content/images/products/small/APP_CashmereScarf_small.jpg",
          "longDescription": "Add a dose of sophistication to your cold-weather look. This cashmere scarf is luxury for everyday use.",
          "isNavigableProduct": false,
          "mediumImageUrl": "/crsdocroot/content/images/products/small/APP_CashmereScarf_small.jpg",
          "fullImageUrl": "/crsdocroot/content/images/products/small/APP_CashmereScarf_small.jpg",
          "displayName": "Cashmere Scarf",
          "repositoryId": "xprod40028",
          "thumbnailImageUrl": "/crsdocroot/content/images/products/small/APP_CashmereScarf_small.jpg"
        },
        "siteName": "ATG Mobile Store",
        "catalogRef": {
          "color": "Dark Blue",
          "displayName": "Cashmere Scarf",
          "type": "clothing-sku",
          "colorSwatchUrl": "/crsdocroot/content/images/catalog/color-dark-blue.gif",
          "repositoryId": "xsku60325",
          "size": "One Size"
        },
        "productId": "xprod40028"
      },
      "priceInfo": {
        "amount": 0,
        "currencyCode": "USD",
        "listPrice": 0,
        "currentPriceDetailsSorted": [{
          "amount": 0,
          "currencyCode": "USD",
          "quantity": 1,
          "detailedUnitPrice": 0
        }],
        "adjustments": [{
          "pricingModel": "Free Scarf with all orders over $200",
          "coupon": null
        }]
      },
      "quantity": 1,
      "catalogRefId": "xsku60325",
      "productId": "xprod40028"
    }
  ],
  "totalCommerceItemCount": 2
}}

Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices