Line.fromGraphJson constructor

Line.fromGraphJson(
  1. Map<String, dynamic> json
)

The cart line from json

Implementation

factory Line.fromGraphJson(Map<String, dynamic> json) {
  Map<String, dynamic> nodeJson = json['node'] ?? {};
  return Line(
    id: nodeJson['id'],
    quantity: nodeJson['quantity'],
    cost: nodeJson['cost'] != null
        ? CartLineCost.fromJson(nodeJson['cost'])
        : null,
    merchandise: nodeJson['merchandise'] != null
        ? ProductVariant.fromJson(nodeJson['merchandise'])
        : null,
    variantId: nodeJson['merchandise'] != null
        ? ProductVariant.fromJson(nodeJson['merchandise']).id
        : null,
    discountAllocations: (nodeJson['discountAllocations'] != null &&
            nodeJson['discountAllocations'] is List)
        ? (nodeJson['discountAllocations'] as List)
            .map((e) => CartDiscountAllocation.fromJson(e))
            .toList()
        : null,
  );
}