Coupon.fromJson constructor
Implementation
Coupon.fromJson(Map<String, dynamic> json) {
try {
amount = double.parse(json['amount'].toString());
code = json['code'];
id = json['id']?.toString();
discountType = json['discount_type'];
description = json['description'];
minimumAmount = json['minimum_amount'] != null
? double.parse(json['minimum_amount'].toString())
: 0.0;
maximumAmount = json['maximum_amount'] != null
? double.parse(json['maximum_amount'].toString())
: 0.0;
dateExpires = json['date_expires'] != null
? DateTime.parse(json['date_expires'])
: null;
message = '';
usageCount = json['usage_count'];
individualUse = json['individual_use'] ?? false;
usageLimit = json['usage_limit'];
usageLimitPerUser = json['usage_limit_per_user'];
freeShipping = json['free_shipping'] ?? false;
excludeSaleItems = json['exclude_sale_items'] ?? false;
if (json['product_ids'] != null) {
productIds = [];
json['product_ids'].forEach((e) {
productIds.add(e.toString());
});
}
if (json['excluded_product_ids'] != null) {
excludedProductIds = [];
json['excluded_product_ids'].forEach((e) {
excludedProductIds.add(e.toString());
});
}
if (json['product_categories'] != null) {
productCategories = [];
json['product_categories'].forEach((e) {
productCategories.add(e.toString());
});
}
if (json['excluded_product_categories'] != null) {
excludedProductCategories = [];
json['excluded_product_categories'].forEach((e) {
excludedProductCategories.add(e.toString());
});
}
if (json['email_restrictions'] != null) {
emailRestrictions = [];
json['email_restrictions'].forEach((e) {
emailRestrictions.add(e.toString());
});
}
if (json['used_by'] != null) {
usedBy = [];
json['used_by'].forEach((e) {
usedBy!.add(e.toString());
});
}
} catch (e) {
// ignore: avoid_print
print(e.toString());
}
}