Skip to content

Commit 637ee2c

Browse files
authored
Merge pull request #14943 from woocommerce/issue/woomob-1685-woo-poslocal-catalog-product-not-available-state
POS - Product Not Available At Checkout
2 parents e4b19df + 41918de commit 637ee2c

File tree

16 files changed

+297
-80
lines changed

16 files changed

+297
-80
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeChildToParentCommunication.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ sealed class ChildToParentEvent {
4444
data class CouponsRemoved(
4545
val cartDataList: List<WooPosItemsViewModel.ItemClickedData>
4646
) : ChildToParentEvent()
47+
data class RemoveProductsClicked(val removedProductsIds: List<Long>) :
48+
ChildToParentEvent()
49+
data class ProductsRemoved(
50+
val cartDataList: List<WooPosItemsViewModel.ItemClickedData>
51+
) : ChildToParentEvent()
4752

4853
data class ToastMessageDisplayed(val message: String) : ChildToParentEvent()
4954
data object RefreshProductList : ChildToParentEvent()

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeParentToChildCommunication.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ sealed class ParentToChildrenEvent {
2929
data class CouponsRemoved(
3030
val cartDataList: List<WooPosItemsViewModel.ItemClickedData>
3131
) : ParentToChildrenEvent()
32+
data class RemoveProductsClicked(
33+
val productIdsToRemove: List<Long>
34+
) : ParentToChildrenEvent()
35+
data class ProductsRemoved(
36+
val cartDataList: List<WooPosItemsViewModel.ItemClickedData>
37+
) : ParentToChildrenEvent()
3238
data class ItemClickedInItemsList(
3339
val itemData: WooPosItemsViewModel.ItemClickedData,
3440
val eventForTracking: WooPosAnalyticsEvent.Event.ItemAddedToCart?

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ class WooPosHomeViewModel @Inject constructor(
237237
sendEventToChildren(CouponsRemoved(event.cartDataList))
238238
}
239239

240+
is ChildToParentEvent.RemoveProductsClicked -> {
241+
sendEventToChildren(ParentToChildrenEvent.RemoveProductsClicked(event.removedProductsIds))
242+
}
243+
244+
is ChildToParentEvent.ProductsRemoved -> {
245+
sendEventToChildren(ParentToChildrenEvent.ProductsRemoved(event.cartDataList))
246+
}
247+
240248
ChildToParentEvent.RefreshProductList -> {
241249
sendEventToChildren(ParentToChildrenEvent.RefreshProductList)
242250
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/cart/WooPosCartScreen.kt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,7 @@ private fun ProductItem(
517517
modifier = modifier
518518
.wrapContentHeight()
519519
.semantics { contentDescription = itemContentDescription },
520-
backgroundColor = if (item.productDoesNotExist) {
521-
WooPosTheme.colors.disabledContainer
522-
} else {
523-
MaterialTheme.colorScheme.surfaceContainerLowest
524-
},
520+
backgroundColor = MaterialTheme.colorScheme.surfaceContainerLowest,
525521
elevation = WooPosElevation.Medium,
526522
shadowType = ShadowType.Soft,
527523
shape = RoundedCornerShape(WooPosCornerRadius.Medium.value),
@@ -554,11 +550,7 @@ private fun ProductItem(
554550
Image(
555551
imageVector = Icons.Outlined.Inventory2,
556552
contentDescription = null,
557-
colorFilter = if (item.productDoesNotExist) {
558-
ColorFilter.tint(WooPosTheme.colors.onSurfaceVariantLowest)
559-
} else {
560-
ColorFilter.tint(WooPosTheme.colors.onDisabledContainer)
561-
},
553+
colorFilter = ColorFilter.tint(WooPosTheme.colors.onDisabledContainer),
562554
modifier = Modifier.size(36.dp)
563555
)
564556
}
@@ -569,7 +561,7 @@ private fun ProductItem(
569561
contentScale = ContentScale.Crop,
570562
modifier = Modifier
571563
.size(96.dp)
572-
.alpha(if (item.productDoesNotExist) 0.5f else 1f)
564+
.alpha(1f)
573565
)
574566
}
575567

@@ -587,11 +579,7 @@ private fun ProductItem(
587579
style = WooPosTypography.BodySmall,
588580
fontWeight = FontWeight.Bold,
589581
overflow = TextOverflow.Ellipsis,
590-
color = if (item.productDoesNotExist) {
591-
WooPosTheme.colors.onDisabledContainer
592-
} else {
593-
MaterialTheme.colorScheme.onSurface
594-
},
582+
color = MaterialTheme.colorScheme.onSurface,
595583
modifier = Modifier
596584
.clearAndSetSemantics { }
597585
)
@@ -600,11 +588,7 @@ private fun ProductItem(
600588
WooPosText(
601589
text = item.description ?: "",
602590
style = WooPosTypography.BodySmall,
603-
color = if (item.productDoesNotExist) {
604-
WooPosTheme.colors.onDisabledContainer
605-
} else {
606-
WooPosTheme.colors.onSurfaceVariantHighest
607-
},
591+
color = WooPosTheme.colors.onSurfaceVariantHighest,
608592
maxLines = 1,
609593
overflow = TextOverflow.Ellipsis,
610594
modifier = Modifier
@@ -615,14 +599,22 @@ private fun ProductItem(
615599
WooPosText(
616600
text = item.price,
617601
style = WooPosTypography.BodySmall,
618-
color = if (item.productDoesNotExist) {
619-
WooPosTheme.colors.onDisabledContainer
620-
} else {
621-
WooPosTheme.colors.onSurfaceVariantHighest
622-
},
602+
color = WooPosTheme.colors.onSurfaceVariantHighest,
623603
modifier = Modifier
624604
.clearAndSetSemantics { }
625605
)
606+
607+
if (item.productDoesNotExist) {
608+
Spacer(modifier = Modifier.height(WooPosSpacing.XSmall.value.toAdaptivePadding()))
609+
WooPosText(
610+
text = stringResource(R.string.woopos_cart_product_unknown_item),
611+
style = WooPosTypography.BodySmall,
612+
maxLines = 2,
613+
overflow = TextOverflow.Ellipsis,
614+
color = MaterialTheme.colorScheme.error,
615+
modifier = Modifier.clearAndSetSemantics { }
616+
)
617+
}
626618
}
627619

628620
if (canRemoveItems) {

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/cart/WooPosCartViewModel.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class WooPosCartViewModel @Inject constructor(
176176
}
177177

178178
private fun getCartItemsDataList(): List<WooPosItemsViewModel.ItemClickedData> {
179-
val itemClickedDataList = (_state.value.body as WooPosCartState.Body.WithItems).itemsInCart.mapNotNull {
179+
val itemClickedDataList = (_state.value.body as? WooPosCartState.Body.WithItems)?.itemsInCart?.mapNotNull {
180180
when (it) {
181181
is Product.Simple -> WooPosItemsViewModel.ItemClickedData.Product.Simple(it.id)
182182
is Product.Variation -> WooPosItemsViewModel.ItemClickedData.Product.Variation(
@@ -188,7 +188,7 @@ class WooPosCartViewModel @Inject constructor(
188188
is WooPosCartItemViewState.Loading -> null
189189
is WooPosCartItemViewState.Error -> null
190190
}
191-
}
191+
} ?: emptyList()
192192
return itemClickedDataList
193193
}
194194

@@ -227,9 +227,15 @@ class WooPosCartViewModel @Inject constructor(
227227
removeCouponsFromCart()
228228
}
229229

230+
is ParentToChildrenEvent.RemoveProductsClicked -> {
231+
removeNotFoundProductsFromCart(event)
232+
}
233+
230234
is ParentToChildrenEvent.BarcodeEvent -> {
231235
onBarcodeEvent(event.result)
232236
}
237+
238+
is ParentToChildrenEvent.ProductsRemoved -> Unit
233239
}
234240
}
235241
}
@@ -288,6 +294,19 @@ class WooPosCartViewModel @Inject constructor(
288294
sendEventToParent(CouponsRemoved(getCartItemsDataList()))
289295
}
290296

297+
private fun removeNotFoundProductsFromCart(event: ParentToChildrenEvent.RemoveProductsClicked) {
298+
val cartBody = _state.value.body as? WooPosCartState.Body.WithItems ?: return
299+
300+
val productsToRemove = cartBody.itemsInCart
301+
.filterIsInstance<Product.Simple>()
302+
.filter { it.id in event.productIdsToRemove }
303+
.toSet()
304+
305+
removeItemsFromCart(productsToRemove, WooPosAnalyticsEventConstant.CartSource.ERROR)
306+
307+
sendEventToParent(ChildToParentEvent.ProductsRemoved(getCartItemsDataList()))
308+
}
309+
291310
private fun handleBackFromCheckoutToCartClicked() {
292311
val currentState = _state.value
293312
val newCartStatus = EDITABLE

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/WooPosItemsSearchHelper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class WooPosItemsSearchHelper @Inject constructor(
6767
is ParentToChildrenEvent.CouponsRemoved -> Unit
6868
is ParentToChildrenEvent.RemoveCouponsClicked -> Unit
6969
is ParentToChildrenEvent.CouponsValidationFailed -> Unit
70+
is ParentToChildrenEvent.RemoveProductsClicked -> Unit
71+
is ParentToChildrenEvent.ProductsRemoved -> Unit
7072
is ParentToChildrenEvent.OrderSuccessfullyPaid -> Unit
7173
is ParentToChildrenEvent.SettingsEvent -> Unit
7274
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/WooPosItemsViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class WooPosItemsViewModel @Inject constructor(
124124
is ParentToChildrenEvent.SearchEvent.RecentSearchSelected,
125125
ParentToChildrenEvent.SearchEvent.Started,
126126
is ParentToChildrenEvent.BarcodeEvent,
127+
is ParentToChildrenEvent.RemoveProductsClicked,
128+
is ParentToChildrenEvent.ProductsRemoved,
127129
is ParentToChildrenEvent.SettingsEvent -> Unit
128130

129131
is ParentToChildrenEvent.OrderSuccessfullyPaid -> _viewState.value = initialState()

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class WooPosProductsViewModel @Inject constructor(
8686
ParentToChildrenEvent.SearchEvent.Finished,
8787
is ParentToChildrenEvent.SearchEvent.RecentSearchSelected,
8888
ParentToChildrenEvent.SearchEvent.Started,
89+
is ParentToChildrenEvent.RemoveProductsClicked,
90+
is ParentToChildrenEvent.ProductsRemoved,
8991
is ParentToChildrenEvent.SettingsEvent -> Unit
9092
}
9193
}
@@ -340,7 +342,7 @@ class WooPosProductsViewModel @Inject constructor(
340342
}
341343
}
342344
}
343-
}.onFailure { exception ->
345+
}.onFailure { _ ->
344346
handlePTRError()
345347
}
346348
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/search/WooPosItemsSearchViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class WooPosItemsSearchViewModel @Inject constructor(
186186
is ParentToChildrenEvent.CouponsRemoved -> Unit
187187
is ParentToChildrenEvent.RefreshProductList -> Unit
188188
is ParentToChildrenEvent.CouponsValidationFailed -> Unit
189+
is ParentToChildrenEvent.RemoveProductsClicked -> Unit
190+
is ParentToChildrenEvent.ProductsRemoved -> Unit
189191
is ParentToChildrenEvent.SettingsEvent -> Unit
190192
is ParentToChildrenEvent.ItemClickedInItemsList -> {
191193
if (event.itemData is ItemClickedData.Product.Variation && searchHelper.isSearchOpen()) {

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsScreen.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ private fun WooPosTotalsScreen(
125125
}
126126
}
127127

128+
StateChangeAnimated(visible = state is WooPosTotalsViewState.ProductNotFoundError) {
129+
if (state is WooPosTotalsViewState.ProductNotFoundError) {
130+
TotalsProductNotFoundErrorScreen(
131+
errorMessage = state.message,
132+
errorReason = state.reason,
133+
onUIEvent = onUIEvent
134+
)
135+
}
136+
}
137+
128138
StateChangeAnimated(visible = state is WooPosTotalsViewState.PaymentInProgress) {
129139
if (state is WooPosTotalsViewState.PaymentInProgress) {
130140
WooPosPaymentInProgressScreen(state, onUIEvent)
@@ -475,6 +485,26 @@ private fun TotalsInvalidCouponsErrorScreen(
475485
)
476486
}
477487

488+
@Composable
489+
private fun TotalsProductNotFoundErrorScreen(
490+
errorMessage: String,
491+
errorReason: String,
492+
onUIEvent: (WooPosTotalsUIEvent) -> Unit
493+
) {
494+
return WooPosErrorScreen(
495+
message = errorMessage,
496+
reason = errorReason,
497+
primaryButton = WooPosErrorScreenButtonState(
498+
text = stringResource(R.string.woopos_totals_product_not_found_edit_order),
499+
click = { onUIEvent(WooPosTotalsUIEvent.GoBackToOrderEditAfterProductNotFound) }
500+
),
501+
secondaryButton = WooPosErrorScreenButtonState(
502+
text = stringResource(R.string.woopos_totals_product_not_found_remove_products),
503+
click = { onUIEvent(WooPosTotalsUIEvent.OnRemoveProductsClicked) }
504+
)
505+
)
506+
}
507+
478508
@Composable
479509
@WooPosPreview
480510
fun WooPosTotalsScreenPreview(modifier: Modifier = Modifier) {

0 commit comments

Comments
 (0)