Skip to content

Commit 1b9f24f

Browse files
authored
Recipient / Shipping edit flow for order creation (#6)
* Cart and order price / quantity states * Create order recipient edit flow * Create order shipping edit flow * Feature translation patch 1 * Feature translation patch 2
1 parent b70be0e commit 1b9f24f

28 files changed

Lines changed: 1422 additions & 377 deletions

assets/translations/en.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"create_order_title": "New order",
114114
"create_order_products": "Products",
115115
"create_order_totals": "Total products price",
116-
"create_order_person": "Order recipient",
116+
"create_order_person": "Recipient",
117117
"create_order_name": "Name",
118118
"create_order_phone": "Phone",
119119
"create_order_shipping": "Shipping",
@@ -126,11 +126,29 @@
126126
"create_order_address_1": "Address",
127127
"create_order_address_2": "Details",
128128
"create_order_terms": "I have read and fully agree with the rules of the store, terms of use of the application.",
129+
"create_order_edit_recipient_select": "Select who will receive the order",
130+
"create_order_edit_recipient_data": "Recipient data",
131+
"create_order_edit_confirm_action": "Save",
132+
"create_order_recipient_me": "Me",
133+
"create_order_recipient_other": "Someone else",
134+
"create_order_edit_shipping_select": "Choose where you need to deliver your order",
135+
"create_order_edit_shipping_data": "Location details",
136+
"create_order_shipping_me": "My address",
137+
"create_order_shipping_other": "Another address",
129138
"search": "Search",
130139
"error": "Error",
140+
"error_validation_first_name": "Please, enter valid first name",
141+
"error_validation_last_name": "Please, enter valid last name",
142+
"error_validation_phone": "Please, enter phone number",
143+
"error_validation_country": "Please, enter country",
144+
"error_validation_city": "Please, enter city",
145+
"error_validation_state": "Please, enter state",
146+
"error_validation_post_code": "Please, enter post code",
147+
"error_validation_address_1": "Please, enter address",
148+
"error_validation_address_2": "Please, enter address details",
131149
"error_state_oops": "Oops \uD83D\uDE32",
132150
"error_state_title": "Something went wrong",
133151
"error_state_subtitle": "We are working on fixing the problem.\nPlease, try again.",
134152
"error_state_retry": "Try again",
135153
"error_user_not_exist": "There is no user registered with provided name.\nPlease, check your username!"
136-
}
154+
}

assets/translations/ru.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"create_order_title": "Оформление заказа",
114114
"create_order_products": "Товары",
115115
"create_order_totals": "Общая сумма",
116-
"create_order_person": "Получатель заказа",
116+
"create_order_person": "Получатель",
117117
"create_order_name": "Имя",
118118
"create_order_phone": "Телефон",
119119
"create_order_shipping": "Адрес доставки",
@@ -126,11 +126,29 @@
126126
"create_order_address_1": "Адрес",
127127
"create_order_address_2": "Информация",
128128
"create_order_terms": "Я ознакомился и полностью соглашаюсь с правилами магазина, условиями использования приложения.",
129+
"create_order_edit_recipient_select": "Выберите кто будет получать заказ",
130+
"create_order_edit_recipient_data": "Данные получателя",
131+
"create_order_edit_confirm_action": "Сохранить",
132+
"create_order_recipient_me": "Я",
133+
"create_order_recipient_other": "Кто-то другой",
134+
"create_order_edit_shipping_select": "Выберите куда нужно доставть ваш заказ",
135+
"create_order_edit_shipping_data": "Подробное расположение",
136+
"create_order_shipping_me": "Мой адрес",
137+
"create_order_shipping_other": "Другой адрес",
129138
"search": "Поиск",
130139
"error": "Ошибка",
140+
"error_validation_first_name": "Заполните имя",
141+
"error_validation_last_name": "Заполните фамилию",
142+
"error_validation_phone": "Заполните телефон",
143+
"error_validation_country": "Заполните страну",
144+
"error_validation_city": "Заполните город",
145+
"error_validation_state": "Заполните область",
146+
"error_validation_post_code": "Заполните почтовый индекс",
147+
"error_validation_address_1": "Заполните адрес",
148+
"error_validation_address_2": "Заполните детали адреса",
131149
"error_state_oops": "Упс \uD83D\uDE32",
132150
"error_state_title": "Что-то пошло не так",
133151
"error_state_subtitle": "Мы работаем над устранением ошибки.\nПожалуйста, попробуйте еще раз.",
134152
"error_state_retry": "Перезагрузить",
135153
"error_user_not_exist": "Пользователя с таким именем не существует.\nПожалуйста, проверьте имя пользователя!"
136-
}
154+
}

