Skip to content

Commit 35f0eb3

Browse files
authored
Show replace modifier as negative disocunt (APPS-2496) (#265)
1 parent 3bddef4 commit 35f0eb3

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
77
### Removed
88
### Fixed
99

10+
## [0.82.3]
11+
### Fixed
12+
* ui: Show replace Modifiers as negative discount
13+
1014
## [0.82.2]
1115
### Added
1216
* core: Add function to search for products by a prefix

ui/src/main/java/io/snabble/sdk/ui/cart/shoppingcart/ShoppingCartViewModel.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,27 +198,33 @@ class ShoppingCartViewModel : ViewModel() {
198198
val name = priceModifier.name.orEmpty()
199199
val weightUnit = item.item.lineItem?.weightUnit
200200
val referenceUnit = item.item.lineItem?.referenceUnit
201-
val modifiedPrice = if (weightUnit != null && referenceUnit != null) {
202-
priceModifier
203-
.convertPriceModifier(
204-
amount = item.quantity,
205-
weightedUnit = weightUnit,
206-
referencedUnit = referenceUnit
207-
)
208-
.let { priceFormatter?.format(it).orEmpty() }
209-
} else {
210-
(priceModifier.price * item.quantity).let {
211-
priceFormatter?.format(it).orEmpty()
201+
val modifiedPrice =
202+
if (priceModifier.action == "replace") {
203+
priceFormatter?.format(
204+
(item.item.lineItem?.price ?: 0) - priceModifier.price
205+
).orEmpty()
206+
} else if (weightUnit != null && referenceUnit != null) {
207+
priceModifier
208+
.convertPriceModifier(
209+
amount = item.quantity,
210+
weightedUnit = weightUnit,
211+
referencedUnit = referenceUnit
212+
)
213+
.let { priceFormatter?.format(it).orEmpty() }
214+
} else {
215+
(priceModifier.price * item.quantity).let {
216+
priceFormatter?.format(it).orEmpty()
217+
}
212218
}
213-
}
214219
// Set this to zero because the backend already subtracted the discount from the total price:
215220
val discountValue = 0
216221
modifiedPrice.let {
217222
discounts.add(
218223
DiscountItem(
219224
name = name,
220225
discount = modifiedPrice,
221-
discountValue = discountValue
226+
discountValue = discountValue,
227+
useNegativeValue = priceModifier.action == "replace"
222228
)
223229
)
224230
}

ui/src/main/java/io/snabble/sdk/ui/cart/shoppingcart/product/model/DiscountItem.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package io.snabble.sdk.ui.cart.shoppingcart.product.model
33
internal data class DiscountItem(
44
val name: String,
55
val discount: String,
6-
val discountValue: Int
6+
val discountValue: Int,
7+
val useNegativeValue: Boolean = false
78
)

ui/src/main/java/io/snabble/sdk/ui/cart/shoppingcart/product/widget/Product.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private fun DiscountItemWidget(it: DiscountItem) {
9090
verticalAlignment = Alignment.CenterVertically
9191
) {
9292
Text(
93-
it.discount,
93+
if (it.useNegativeValue) "-${it.discount}" else it.discount,
9494
style = MaterialTheme.typography.bodySmall,
9595
color = MaterialTheme.colorScheme.onSurface
9696
)

0 commit comments

Comments
 (0)