Skip to content

Commit

Permalink
Add changes for zero amount checkout and drv first support (Apps-1939/…
Browse files Browse the repository at this point in the history
… 2049) (#236)
  • Loading branch information
Fabtron authored Jan 10, 2025
1 parent e9fe1af commit 9bf10bf
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ All notable changes to this project will be documented in this file.
* core: Handle invalid items (APPS-2039)
* ui/core: Integrate new states for deposit return vouchers into the checkout process and handle them
### Changed
* ui: Change button message for a total price of zero and price text color for a negative total price (APPS-1939)
* core: Handle only a set of pre defined violations (APPS-2049)
### Removed
* ui/core: Remove everything related to the old deposit return voucher feature
* core: Remove handling an empty list of payment methods in the checkout info as error (APPS-2049)
### Fixed

## [0.80.3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ class DefaultCheckoutApi(private val project: Project,
?: shoppingCart.totalPrice

val availablePaymentMethods = signedCheckoutInfo.getAvailablePaymentMethods()
if (availablePaymentMethods.isNotEmpty()) {
checkoutInfoResult?.onSuccess(signedCheckoutInfo, price, availablePaymentMethods)
} else {
checkoutInfoResult?.onConnectionError()
}
checkoutInfoResult?.onSuccess(signedCheckoutInfo, price, availablePaymentMethods)
}

override fun failure(obj: JsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,17 @@ class ShoppingCart(

@RestrictTo(RestrictTo.Scope.LIBRARY)
fun resolveViolations(violations: List<Violation>) {
handleCouponViolations(violations)
handleDepositReturnVoucherViolations(violations)
val validViolations = getValidViolations(violations) ?: return
handleCouponViolations(validViolations)
handleDepositReturnVoucherViolations(validViolations)
notifyViolations()
updatePrices(debounce = false)
}

private fun getValidViolations(violations: List<Violation>): List<Violation>? {
return violations.filter { it.type in ViolationType.entries }.ifEmpty { null }
}

private fun handleDepositReturnVoucherViolations(violations: List<Violation>) {
violations.resolve(ViolationType.DEPOSIT_RETURN_DUPLICATED)
violations.resolve(ViolationType.DEPOSIT_RETURN_ALREADY_REDEEMED)
Expand Down
30 changes: 24 additions & 6 deletions ui/src/main/java/io/snabble/sdk/ui/cart/CheckoutBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import io.snabble.sdk.ui.utils.observeView
import io.snabble.sdk.ui.utils.requireFragmentActivity
import io.snabble.sdk.ui.utils.setOneShotClickListener
import io.snabble.sdk.utils.Logger
import io.snabble.sdk.utils.getColorByAttribute

open class CheckoutBar @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
Expand Down Expand Up @@ -213,6 +214,13 @@ open class CheckoutBar @JvmOverloads constructor(
val articlesText = resources.getQuantityText(R.plurals.Snabble_Shoppingcart_numberOfItems, quantity)
articleCount.text = String.format(articlesText.toString(), quantity)
priceSum.text = project.priceFormatter.format(price)
priceSum.setTextColor(
if (price < 0) {
context.getColorByAttribute(R.attr.colorError)
} else {
context.getColorByAttribute(R.attr.colorOnSurface)
}
)

val onlinePaymentAvailable = !cart.availablePaymentMethods.isNullOrEmpty()
payButton.isEnabled =
Expand Down Expand Up @@ -245,13 +253,23 @@ open class CheckoutBar @JvmOverloads constructor(
payButton.isEnabled = true
payButton.setText(R.string.Snabble_Shoppingcart_EmptyState_restoreButtonTitle)
} else {
payButton.setText(
I18nUtils.getIdentifierForProject(
resources,
project,
R.string.Snabble_Shoppingcart_BuyProducts_now
if (price == 0) {
payButton.setText(
I18nUtils.getIdentifierForProject(
resources,
project,
R.string.Snabble_Shoppingcart_completePurchase
)
)
)
} else {
payButton.setText(
I18nUtils.getIdentifierForProject(
resources,
project,
R.string.Snabble_Shoppingcart_BuyProducts_now
)
)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
<string name="Snabble.Shoppingcart.EmptyState.title">Dein Warenkorb ist noch leer</string>
<string name="Snabble.Shoppingcart.articleRemoved">Artikel entfernt</string>
<string name="Snabble.Shoppingcart.buyProducts">%1$d Artikel für %2$s kaufen</string>
<string name="Snabble.Shoppingcart.completePurchase">Einkauf abschließen</string>
<string name="Snabble.Shoppingcart.coupon">Gutschein</string>
<string name="Snabble.Shoppingcart.coupons">Gutscheine</string>
<string name="Snabble.Shoppingcart.deposit">Pfand</string>
Expand Down
1 change: 1 addition & 0 deletions ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
<string name="Snabble.Shoppingcart.EmptyState.title">Your shopping cart is empty</string>
<string name="Snabble.Shoppingcart.articleRemoved">Product removed</string>
<string name="Snabble.Shoppingcart.buyProducts">Buy %1$d products for %2$s</string>
<string name="Snabble.Shoppingcart.completePurchase">Complete purchase</string>
<string name="Snabble.Shoppingcart.coupon">Coupon</string>
<string name="Snabble.Shoppingcart.coupons">Coupons</string>
<string name="Snabble.Shoppingcart.deposit">Deposit</string>
Expand Down

0 comments on commit 9bf10bf

Please sign in to comment.