assets/translations/uk.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"product_property_images": "Зображення",
101101
"product_property_undefined": "<не задано>",
102102
"cart_empty_title": "Ваша корзина порожня",
103-
"cart_empty_subtitle": "Саме час зробити выбір!",
103+
"cart_empty_subtitle": "Саме час зробити вибір!",
104104
"cart_empty_action": "За покупками!",
105105
"settings_language": "Мова",
106106
"settings_password": "Змінити пароль",
@@ -113,7 +113,7 @@
113113
"create_order_title": "Оформлення замовлення",
114114
"create_order_products": "Товари",
115115
"create_order_totals": "Загальна сума",
116-
"create_order_person": "Отримувач замовлення",
116+
"create_order_person": "Отримувач",
117117
"create_order_name": "Ім'я",
118118
"create_order_phone": "Телефон",
119119
"create_order_shipping": "Адреса доставки",
@@ -126,8 +126,26 @@
126126
"create_order_address_1": "Адреса",
127127
"create_order_address_2": "Інформація",
128128
"create_order_terms": "Я ознайовився й повністю погоджуюся з правилами магазину, умовами використання додатку.",
129+
"create_order_edit_recipient_select": "Оберіть хто буде отримувати замовлення",
130+
"create_order_edit_recipient_data": "Персональні дані отримувача",
131+
"create_order_edit_confirm_action": "Зберегти",
132+
"create_order_recipient_me": "Я",
133+
"create_order_recipient_other": "Інша особа",
134+
"create_order_edit_shipping_select": "Оберіть куди потрібно доставити ваше замовлення",
135+
"create_order_edit_shipping_data": "Детальне місцезнаходження",
136+
"create_order_shipping_me": "Моя адреса",
137+
"create_order_shipping_other": "Інша адреса",
129138
"search": "Пошук",
130139
"error": "Помилка",
140+
"error_validation_first_name": "Необхідно заповнити Ім'я",
141+
"error_validation_last_name": "Необхідно заповнити Прізвище",
142+
"error_validation_phone": "Необхідно заповнити Телефон",
143+
"error_validation_country": "Необхідно заповнити Країну",
144+
"error_validation_city": "Необхідно заповнити Місто",
145+
"error_validation_state": "Необхідно заповнити Область",
146+
"error_validation_post_code": "Необхідно заповнити Індекс",
147+
"error_validation_address_1": "Необхідно заповнити Адресу",
148+
"error_validation_address_2": "Необхідно заповнити Деталі",
131149
"error_state_oops": "Ой \uD83D\uDE32",
132150
"error_state_title": "Щось пішло не так",
133151
"error_state_subtitle": "Ми працюємо над усуненням помилки.\nБудь-ласка, спробуйте ще раз.",

