Skip to content

Commit da427d3

Browse files
committed
Implement variable product add to cart skeleton
1 parent 6f63d0c commit da427d3

19 files changed

Lines changed: 216 additions & 140 deletions

lib/api/cocart_api_client.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import 'package:dio/dio.dart';
22
import 'package:flutter_dotenv/flutter_dotenv.dart';
3-
import 'package:wooapp/api/interceptor_cocart_auth.dart';
4-
5-
import 'interceptor_logger.dart';
3+
import 'package:wooapp/api/interceptor_logger.dart';
64

75
class CoCartApiClient {
86
final Dio dio = Dio();
97

108
CoCartApiClient() {
119
dio.options.baseUrl = dotenv.env['CO_CART_BASE_URL'].toString();
12-
// dio.interceptors.add(CoCartAuthInterceptor());
1310
dio.interceptors.add(PrinterInterceptor());
1411
}
1512

lib/api/interceptor_logger.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:dio/dio.dart';
22

3-
const _httpTag = 'HTTP';
4-
53
class PrinterInterceptor extends Interceptor {
64

75
@override

lib/api/wp_api_client.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class WpApiClient {
77

88
WpApiClient() {
99
dio.options.baseUrl = dotenv.env['WP_BASE_URL'].toString();
10-
//dio.interceptors.add(CoCartAuthInterceptor());
1110
dio.interceptors.add(PrinterInterceptor());
1211
}
1312
}

lib/datasource/cart_data_source.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class CartDataSourceImpl extends CartDataSource {
2222
if (response.data is List<dynamic>) {
2323
return CartResponse.empty();
2424
}
25-
response.data;
2625
var data = CartResponse.fromJson(response.data);
2726
for (var cartItem in data.items) _db.addToCart(cartItem.id);
2827
return data;
@@ -32,12 +31,32 @@ class CartDataSourceImpl extends CartDataSource {
3231
Future<Response> addItem(int id, int count) => _sendUserRequest()
3332
.then((dio) => dio.post('cart/add-item', data: {
3433
'id': id,
35-
'quantity': count
34+
'quantity': count,
3635
})).then((response) {
3736
if (response.statusCode == 200) _db.addToCart(id);
3837
return response;
3938
});
4039

40+
@override
41+
Future<Response> addVariableItem(
42+
int id,
43+
int count,
44+
Map<String, dynamic> variation,
45+
) =>
46+
_sendUserRequest().then(
47+
(dio) => dio.post(
48+
'cart/add-item',
49+
data: {
50+
'id': id,
51+
'quantity': count,
52+
'variation': variation,
53+
},
54+
),
55+
).then((response) {
56+
if (response.statusCode == 200) _db.addToCart(id);
57+
return response;
58+
});
59+
4160
@override
4261
Future<Response> updateQuantity(String itemKey, int count) => _sendUserRequest()
4362
.then((dio) => dio.post('cart/item/$itemKey', data: {
@@ -72,6 +91,8 @@ abstract class CartDataSource {
7291

7392
Future<Response> addItem(int id, int count);
7493

94+
Future<Response> addVariableItem(int id, int count, Map<String, dynamic> variation);
95+
7596
Future<Response> updateQuantity(String itemKey, int count);
7697

7798
Future<CartResponse> deleteItem(String itemKey, int originalId);

lib/datasource/product_data_source.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ class ProductDataSourceImpl extends ProductDataSource {
77
final WooApiClient _api = locator<WooApiClient>();
88

99
@override
10-
Future<Product> getProducts(int id) => _api.dio
10+
Future<Product> getProduct(int id) => _api.dio
1111
.get('products/$id')
1212
.then((response) => Product.fromJson(response.data));
13-
1413
}
1514

1615
abstract class ProductDataSource {
17-
Future<Product> getProducts(int id);
16+
Future<Product> getProduct(int id);
1817
}

lib/model/product.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Product {
2222
List<WooImage> images;
2323
List<ProductAttribute> attributes;
2424

25+
bool get isVariable => type == 'variable';
26+
2527
Product.fromJson(Map<String, dynamic> json)
2628
: id = json['id'],
2729
name = json['name'],

lib/screens/auth/login.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ class _LoginScreenState extends State<LoginScreen> {
225225
void showResult(String title, String desc) {
226226
showDialog(
227227
context: context,
228-
builder: (ctx) => CustomDialogBox(
228+
builder: (ctx) => WooDialog(
229229
title: title,
230-
descriptions: desc,
230+
text: desc,
231231
),
232232
);
233233
}

lib/screens/auth/register.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ class _RegisterScreenState extends State<RegisterScreen> {
269269
void showResult(String title, String desc) {
270270
showDialog(
271271
context: context,
272-
builder: (ctx) => CustomDialogBox(
272+
builder: (ctx) => WooDialog(
273273
title: title,
274-
descriptions: desc,
274+
text: desc,
275275
),
276276
);
277277
}

lib/screens/auth/reset.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ class _PasswordRecoveryScreenState extends State<PasswordRecoveryScreen> {
153153
void showResult(String title, String desc) {
154154
showDialog(
155155
context: context,
156-
builder: (ctx) => CustomDialogBox(
156+
builder: (ctx) => WooDialog(
157157
title: title,
158-
descriptions: desc,
158+
text: desc,
159159
),
160160
);
161161
}

lib/screens/orders/create/create_order_view.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class CreateOrderView extends StatelessWidget {
6868
void _displayCheckoutSuccess(BuildContext context, Order order) {
6969
showDialog(
7070
context: context,
71-
builder: (ctx) => CustomDialogBox(
71+
builder: (ctx) => WooDialog(
7272
title: 'Success',
73-
descriptions: 'Order #${order.id} created successfully',
73+
text: 'Order #${order.id} created successfully',
7474
),
7575
);
7676
}
@@ -81,9 +81,9 @@ class CreateOrderView extends StatelessWidget {
8181

8282
showDialog(
8383
context: context,
84-
builder: (ctx) => CustomDialogBox(
84+
builder: (ctx) => WooDialog(
8585
title: 'Validation errors',
86-
descriptions: errorsString,
86+
text: errorsString,
8787
),
8888
);
8989
context.read<CreateOrderCubit>().invalidate();

0 commit comments

Comments
 (0)