@@ -21,7 +21,10 @@ import 'package:woosignal/models/response/tax_rate.dart';
2121import '../helpers/tools.dart' ;
2222
2323class CheckoutSession {
24- String sfKeyCheckout = "CS_BILLING_DETAILS" ;
24+ String sfKeyBillingCheckout = "CS_BILLING_DETAILS" ;
25+ String sfKeyShippingCheckout = "CS_SHIPPING_DETAILS" ;
26+ bool shipToDifferentAddress = false ;
27+
2528 CheckoutSession ._privateConstructor ();
2629 static final CheckoutSession getInstance =
2730 CheckoutSession ._privateConstructor ();
@@ -35,19 +38,25 @@ class CheckoutSession {
3538 shippingType = null ;
3639 }
3740
41+ void clear () {
42+ billingDetails = null ;
43+ shippingType = null ;
44+ paymentType = null ;
45+ }
46+
3847 void saveBillingAddress () {
3948 SharedPref sharedPref = SharedPref ();
4049 CustomerAddress customerAddress =
4150 CheckoutSession .getInstance.billingDetails.billingAddress;
4251
4352 String billingAddress = jsonEncode (customerAddress.toJson ());
44- sharedPref.save (sfKeyCheckout , billingAddress);
53+ sharedPref.save (sfKeyBillingCheckout , billingAddress);
4554 }
4655
4756 Future <CustomerAddress > getBillingAddress () async {
4857 SharedPref sharedPref = SharedPref ();
4958
50- String strCheckoutDetails = await sharedPref.read (sfKeyCheckout );
59+ String strCheckoutDetails = await sharedPref.read (sfKeyBillingCheckout );
5160
5261 if (strCheckoutDetails != null && strCheckoutDetails != "" ) {
5362 return CustomerAddress .fromJson (jsonDecode (strCheckoutDetails));
@@ -57,7 +66,30 @@ class CheckoutSession {
5766
5867 void clearBillingAddress () {
5968 SharedPref sharedPref = SharedPref ();
60- sharedPref.remove (sfKeyCheckout);
69+ sharedPref.remove (sfKeyBillingCheckout);
70+ }
71+
72+ void saveShippingAddress () {
73+ SharedPref sharedPref = SharedPref ();
74+ CustomerAddress customerAddress =
75+ CheckoutSession .getInstance.billingDetails.shippingAddress;
76+
77+ String shippingAddress = jsonEncode (customerAddress.toJson ());
78+ sharedPref.save (sfKeyShippingCheckout, shippingAddress);
79+ }
80+
81+ Future <CustomerAddress > getShippingAddress () async {
82+ SharedPref sharedPref = SharedPref ();
83+ String strCheckoutDetails = await sharedPref.read (sfKeyShippingCheckout);
84+ if (strCheckoutDetails != null && strCheckoutDetails != "" ) {
85+ return CustomerAddress .fromJson (jsonDecode (strCheckoutDetails));
86+ }
87+ return null ;
88+ }
89+
90+ void clearShippingAddress () {
91+ SharedPref sharedPref = SharedPref ();
92+ sharedPref.remove (sfKeyShippingCheckout);
6193 }
6294
6395 Future <String > total ({bool withFormat, TaxRate taxRate}) async {
0 commit comments