refactor, pubspec.yaml update
This commit is contained in:
parent
83f6b609be
commit
b5051f2d90
@ -1,3 +1,7 @@
|
|||||||
|
## [2.0.0] - 2020-03-29
|
||||||
|
|
||||||
|
* Bug fixes, refactor, pubspec.yaml update
|
||||||
|
|
||||||
## [1.0.1] - 2020-02-12
|
## [1.0.1] - 2020-02-12
|
||||||
|
|
||||||
* Bug fixes, pubspec.yaml update, rm podfile
|
* Bug fixes, pubspec.yaml update, rm podfile
|
||||||
|
|||||||
@ -16,11 +16,13 @@ import 'package:label_storemax/labelconfig.dart';
|
|||||||
import 'package:edge_alert/edge_alert.dart';
|
import 'package:edge_alert/edge_alert.dart';
|
||||||
import 'package:label_storemax/models/billing_details.dart';
|
import 'package:label_storemax/models/billing_details.dart';
|
||||||
import 'package:label_storemax/models/cart.dart';
|
import 'package:label_storemax/models/cart.dart';
|
||||||
|
import 'package:label_storemax/models/cart_line_item.dart';
|
||||||
import 'package:label_storemax/models/checkout_session.dart';
|
import 'package:label_storemax/models/checkout_session.dart';
|
||||||
import 'package:label_storemax/models/payment_type.dart';
|
import 'package:label_storemax/models/payment_type.dart';
|
||||||
import 'package:html/parser.dart';
|
import 'package:html/parser.dart';
|
||||||
import 'package:flutter_web_browser/flutter_web_browser.dart';
|
import 'package:flutter_web_browser/flutter_web_browser.dart';
|
||||||
import 'package:flutter_money_formatter/flutter_money_formatter.dart';
|
import 'package:flutter_money_formatter/flutter_money_formatter.dart';
|
||||||
|
import 'package:math_expressions/math_expressions.dart';
|
||||||
import 'package:status_alert/status_alert.dart';
|
import 'package:status_alert/status_alert.dart';
|
||||||
import 'package:woosignal/models/response/tax_rate.dart';
|
import 'package:woosignal/models/response/tax_rate.dart';
|
||||||
import 'package:woosignal/woosignal.dart';
|
import 'package:woosignal/woosignal.dart';
|
||||||
@ -202,3 +204,153 @@ checkout(
|
|||||||
Cart cart = Cart.getInstance;
|
Cart cart = Cart.getInstance;
|
||||||
return await completeCheckout(cartTotal, billingDetails, cart);
|
return await completeCheckout(cartTotal, billingDetails, cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double strCal({@required String sum}) {
|
||||||
|
Parser p = Parser();
|
||||||
|
Expression exp = p.parse(sum);
|
||||||
|
ContextModel cm = ContextModel();
|
||||||
|
return exp.evaluate(EvaluationType.REAL, cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<double> workoutShippingCostWC({@required String sum}) async {
|
||||||
|
List<CartLineItem> cartLineItem = await Cart.getInstance.getCart();
|
||||||
|
sum = sum.replaceAllMapped(defaultRegex(r'\[qty\]', strict: true), (replace) {
|
||||||
|
return cartLineItem.length.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
String orderTotal = await Cart.getInstance.getSubtotal();
|
||||||
|
|
||||||
|
sum = sum.replaceAllMapped(defaultRegex(r'\[fee(.*)]'), (replace) {
|
||||||
|
if (replace.groupCount < 1) {
|
||||||
|
return "()";
|
||||||
|
}
|
||||||
|
String newSum = replace.group(1);
|
||||||
|
|
||||||
|
// PERCENT
|
||||||
|
String percentVal = newSum.replaceAllMapped(
|
||||||
|
defaultRegex(r'percent="([0-9\.]+)"'), (replacePercent) {
|
||||||
|
if (replacePercent != null && replacePercent.groupCount >= 1) {
|
||||||
|
String strPercentage = "( (" +
|
||||||
|
orderTotal.toString() +
|
||||||
|
" * " +
|
||||||
|
replacePercent.group(1).toString() +
|
||||||
|
") / 100 )";
|
||||||
|
double calPercentage = strCal(sum: strPercentage);
|
||||||
|
|
||||||
|
// MIN
|
||||||
|
String strRegexMinFee = r'min_fee="([0-9\.]+)"';
|
||||||
|
if (defaultRegex(strRegexMinFee).hasMatch(newSum)) {
|
||||||
|
String strMinFee =
|
||||||
|
defaultRegex(strRegexMinFee).firstMatch(newSum).group(1) ?? "0";
|
||||||
|
double doubleMinFee = double.parse(strMinFee);
|
||||||
|
|
||||||
|
if (calPercentage < doubleMinFee) {
|
||||||
|
return "(" + doubleMinFee.toString() + ")";
|
||||||
|
}
|
||||||
|
newSum = newSum.replaceAll(defaultRegex(strRegexMinFee), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// MAX
|
||||||
|
String strRegexMaxFee = r'max_fee="([0-9\.]+)"';
|
||||||
|
if (defaultRegex(strRegexMaxFee).hasMatch(newSum)) {
|
||||||
|
String strMaxFee =
|
||||||
|
defaultRegex(strRegexMaxFee).firstMatch(newSum).group(1) ?? "0";
|
||||||
|
double doubleMaxFee = double.parse(strMaxFee);
|
||||||
|
|
||||||
|
if (calPercentage > doubleMaxFee) {
|
||||||
|
return "(" + doubleMaxFee.toString() + ")";
|
||||||
|
}
|
||||||
|
newSum = newSum.replaceAll(defaultRegex(strRegexMaxFee), "");
|
||||||
|
}
|
||||||
|
return "(" + calPercentage.toString() + ")";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
|
||||||
|
percentVal = percentVal
|
||||||
|
.replaceAll(
|
||||||
|
defaultRegex(r'(min_fee=\"([0-9\.]+)\"|max_fee=\"([0-9\.]+)\")'),
|
||||||
|
"")
|
||||||
|
.trim();
|
||||||
|
return percentVal;
|
||||||
|
});
|
||||||
|
|
||||||
|
return strCal(sum: sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<double> workoutShippingClassCostWC(
|
||||||
|
{@required String sum, List<CartLineItem> cartLineItem}) async {
|
||||||
|
sum = sum.replaceAllMapped(defaultRegex(r'\[qty\]', strict: true), (replace) {
|
||||||
|
return cartLineItem.length.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
String orderTotal = await Cart.getInstance.getSubtotal();
|
||||||
|
|
||||||
|
sum = sum.replaceAllMapped(defaultRegex(r'\[fee(.*)]'), (replace) {
|
||||||
|
if (replace.groupCount < 1) {
|
||||||
|
return "()";
|
||||||
|
}
|
||||||
|
String newSum = replace.group(1);
|
||||||
|
|
||||||
|
// PERCENT
|
||||||
|
String percentVal = newSum.replaceAllMapped(
|
||||||
|
defaultRegex(r'percent="([0-9\.]+)"'), (replacePercent) {
|
||||||
|
if (replacePercent != null && replacePercent.groupCount >= 1) {
|
||||||
|
String strPercentage = "( (" +
|
||||||
|
orderTotal.toString() +
|
||||||
|
" * " +
|
||||||
|
replacePercent.group(1).toString() +
|
||||||
|
") / 100 )";
|
||||||
|
double calPercentage = strCal(sum: strPercentage);
|
||||||
|
|
||||||
|
// MIN
|
||||||
|
String strRegexMinFee = r'min_fee="([0-9\.]+)"';
|
||||||
|
if (defaultRegex(strRegexMinFee).hasMatch(newSum)) {
|
||||||
|
String strMinFee =
|
||||||
|
defaultRegex(strRegexMinFee).firstMatch(newSum).group(1) ?? "0";
|
||||||
|
double doubleMinFee = double.parse(strMinFee);
|
||||||
|
|
||||||
|
if (calPercentage < doubleMinFee) {
|
||||||
|
return "(" + doubleMinFee.toString() + ")";
|
||||||
|
}
|
||||||
|
newSum = newSum.replaceAll(defaultRegex(strRegexMinFee), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// MAX
|
||||||
|
String strRegexMaxFee = r'max_fee="([0-9\.]+)"';
|
||||||
|
if (defaultRegex(strRegexMaxFee).hasMatch(newSum)) {
|
||||||
|
String strMaxFee =
|
||||||
|
defaultRegex(strRegexMaxFee).firstMatch(newSum).group(1) ?? "0";
|
||||||
|
double doubleMaxFee = double.parse(strMaxFee);
|
||||||
|
|
||||||
|
if (calPercentage > doubleMaxFee) {
|
||||||
|
return "(" + doubleMaxFee.toString() + ")";
|
||||||
|
}
|
||||||
|
newSum = newSum.replaceAll(defaultRegex(strRegexMaxFee), "");
|
||||||
|
}
|
||||||
|
return "(" + calPercentage.toString() + ")";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
|
||||||
|
percentVal = percentVal
|
||||||
|
.replaceAll(
|
||||||
|
defaultRegex(r'(min_fee=\"([0-9\.]+)\"|max_fee=\"([0-9\.]+)\")'),
|
||||||
|
"")
|
||||||
|
.trim();
|
||||||
|
return percentVal;
|
||||||
|
});
|
||||||
|
|
||||||
|
return strCal(sum: sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
RegExp defaultRegex(
|
||||||
|
String pattern, {
|
||||||
|
bool strict,
|
||||||
|
}) {
|
||||||
|
return new RegExp(
|
||||||
|
pattern,
|
||||||
|
caseSensitive: strict ?? false,
|
||||||
|
multiLine: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
const app_name = "MyApp";
|
const app_name = "MyApp";
|
||||||
|
|
||||||
const app_key = "My app key";
|
const app_key =
|
||||||
|
"My App Key";
|
||||||
|
|
||||||
const app_logo_url = "https://woosignal.com/images/120x120_woosignal.png";
|
const app_logo_url = "https://woosignal.com/images/120x120_woosignal.png";
|
||||||
|
|
||||||
|
|||||||
@ -217,6 +217,8 @@ class CheckoutConfirmationPageState extends State<CheckoutConfirmationPage> {
|
|||||||
color: Colors.black12,
|
color: Colors.black12,
|
||||||
thickness: 1,
|
thickness: 1,
|
||||||
),
|
),
|
||||||
|
wsCheckoutSubtotalWidgetFB(
|
||||||
|
title: trans(context, "Subtotal")),
|
||||||
widgetCheckoutMeta(context,
|
widgetCheckoutMeta(context,
|
||||||
title: trans(context, "Shipping fee"),
|
title: trans(context, "Shipping fee"),
|
||||||
amount:
|
amount:
|
||||||
@ -227,8 +229,6 @@ class CheckoutConfirmationPageState extends State<CheckoutConfirmationPage> {
|
|||||||
(_taxRate != null
|
(_taxRate != null
|
||||||
? wsCheckoutTaxAmountWidgetFB(taxRate: _taxRate)
|
? wsCheckoutTaxAmountWidgetFB(taxRate: _taxRate)
|
||||||
: Container()),
|
: Container()),
|
||||||
wsCheckoutSubtotalWidgetFB(
|
|
||||||
title: trans(context, "Subtotal")),
|
|
||||||
wsCheckoutTotalWidgetFB(
|
wsCheckoutTotalWidgetFB(
|
||||||
title: trans(context, "Total"), taxRate: _taxRate),
|
title: trans(context, "Total"), taxRate: _taxRate),
|
||||||
Divider(
|
Divider(
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import 'package:label_storemax/models/customer_address.dart';
|
|||||||
import 'package:label_storemax/models/shipping_type.dart';
|
import 'package:label_storemax/models/shipping_type.dart';
|
||||||
import 'package:label_storemax/widgets/app_loader.dart';
|
import 'package:label_storemax/widgets/app_loader.dart';
|
||||||
import 'package:label_storemax/widgets/buttons.dart';
|
import 'package:label_storemax/widgets/buttons.dart';
|
||||||
|
import 'package:math_expressions/math_expressions.dart';
|
||||||
import 'package:woosignal/models/response/shipping_method.dart';
|
import 'package:woosignal/models/response/shipping_method.dart';
|
||||||
import 'package:label_storemax/app_country_options.dart';
|
import 'package:label_storemax/app_country_options.dart';
|
||||||
|
|
||||||
@ -59,11 +60,9 @@ class _CheckoutShippingTypePageState extends State<CheckoutShippingTypePage> {
|
|||||||
.firstWhere((c) => c['name'] == country, orElse: () => null)["code"];
|
.firstWhere((c) => c['name'] == country, orElse: () => null)["code"];
|
||||||
|
|
||||||
for (final shipping in wsShipping) {
|
for (final shipping in wsShipping) {
|
||||||
Locations location = shipping.locations
|
Locations location = shipping.locations.firstWhere(
|
||||||
.firstWhere((ws) => (ws.code == postalCode || ws.code == countryCode),
|
(ws) => (ws.code == postalCode || ws.code == countryCode),
|
||||||
orElse: () {
|
orElse: () => null);
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
_shipping = shipping;
|
_shipping = shipping;
|
||||||
@ -129,21 +128,48 @@ class _CheckoutShippingTypePageState extends State<CheckoutShippingTypePage> {
|
|||||||
Future<String> _getShippingPrice(int index) async {
|
Future<String> _getShippingPrice(int index) async {
|
||||||
double total = 0;
|
double total = 0;
|
||||||
List<CartLineItem> cartLineItem = await Cart.getInstance.getCart();
|
List<CartLineItem> cartLineItem = await Cart.getInstance.getCart();
|
||||||
|
|
||||||
|
total +=
|
||||||
|
await workoutShippingCostWC(sum: _wsShippingOptions[index]['cost']);
|
||||||
|
|
||||||
switch (_wsShippingOptions[index]['method_id']) {
|
switch (_wsShippingOptions[index]['method_id']) {
|
||||||
case "flat_rate":
|
case "flat_rate":
|
||||||
FlatRate flatRate = (_wsShippingOptions[index]['object'] as FlatRate);
|
FlatRate flatRate = (_wsShippingOptions[index]['object'] as FlatRate);
|
||||||
cartLineItem.forEach((c) {
|
|
||||||
ShippingClasses shippingClasses = flatRate.shippingClasses
|
if (cartLineItem.firstWhere(
|
||||||
.firstWhere((s) => s.id == c.shippingClassId, orElse: () => null);
|
(t) => t.shippingClassId == null || t.shippingClassId == "0",
|
||||||
if (shippingClasses != null) {
|
orElse: () => null) !=
|
||||||
total = total + double.parse(shippingClasses.cost);
|
null) {
|
||||||
|
total += await workoutShippingClassCostWC(
|
||||||
|
sum: flatRate.classCost,
|
||||||
|
cartLineItem: cartLineItem
|
||||||
|
.where((t) =>
|
||||||
|
t.shippingClassId == null || t.shippingClassId == "0")
|
||||||
|
.toList());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
List<CartLineItem> cItemsWithShippingClasses = cartLineItem
|
||||||
|
.where((t) => t.shippingClassId != null && t.shippingClassId != "0")
|
||||||
|
.toList();
|
||||||
|
for (int i = 0; i < cItemsWithShippingClasses.length; i++) {
|
||||||
|
ShippingClasses shippingClasses = flatRate.shippingClasses.firstWhere(
|
||||||
|
(d) => d.id == cItemsWithShippingClasses[i].shippingClassId,
|
||||||
|
orElse: () => null);
|
||||||
|
if (shippingClasses != null) {
|
||||||
|
double classTotal = await workoutShippingClassCostWC(
|
||||||
|
sum: shippingClasses.cost,
|
||||||
|
cartLineItem: cartLineItem
|
||||||
|
.where((g) => g.shippingClassId == shippingClasses.id)
|
||||||
|
.toList());
|
||||||
|
total += classTotal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (total + double.parse(_wsShippingOptions[index]['cost'])).toString();
|
return (total).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -231,6 +231,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.6"
|
version: "0.12.6"
|
||||||
|
math_expressions:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: math_expressions
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -36,6 +36,7 @@ dependencies:
|
|||||||
flutter_swiper: ^1.1.6
|
flutter_swiper: ^1.1.6
|
||||||
edge_alert: ^0.0.1
|
edge_alert: ^0.0.1
|
||||||
status_alert: ^0.1.1
|
status_alert: ^0.1.1
|
||||||
|
math_expressions: ^2.0.0
|
||||||
fluttertoast: ^4.0.1
|
fluttertoast: ^4.0.1
|
||||||
flutter_spinkit: ^4.1.2+1
|
flutter_spinkit: ^4.1.2+1
|
||||||
flutter_launcher_icons: ^0.7.4
|
flutter_launcher_icons: ^0.7.4
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user