Coupon.fromShopify constructor
Coupon.fromShopify(
- Map<String, dynamic> json
)
Implementation
Coupon.fromShopify(Map<String, dynamic> json) {
final List? listCouponApply = json['edges'];
var info = {};
if (listCouponApply?.isNotEmpty ?? false) {
info = listCouponApply![0]['node'] ?? {};
}
if (info['applicable'] == false) {
info = {};
}
try {
code = info['code'];
id = info['code'];
amount = 0;
final infoCoupon = info['value'] ?? {};
if (infoCoupon['__typename'] == 'MoneyV2') {
discountType = CouponType.fixedAmount;
amount = double.tryParse(infoCoupon['amount'] ?? '0');
} else if (infoCoupon['__typename'] == 'PricingPercentageValue') {
discountType = CouponType.percentage;
amount = infoCoupon['percentage'];
}
description = '';
minimumAmount = 0.0;
maximumAmount = 0.0;
dateExpires = null;
message = 'Hello';
} catch (e) {
// ignore: avoid_print
print(e.toString());
}
}