Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
### Removed
### Fixed

## [0.82.3]
### Fixed
* ui: Show replace Modifiers as negative discount

## [0.82.2]
### Added
* core: Add function to search for products by a prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,33 @@ class ShoppingCartViewModel : ViewModel() {
val name = priceModifier.name.orEmpty()
val weightUnit = item.item.lineItem?.weightUnit
val referenceUnit = item.item.lineItem?.referenceUnit
val modifiedPrice = if (weightUnit != null && referenceUnit != null) {
priceModifier
.convertPriceModifier(
amount = item.quantity,
weightedUnit = weightUnit,
referencedUnit = referenceUnit
)
.let { priceFormatter?.format(it).orEmpty() }
} else {
(priceModifier.price * item.quantity).let {
priceFormatter?.format(it).orEmpty()
val modifiedPrice =
if (priceModifier.action == "replace") {
priceFormatter?.format(
(item.item.lineItem?.price ?: 0) - priceModifier.price
).orEmpty()
} else if (weightUnit != null && referenceUnit != null) {
priceModifier
.convertPriceModifier(
amount = item.quantity,
weightedUnit = weightUnit,
referencedUnit = referenceUnit
)
.let { priceFormatter?.format(it).orEmpty() }
} else {
(priceModifier.price * item.quantity).let {
priceFormatter?.format(it).orEmpty()
}
}
}
// Set this to zero because the backend already subtracted the discount from the total price:
val discountValue = 0
modifiedPrice.let {
discounts.add(
DiscountItem(
name = name,
discount = modifiedPrice,
discountValue = discountValue
discountValue = discountValue,
useNegativeValue = priceModifier.action == "replace"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package io.snabble.sdk.ui.cart.shoppingcart.product.model
internal data class DiscountItem(
val name: String,
val discount: String,
val discountValue: Int
val discountValue: Int,
val useNegativeValue: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private fun DiscountItemWidget(it: DiscountItem) {
verticalAlignment = Alignment.CenterVertically
) {
Text(
it.discount,
if (it.useNegativeValue) "-${it.discount}" else it.discount,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface
)
Expand Down