|
| 1 | +class ShippingZonesResponse { |
| 2 | + List<ShippingZone> shippingZones; |
| 3 | + |
| 4 | + ShippingZonesResponse({ |
| 5 | + required this.shippingZones, |
| 6 | + }); |
| 7 | + |
| 8 | + factory ShippingZonesResponse.fromJson(Map<String, dynamic> json) => ShippingZonesResponse( |
| 9 | + shippingZones: List<ShippingZone>.from(json["shipping_zones"].map((x) => ShippingZone.fromJson(x))), |
| 10 | + ); |
| 11 | + |
| 12 | + Map<String, dynamic> toJson() => { |
| 13 | + "shipping_zones": List<dynamic>.from(shippingZones.map((x) => x.toJson())), |
| 14 | + }; |
| 15 | +} |
| 16 | + |
| 17 | +class ShippingZone { |
| 18 | + int id; |
| 19 | + String name; |
| 20 | + String profileId; |
| 21 | + String locationGroupId; |
| 22 | + String adminGraphqlApiId; |
| 23 | + List<Country> countries; |
| 24 | + List<dynamic> weightBasedShippingRates; |
| 25 | + List<PriceBasedShippingRate> priceBasedShippingRates; |
| 26 | + List<dynamic> carrierShippingRateProviders; |
| 27 | + |
| 28 | + ShippingZone({ |
| 29 | + required this.id, |
| 30 | + required this.name, |
| 31 | + required this.profileId, |
| 32 | + required this.locationGroupId, |
| 33 | + required this.adminGraphqlApiId, |
| 34 | + required this.countries, |
| 35 | + required this.weightBasedShippingRates, |
| 36 | + required this.priceBasedShippingRates, |
| 37 | + required this.carrierShippingRateProviders, |
| 38 | + }); |
| 39 | + |
| 40 | + factory ShippingZone.fromJson(Map<String, dynamic> json) => ShippingZone( |
| 41 | + id: json["id"], |
| 42 | + name: json["name"], |
| 43 | + profileId: json["profile_id"], |
| 44 | + locationGroupId: json["location_group_id"], |
| 45 | + adminGraphqlApiId: json["admin_graphql_api_id"], |
| 46 | + countries: List<Country>.from(json["countries"].map((x) => Country.fromJson(x))), |
| 47 | + weightBasedShippingRates: List<dynamic>.from(json["weight_based_shipping_rates"].map((x) => x)), |
| 48 | + priceBasedShippingRates: List<PriceBasedShippingRate>.from(json["price_based_shipping_rates"].map((x) => PriceBasedShippingRate.fromJson(x))), |
| 49 | + carrierShippingRateProviders: List<dynamic>.from(json["carrier_shipping_rate_providers"].map((x) => x)), |
| 50 | + ); |
| 51 | + |
| 52 | + Map<String, dynamic> toJson() => { |
| 53 | + "id": id, |
| 54 | + "name": name, |
| 55 | + "profile_id": profileId, |
| 56 | + "location_group_id": locationGroupId, |
| 57 | + "admin_graphql_api_id": adminGraphqlApiId, |
| 58 | + "countries": List<dynamic>.from(countries.map((x) => x.toJson())), |
| 59 | + "weight_based_shipping_rates": List<dynamic>.from(weightBasedShippingRates.map((x) => x)), |
| 60 | + "price_based_shipping_rates": List<dynamic>.from(priceBasedShippingRates.map((x) => x.toJson())), |
| 61 | + "carrier_shipping_rate_providers": List<dynamic>.from(carrierShippingRateProviders.map((x) => x)), |
| 62 | + }; |
| 63 | +} |
| 64 | + |
| 65 | +class Country { |
| 66 | + int id; |
| 67 | + String name; |
| 68 | + double tax; |
| 69 | + String code; |
| 70 | + String taxName; |
| 71 | + int shippingZoneId; |
| 72 | + List<Province> provinces; |
| 73 | + |
| 74 | + Country({ |
| 75 | + required this.id, |
| 76 | + required this.name, |
| 77 | + required this.tax, |
| 78 | + required this.code, |
| 79 | + required this.taxName, |
| 80 | + required this.shippingZoneId, |
| 81 | + required this.provinces, |
| 82 | + }); |
| 83 | + |
| 84 | + factory Country.fromJson(Map<String, dynamic> json) => Country( |
| 85 | + id: json["id"], |
| 86 | + name: json["name"], |
| 87 | + tax: json["tax"]?.toDouble(), |
| 88 | + code: json["code"], |
| 89 | + taxName: json["tax_name"], |
| 90 | + shippingZoneId: json["shipping_zone_id"], |
| 91 | + provinces: List<Province>.from(json["provinces"].map((x) => Province.fromJson(x))), |
| 92 | + ); |
| 93 | + |
| 94 | + Map<String, dynamic> toJson() => { |
| 95 | + "id": id, |
| 96 | + "name": name, |
| 97 | + "tax": tax, |
| 98 | + "code": code, |
| 99 | + "tax_name": taxName, |
| 100 | + "shipping_zone_id": shippingZoneId, |
| 101 | + "provinces": List<dynamic>.from(provinces.map((x) => x.toJson())), |
| 102 | + }; |
| 103 | +} |
| 104 | + |
| 105 | +class Province { |
| 106 | + int id; |
| 107 | + int countryId; |
| 108 | + String name; |
| 109 | + String code; |
| 110 | + int tax; |
| 111 | + TaxName taxName; |
| 112 | + String? taxType; |
| 113 | + int taxPercentage; |
| 114 | + int shippingZoneId; |
| 115 | + |
| 116 | + Province({ |
| 117 | + required this.id, |
| 118 | + required this.countryId, |
| 119 | + required this.name, |
| 120 | + required this.code, |
| 121 | + required this.tax, |
| 122 | + required this.taxName, |
| 123 | + this.taxType, |
| 124 | + required this.taxPercentage, |
| 125 | + required this.shippingZoneId, |
| 126 | + }); |
| 127 | + |
| 128 | + factory Province.fromJson(Map<String, dynamic> json) => Province( |
| 129 | + id: json["id"], |
| 130 | + countryId: json["country_id"], |
| 131 | + name: json["name"], |
| 132 | + code: json["code"], |
| 133 | + tax: json["tax"], |
| 134 | + taxName: taxNameValues.map[json["tax_name"]]!, |
| 135 | + taxType: json["tax_type"], |
| 136 | + taxPercentage: json["tax_percentage"], |
| 137 | + shippingZoneId: json["shipping_zone_id"], |
| 138 | + ); |
| 139 | + |
| 140 | + Map<String, dynamic> toJson() => { |
| 141 | + "id": id, |
| 142 | + "country_id": countryId, |
| 143 | + "name": name, |
| 144 | + "code": code, |
| 145 | + "tax": tax, |
| 146 | + "tax_name": taxNameValues.reverse[taxName], |
| 147 | + "tax_type": taxType, |
| 148 | + "tax_percentage": taxPercentage, |
| 149 | + "shipping_zone_id": shippingZoneId, |
| 150 | + }; |
| 151 | +} |
| 152 | + |
| 153 | +enum TaxName { VAT, TAX, PST, RST, HST, QST, THE_00, SST, GST, STATE_TAX, GRT } |
| 154 | + |
| 155 | +final taxNameValues = EnumValues({ |
| 156 | + "GRT": TaxName.GRT, |
| 157 | + "GST": TaxName.GST, |
| 158 | + "HST": TaxName.HST, |
| 159 | + "PST": TaxName.PST, |
| 160 | + "QST": TaxName.QST, |
| 161 | + "RST": TaxName.RST, |
| 162 | + "SST": TaxName.SST, |
| 163 | + "State Tax": TaxName.STATE_TAX, |
| 164 | + "Tax": TaxName.TAX, |
| 165 | + "0.0": TaxName.THE_00, |
| 166 | + "VAT": TaxName.VAT |
| 167 | +}); |
| 168 | + |
| 169 | +class PriceBasedShippingRate { |
| 170 | + int id; |
| 171 | + String name; |
| 172 | + String price; |
| 173 | + int shippingZoneId; |
| 174 | + String minOrderSubtotal; |
| 175 | + dynamic maxOrderSubtotal; |
| 176 | + |
| 177 | + PriceBasedShippingRate({ |
| 178 | + required this.id, |
| 179 | + required this.name, |
| 180 | + required this.price, |
| 181 | + required this.shippingZoneId, |
| 182 | + required this.minOrderSubtotal, |
| 183 | + this.maxOrderSubtotal, |
| 184 | + }); |
| 185 | + |
| 186 | + factory PriceBasedShippingRate.fromJson(Map<String, dynamic> json) => PriceBasedShippingRate( |
| 187 | + id: json["id"], |
| 188 | + name: json["name"], |
| 189 | + price: json["price"], |
| 190 | + shippingZoneId: json["shipping_zone_id"], |
| 191 | + minOrderSubtotal: json["min_order_subtotal"], |
| 192 | + maxOrderSubtotal: json["max_order_subtotal"], |
| 193 | + ); |
| 194 | + |
| 195 | + Map<String, dynamic> toJson() => { |
| 196 | + "id": id, |
| 197 | + "name": name, |
| 198 | + "price": price, |
| 199 | + "shipping_zone_id": shippingZoneId, |
| 200 | + "min_order_subtotal": minOrderSubtotal, |
| 201 | + "max_order_subtotal": maxOrderSubtotal, |
| 202 | + }; |
| 203 | +} |
| 204 | + |
| 205 | +class EnumValues<T> { |
| 206 | + Map<String, T> map; |
| 207 | + late Map<T, String> reverseMap; |
| 208 | + |
| 209 | + EnumValues(this.map); |
| 210 | + |
| 211 | + Map<T, String> get reverse { |
| 212 | + reverseMap = map.map((k, v) => MapEntry(v, k)); |
| 213 | + return reverseMap; |
| 214 | + } |
| 215 | +} |
0 commit comments