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'] ?? {};
  final ProductVariant? merchandise = nodeJson['merchandise'] != null
      ? ProductVariant.fromGraphJson(
          nodeJson['merchandise'],
          forceParse: true,
        )
      : null;
  return Line(
    id: nodeJson['id'],
    quantity: nodeJson['quantity'],
    cost: nodeJson['cost'] != null
        ? CartLineCost.fromJson(nodeJson['cost'])
        : null,
    merchandise: merchandise,
    variantId: merchandise?.id,
    discountAllocations: (nodeJson['discountAllocations'] != null &&
            nodeJson['discountAllocations'] is List)
        ? (nodeJson['discountAllocations'] as List)
            .map((e) => CartDiscountAllocation.fromJson(e))
            .toList()
        : null,
    sellingPlanAllocation: nodeJson['sellingPlanAllocation'] != null
        ? SellingPlanAllocation.fromJson(nodeJson['sellingPlanAllocation'])
        : null,
  );
}