@@ -21,6 +21,9 @@ import io.snabble.sdk.utils.getIntOpt
2121import io.snabble.sdk.utils.getString
2222import io.snabble.sdk.utils.getStringListOpt
2323import io.snabble.sdk.utils.getStringOpt
24+ import kotlinx.coroutines.flow.MutableStateFlow
25+ import kotlinx.coroutines.flow.StateFlow
26+ import kotlinx.coroutines.flow.asStateFlow
2427import okhttp3.OkHttpClient
2528import okhttp3.Request
2629import org.apache.commons.lang3.LocaleUtils
@@ -290,11 +293,18 @@ class Project internal constructor(jsonObject: JsonObject) {
290293 private lateinit var shoppingCartStorage: ShoppingCartStorage
291294 private set
292295
296+ private val _shoppingCart = MutableStateFlow (ShoppingCart ())
297+
298+ /* *
299+ * Flow to observe the current users shopping cart
300+ */
301+ val shoppingCartFlow: StateFlow <ShoppingCart > = _shoppingCart .asStateFlow()
302+
293303 /* *
294304 * The users shopping cart
295305 */
296- lateinit var shoppingCart: ShoppingCart
297- private set
306+ val shoppingCart: ShoppingCart
307+ get() = shoppingCartFlow.value
298308
299309 /* *
300310 * Provides a list of active coupons
@@ -496,15 +506,15 @@ class Project internal constructor(jsonObject: JsonObject) {
496506 .addInterceptor(AcceptedLanguageInterceptor ())
497507 .build()
498508
499- shoppingCart = ShoppingCart (this )
509+ _shoppingCart .tryEmit( ShoppingCart (this ) )
500510
501511 shoppingCartStorage = ShoppingCartStorage (this )
502512
503- checkout = Checkout (this , shoppingCart )
513+ checkout = Checkout (this , shoppingCartFlow.value )
504514
505- productDatabase = ProductDatabase (this , shoppingCart , " $id .sqlite3" , Snabble .config.generateSearchIndex)
515+ productDatabase = ProductDatabase (this , shoppingCartFlow.value , " $id .sqlite3" , Snabble .config.generateSearchIndex)
506516
507- events = Events (this , shoppingCart )
517+ events = Events (this , shoppingCartFlow.value )
508518
509519 assets = Assets (this )
510520
0 commit comments