toPageViewData method

PageViewData toPageViewData()

Implementation

PageViewData toPageViewData() {
  final billData =
      bill != null
          ? BillData(
            billId: bill!.billId,
            customerId: bill!.customerId,
            total: bill!.total,
            country: bill!.country,
            cip: bill!.cip,
            city: bill!.city,
          )
          : null;

  final loginData =
      login != null
          ? LoginData(
            userId: login!.userId,
            resultCode: login!.resultCode,
            scramble: login!.scramble,
          )
          : null;

  final registerData =
      register != null
          ? RegisterData(
            userId: register!.userId,
            resultCode: register!.resultCode,
            scramble: register!.scramble,
          )
          : null;

  final searchData =
      search != null
          ? SearchData(
            queryString: search!.queryString,
            numberOfHits: search!.numberOfHits,
          )
          : null;

  final targetData =
      target != null
          ? TargetData(
            target: target!.target,
            additionalInfo: target!.additionalInfo,
            score: target!.score,
            rule: target!.rule,
          )
          : null;

  final productEventsData =
      productEvents.map((productEvent) {
        final item = BasketItemData(
          productId: productEvent.item.productId,
          productName: productEvent.item.productName,
          sku: productEvent.item.sku,
          productGroup: productEvent.item.productGroup,
          variants: productEvent.item.variants,
          price: productEvent.item.price,
          quantity: productEvent.item.quantity,
        );

        return ProductEventData(
          eventType: productEvent.eventType,
          item: item,
        );
      }).toList();

  final customStringProperties = Map.fromEntries(
    customProperties.entries
        .where((entry) => entry.value is String)
        .map((entry) => MapEntry(entry.key, entry.value as String)),
  );

  final customIntProperties = Map.fromEntries(
    customProperties.entries
        .where((entry) => entry.value is int)
        .map((entry) => MapEntry(entry.key, entry.value as int)),
  );

  final customDoubleProperties = Map.fromEntries(
    customProperties.entries
        .where((entry) => entry.value is double)
        .map((entry) => MapEntry(entry.key, entry.value as double)),
  );

  final customBoolProperties = Map.fromEntries(
    customProperties.entries
        .where((entry) => entry.value is bool)
        .map((entry) => MapEntry(entry.key, entry.value as bool)),
  );

  final data = PageViewData(
    bill: billData,
    campaign: campaign,
    contactType: contactType,
    content: content,
    countryId: countryId,
    download: download,
    intern: intern,
    login: loginData,
    langId: langId,
    marker: marker,
    marketingChannel: marketingChannel,
    orderProcess: orderProcess,
    register: registerData,
    search: searchData,
    siteId: siteId,
    source: source,
    target: targetData,
    productEvents: productEventsData,
    customStringProperties: customStringProperties,
    customIntProperties: customIntProperties,
    customDoubleProperties: customDoubleProperties,
    customBoolProperties: customBoolProperties,
  );

  return data;
}