These are in a fairly good spot, but we still need a simplified way to communicate product data along with the product display. This will allow clients access to all the information they need to build a product display / Add to Cart form without requiring two separate API requests (one to get the display node data and another to get the actual product data). An example response might be:
{
nid: 1,
title: "Laptop Bag 231",
products: [
{ product_id: 5, sku: "AWEF", price: "$52", images: ["http://example.com/image1.jpg"] }
]
}
Where instead of "products" we might use the actual field name of the product reference field (e.g. "field_product"). It might be that we can simply standardize on this behavior for any Drupal Commerce reference field, providing the same behavior for product references, line item references, and customer profile references.
Comments
Comment #1
rszrama commentedAlrighty - the remaining issue has been addressed, though with a slightly different approach. I realized that it's in our best interest to not destroy the field data, as then the entity can no longer be wrapped or manipulated as expected by the Field API. Much better to simply add a corresponding property to the entity that contains the full entities.
So, I've added a parameter to read requests called expand_entities that defaults to "expanding" the reference field values on the immediate entity into an array of full entities keyed by ID. It only goes to that first depth by default, but you can pass a value greater than 1 to expand the reference field values of child entities as well.
The return value would look more like this:
Note that this is only a subset of the data that would be returned to demonstrate three things:
I'm up for more ideas along these lines. I'm also considering changing entity expansion to actually use an array, so you can specify what types of entity reference fields should be expanded (along the lines of
expand_field_product=1 / expand[field_product]=1or something similar. I'm not decided. There may be other helper attributes we can decorate entities with - for example, I haven't played around with taxonomy term reference fields at all in relation to these resources yet.Commit: http://drupalcode.org/project/commerce_services.git/commitdiff/0afd975
Comment #2
sumitk commentedTwo requests: