diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/model/Product.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/model/Product.kt index 4b0fa6e712f..ef373bb37c3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/model/Product.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/model/Product.kt @@ -89,6 +89,8 @@ data class Product( val isConfigurable: Boolean = false, val minAllowedQuantity: Int?, val maxAllowedQuantity: Int?, + val bundleMinSize: Float?, + val bundleMaxSize: Float?, val groupOfQuantity: Int?, val combineVariationQuantities: Boolean? ) : Parcelable, IProduct { @@ -585,6 +587,8 @@ fun WCProductModel.toAppModel(): Product { isConfigurable = isConfigurable, minAllowedQuantity = this.getMinAllowedQuantity(), maxAllowedQuantity = this.maxAllowedQuantity(), + bundleMinSize = this.bundleMinSize, + bundleMaxSize = this.bundleMaxSize, groupOfQuantity = this.groupOfQuantity(), combineVariationQuantities = this.combineVariationQuantities ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/GetProductRules.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/GetProductRules.kt index 62d9c98abb7..9eb43f8360c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/GetProductRules.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/GetProductRules.kt @@ -7,8 +7,6 @@ import com.woocommerce.android.ui.products.GetBundledProducts import com.woocommerce.android.ui.products.ProductType import com.woocommerce.android.ui.products.details.ProductDetailRepository import kotlinx.coroutines.flow.first -import org.wordpress.android.fluxc.model.WCMetaData -import org.wordpress.android.fluxc.model.get import javax.inject.Inject class GetProductRules @Inject constructor( @@ -30,11 +28,7 @@ class GetProductRules @Inject constructor( val builder = ProductRules.Builder().apply { productType = ProductType.BUNDLE } - productDetailRepository.getProductMetadata(product.remoteId)?.let { list -> - val maxSize = list[WCMetaData.BundleMetadataKeys.BUNDLE_MAX_SIZE]?.valueAsString?.toFloatOrNull() - val minSize = list[WCMetaData.BundleMetadataKeys.BUNDLE_MIN_SIZE]?.valueAsString?.toFloatOrNull() - builder.setQuantityRules(minSize, maxSize) - } + builder.setQuantityRules(quantityMin = product.bundleMinSize, quantityMax = product.bundleMaxSize) getBundledProducts(product.remoteId).first().forEach { bundledProduct -> builder.setChildQuantityRules( itemId = bundledProduct.id, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductHelper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductHelper.kt index b0dcf1461d6..d639a19e612 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductHelper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductHelper.kt @@ -103,6 +103,8 @@ object ProductHelper { parentId = 0, minAllowedQuantity = null, maxAllowedQuantity = null, + bundleMinSize = null, + bundleMaxSize = null, groupOfQuantity = null, combineVariationQuantities = null ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailRepository.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailRepository.kt index 2787e4ca116..454b2d52ce0 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailRepository.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailRepository.kt @@ -301,8 +301,8 @@ class ProductDetailRepository @Inject constructor( } } - fun getProductMetadata(remoteProductId: Long): List? { - return getCachedWCProductModel(remoteProductId)?.parsedMetaData ?: return null + suspend fun getProductMetadata(remoteProductId: Long): List { + return productStore.getProductMetaData(selectedSite.get(), remoteProductId) } @SuppressWarnings("unused") diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/addons/AddonTestFixtures.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/addons/AddonTestFixtures.kt index 8e750314f48..35fcf962417 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/addons/AddonTestFixtures.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/addons/AddonTestFixtures.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.products.addons +import com.google.gson.Gson import com.woocommerce.android.model.Order.Item.Attribute import com.woocommerce.android.ui.orders.OrderTestUtils import com.woocommerce.android.util.UnitTestUtils.jsonFileAs @@ -7,7 +8,10 @@ import com.woocommerce.android.util.UnitTestUtils.jsonFileToString import org.wordpress.android.fluxc.domain.Addon import org.wordpress.android.fluxc.domain.Addon.HasAdjustablePrice.Price.Adjusted.* import org.wordpress.android.fluxc.model.OrderEntity +import org.wordpress.android.fluxc.model.WCMetaData import org.wordpress.android.fluxc.model.WCProductModel +import org.wordpress.android.fluxc.model.addons.RemoteAddonDto +import org.wordpress.android.fluxc.model.get import org.wordpress.android.fluxc.model.order.LineItem import org.wordpress.android.fluxc.network.rest.wpcom.wc.addons.mappers.RemoteAddonMapper @@ -49,14 +53,15 @@ object AddonTestFixtures { .apply { attributes = "[]" status = "draft" - metadata = "mocks/product_addon_metadata.json".jsonFileToString() ?: "" } } val defaultProductAddonList by lazy { - defaultWCProductModel - .addons - ?.map { remoteAddonDto -> RemoteAddonMapper.toDomain(remoteAddonDto) } + "mocks/product_addon_metadata.json".jsonFileToString() + ?.let { Gson().fromJson(it, Array::class.java).toList() } + ?.let { it[WCMetaData.AddOnsMetadataKeys.ADDONS_METADATA_KEY] } + ?.let { RemoteAddonDto.fromMetaDataValue(it.value) } + ?.map { RemoteAddonMapper.toDomain(it) } .orEmpty() } diff --git a/build.gradle b/build.gradle index d6847873a68..450d948ca96 100644 --- a/build.gradle +++ b/build.gradle @@ -99,7 +99,7 @@ tasks.register("installGitHooks", Copy) { } ext { - fluxCVersion = '2.92.1' + fluxCVersion = 'trunk-6c8bfe8b38b9e29649d32dc80b433977e31b4d99' glideVersion = '4.16.0' coilVersion = '2.1.0' constraintLayoutVersion = '1.2.0'