WT 1.1.14+2 sales page update
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/product.dart';
|
||||
import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/model/purchase.dart';
|
||||
import 'package:aitrainer_app/repository/description_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/purchase_service.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
@@ -13,6 +14,7 @@ import 'package:aitrainer_app/util/purchases.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
||||
import 'package:purchases_flutter/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
@@ -22,8 +24,29 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
List<ProductTest>? tests = [];
|
||||
List<Product> product2Display = [];
|
||||
int productSet = -1;
|
||||
final DescriptionRepository descriptionRepository = DescriptionRepository();
|
||||
SalesBloc() : super(SalesInitial());
|
||||
|
||||
String? salesText;
|
||||
|
||||
String salesButtonText = "<h1>Workout Test Monthly</h1><p>localizedPrice</p><p><small>cancel any time</small></p>";
|
||||
Product? offeredProduct;
|
||||
|
||||
Product? getProductByName(String name) {
|
||||
Product? product;
|
||||
if (product2Display.isNotEmpty) {
|
||||
product2Display.forEach((element) {
|
||||
if (element.type == name) {
|
||||
product = element;
|
||||
salesButtonText = salesButtonText.replaceFirst(RegExp(r'localizedPrice'), product!.localizedPrice!);
|
||||
print("Localized Price ${product!.localizedPrice!} - Text: $salesButtonText");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<SalesState> mapEventToState(
|
||||
SalesEvent event,
|
||||
@@ -32,9 +55,30 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
if (event is SalesLoad) {
|
||||
yield SalesLoading();
|
||||
log("Load Sales");
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("Please log in");
|
||||
}
|
||||
|
||||
String descriptionName = "sales_page_text";
|
||||
RemoteConfig? remoteConfig = Cache().remoteConfig;
|
||||
if (remoteConfig != null) {
|
||||
remoteConfig.fetchAndActivate();
|
||||
Map config = remoteConfig.getAll();
|
||||
RemoteConfigValue? value = config['sales_page_text_a'];
|
||||
if (value != null) {
|
||||
log("RemoteConfig sales_page_text value: ${value.asString()}");
|
||||
if (value.asString() == "1") {
|
||||
descriptionName = "sales_page_text_a";
|
||||
}
|
||||
}
|
||||
}
|
||||
await RevenueCatPurchases().getOfferings();
|
||||
this.getProductSet();
|
||||
salesText = descriptionRepository.getDescriptionByName(descriptionName);
|
||||
log(salesText!);
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_monthly");
|
||||
offeredProduct = getProductByName("wt_sub_2_3");
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
yield SalesReady();
|
||||
} else if (event is SalesPurchase) {
|
||||
if (Cache().hasPurchased) {
|
||||
@@ -60,6 +104,22 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
} else {
|
||||
yield SalesError(message: "No selected product");
|
||||
}
|
||||
} else if (event is SalesChangeSubscription) {
|
||||
yield SalesLoading();
|
||||
print("offered product .. $offeredProduct");
|
||||
if (offeredProduct != null) {
|
||||
if (offeredProduct!.type == "wt_sub_2_3") {
|
||||
print("go yearly");
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_yearly");
|
||||
offeredProduct = getProductByName("wt_sub_2_1");
|
||||
} else {
|
||||
print("go monthly");
|
||||
salesButtonText = descriptionRepository.getDescriptionByName("sales_button_monthly");
|
||||
offeredProduct = getProductByName("wt_sub_2_3");
|
||||
}
|
||||
}
|
||||
|
||||
yield SalesReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
@@ -76,7 +136,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
return prod;
|
||||
}
|
||||
|
||||
String getLocalizedPrice(String productId) {
|
||||
String getLocalizedPrice(String productId, Product product) {
|
||||
String price = "";
|
||||
Offering? offering = RevenueCatPurchases().offering;
|
||||
if (offering != null) {
|
||||
@@ -86,7 +146,7 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
price = package.product.priceString;
|
||||
if (price.contains(r'HUF')) {
|
||||
price = price.replaceAll(RegExp(r'HUF'), 'Ft');
|
||||
price = price.replaceAll(RegExp(r',00'), "");
|
||||
price = price.replaceAll(RegExp(r'\,00'), "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -94,18 +154,21 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
} else {
|
||||
log(" !!! No Offering");
|
||||
}
|
||||
if (price.isEmpty) {
|
||||
price = Platform.isAndroid ? product.priceAndroid.toString() : product.priceIos.toString();
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
void getProductSet() {
|
||||
int productId = 0;
|
||||
this.tests = Cache().productTests;
|
||||
//this.tests = Cache().productTests;
|
||||
List<Product>? products = Cache().products;
|
||||
if (products == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tests != null && tests!.isEmpty) {
|
||||
/* if (tests != null && tests!.isEmpty) {
|
||||
var rand = math.Random.secure();
|
||||
productSet = rand.nextInt(5) + 1;
|
||||
} else {
|
||||
@@ -118,9 +181,9 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
ProductTest productTest = ProductTest();
|
||||
//ProductTest productTest = ProductTest();
|
||||
|
||||
productSet = 2;
|
||||
log("ProductSet: " + productSet.toString());
|
||||
@@ -130,7 +193,8 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
if (product.productSet == productSet) {
|
||||
productId = product.productId;
|
||||
final String platformProductId = Platform.isAndroid ? product.productIdAndroid! : product.productIdIos!;
|
||||
product.localizedPrice = getLocalizedPrice(platformProductId);
|
||||
product.localizedPrice = getLocalizedPrice(platformProductId, product);
|
||||
log("product with localized price: $product");
|
||||
product2Display.add(product);
|
||||
}
|
||||
}
|
||||
@@ -139,9 +203,9 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
return a.sort < b.sort ? -1 : 1;
|
||||
});
|
||||
|
||||
productTest.productId = productId;
|
||||
productTest.customerId = Cache().userLoggedIn!.customerId!;
|
||||
productTest.dateView = DateTime.now();
|
||||
//productTest.productId = productId;
|
||||
//productTest.customerId = Cache().userLoggedIn!.customerId!;
|
||||
//productTest.dateView = DateTime.now();
|
||||
//ProductTestApi().saveProductTest(productTest);
|
||||
//Cache().productTests.add(productTest);
|
||||
}
|
||||
|
||||
@@ -15,3 +15,7 @@ class SalesPurchase extends SalesEvent {
|
||||
final int productId;
|
||||
const SalesPurchase({required this.productId});
|
||||
}
|
||||
|
||||
class SalesChangeSubscription extends SalesEvent {
|
||||
const SalesChangeSubscription();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user