lib/datasource/cart_data_source.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CartDataSourceImpl extends CartDataSource {
2424
Future<CartResponse> getCart() => _sendUserRequest()
2525
.then((dio) => dio.get('cart'))
2626
.then((response) {
27+
response;
2728
if (response.data is List<dynamic>) {
2829
return CartResponse.empty();
2930
}

lib/datasource/orders_create_data_source.dart

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,70 @@ import 'package:wooapp/model/cart_response.dart';
55
import 'package:wooapp/model/order.dart';
66
import 'package:wooapp/model/payment_method.dart';
77
import 'package:wooapp/model/shipping_method.dart';
8-
import 'package:wooapp/screens/orders/create/create_order_model.dart';
8+
import 'package:wooapp/screens/orders/create/model/create_order_model.dart';
99

1010
class CreateOrderDataSourceImpl extends CreateOrderDataSource {
1111
final WooApiClient _api = locator<WooApiClient>();
1212
final AppDb _db = locator<AppDb>();
1313

1414
@override
1515
Future<Order> createOrder(
16-
List<CartItem> cartItems,
17-
CreateOrderRecipient recipient,
18-
CreateOrderShipping shipping,
19-
ShippingMethod shippingMethod,
20-
PaymentMethod paymentMethod) =>
21-
_db.getUserId().then((userId) => _api.dio.post('orders', data: {
22-
'payment_method': paymentMethod.id,
23-
'payment_method_title': paymentMethod.title,
24-
'set_paid': 'false',
25-
'customer_id': userId,
26-
'billing': {
27-
'first_name': recipient.firstName,
28-
'last_name': recipient.lastName,
29-
'address_1': shipping.address1,
30-
'address_2': shipping.address2,
31-
'city': shipping.city,
32-
'state': shipping.state,
33-
'postcode': shipping.index,
34-
'country': shipping.country,
35-
'email': recipient.email,
36-
'phone': recipient.phone
16+
List<CartItem> cartItems,
17+
CreateOrderRecipient recipient,
18+
CreateOrderShipping shipping,
19+
ShippingMethod shippingMethod,
20+
PaymentMethod paymentMethod,
21+
) =>
22+
_db.getUserId().then((userId) => _api.dio.post(
23+
'orders',
24+
data: {
25+
'payment_method': paymentMethod.id,
26+
'payment_method_title': paymentMethod.title,
27+
'set_paid': 'false',
28+
'customer_id': userId,
29+
'billing': {
30+
'first_name': recipient.firstName,
31+
'last_name': recipient.lastName,
32+
'address_1': shipping.address1,
33+
'address_2': shipping.address2,
34+
'city': shipping.city,
35+
'state': shipping.state,
36+
'postcode': shipping.index,
37+
'country': shipping.country,
38+
'email': recipient.email,
39+
'phone': recipient.phone,
40+
},
41+
'shipping': {
42+
'first_name': recipient.firstName,
43+
'last_name': recipient.lastName,
44+
'address_1': shipping.address1,
45+
'address_2': shipping.address2,
46+
'city': shipping.city,
47+
'state': shipping.state,
48+
'postcode': shipping.index,
49+
'country': shipping.country,
50+
},
51+
'line_items': [
52+
for (var prd in cartItems)
53+
{'product_id': prd.id, 'quantity': prd.quantity.value},
54+
],
55+
'shipping_lines': [
56+
{
57+
'method_id': shippingMethod.id,
58+
'method_title': shippingMethod.title,
59+
// 'total': '0'
60+
},
61+
],
3762
},
38-
'shipping': {
39-
'first_name': recipient.firstName,
40-
'last_name': recipient.lastName,
41-
'address_1': shipping.address1,
42-
'address_2': shipping.address2,
43-
'city': shipping.city,
44-
'state': shipping.state,
45-
'postcode': shipping.index,
46-
'country': shipping.country,
47-
},
48-
'line_items': [
49-
for (var prd in cartItems)
50-
{'product_id': prd.id, 'quantity': prd.quantity.value}
51-
],
52-
'shipping_lines': [
53-
{
54-
'method_id': shippingMethod.id,
55-
'method_title': shippingMethod.title,
56-
// 'total': '0'
57-
}
58-
]
59-
})
60-
.then((response) => Order.fromJson(response.data)));
63+
).then((response) => Order.fromJson(response.data)));
6164
}
6265

6366
abstract class CreateOrderDataSource {
6467
Future<Order> createOrder(
65-
List<CartItem> cartItems,
66-
CreateOrderRecipient recipient,
67-
CreateOrderShipping shipping,
68-
ShippingMethod shippingMethod,
69-
PaymentMethod paymentMethod
68+
List<CartItem> cartItems,
69+
CreateOrderRecipient recipient,
70+
CreateOrderShipping shipping,
71+
ShippingMethod shippingMethod,
72+
PaymentMethod paymentMethod,
7073
);
7174
}

lib/extensions/extensions_product.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ String parseHtml(String htmlDescription) {
44
final document = parse(htmlDescription);
55
return parse(document.body!.text).documentElement!.text;
66
}
7+
8+
String parseTotals(
9+
String totals, {
10+
int fraction = 2,
11+
String delimiter = '.',
12+
}) {
13+
var partBase = totals.substring(0, totals.length - fraction);
14+
var partFraction = totals.substring(totals.length - fraction, totals.length);
15+
return '$partBase$delimiter$partFraction';
16+
}

lib/extensions/extensions_widget.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'package:shimmer_animation/shimmer_animation.dart';
33
import 'package:wooapp/config/theme.dart';
44

55
Widget shimmer() => Shimmer(
6-
duration: Duration(seconds: 1),
7-
enabled: true,
8-
direction: ShimmerDirection.fromLTRB(),
9-
color: WooAppTheme.colorShimmerForeground,
10-
child: Container(color: WooAppTheme.colorShimmerBackground)
11-
);
6+
duration: Duration(seconds: 1),
7+
enabled: true,
8+
direction: ShimmerDirection.fromLTRB(),
9+
color: WooAppTheme.colorShimmerForeground,
10+
child: Container(color: WooAppTheme.colorShimmerBackground),
11+
);

lib/model/cart_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CartTotals {
6262
CartTotals.fromJson(Map<String, dynamic> json)
6363
: subtotal = json['subtotal'] ?? '',
6464
subtotalTax = json['subtotal_tax'] ?? '',
65-
total = json['total'] ?? '',
65+
total = double.tryParse(json['total'].toString()) ?? 0.0,
6666
tax = json['tax'] ?? '';
6767
}
6868

lib/screens/cart/cart_cubit.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter_bloc/flutter_bloc.dart';
24
import 'package:wooapp/database/database.dart';
35
import 'package:wooapp/datasource/cart_data_source.dart';
@@ -23,8 +25,7 @@ class CartCubit extends Cubit<CartState> {
2325
emit(ContentCartState(cart));
2426
}
2527
}).catchError((error, stacktrace) {
26-
print('$error');
27-
print('$stacktrace');
28+
Completer().completeError(error, stacktrace);
2829
emit(ErrorCartState());
2930
});
3031
}
@@ -38,9 +39,9 @@ class CartCubit extends Cubit<CartState> {
3839
} else {
3940
emit(ContentCartState(cart));
4041
}
41-
}).catchError((error) {
42-
print('$error');
42+
}).catchError((error, stacktrace) {
43+
Completer().completeError(error, stacktrace);
4344
emit(ErrorCartState());
4445
});
4546
}
46-
}
47+
}

0 commit comments

Comments
 (0)