From c22e1f1f9cb6816fbddad4cbf053674b8a9fe21c Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Wed, 7 Aug 2024 18:43:25 +0100 Subject: [PATCH 1/5] Bump fluxc --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0054b8af24a..026843c8c5a 100644 --- a/build.gradle +++ b/build.gradle @@ -99,7 +99,7 @@ tasks.register("installGitHooks", Copy) { } ext { - fluxCVersion = 'trunk-06355b8e708b8303653a5e1afb751c25d469c40e' + fluxCVersion = '3074-a62356b48909fe33933b0330c594a04faee34e6f' glideVersion = '4.16.0' coilVersion = '2.1.0' constraintLayoutVersion = '1.2.0' From 16c92797c3f3d12d830eda0a8eb6cb3ae6139c08 Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Thu, 8 Aug 2024 11:04:22 +0100 Subject: [PATCH 2/5] Update Product model to expose bundle min/max sizes This aligns with the change to remove saving the sizes as metadata --- .../main/kotlin/com/woocommerce/android/model/Product.kt | 4 ++++ .../android/ui/orders/creation/GetProductRules.kt | 8 +------- .../com/woocommerce/android/ui/products/ProductHelper.kt | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) 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 ) From efc5ac94c8cbd139d8284ad297a2c64cefd4d9f1 Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Fri, 9 Aug 2024 16:47:24 +0100 Subject: [PATCH 3/5] Fix function --- .../android/ui/products/details/ProductDetailRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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") From 2004aaa2d7d8915acda3867b4295495af598a8b6 Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Fri, 9 Aug 2024 17:40:44 +0100 Subject: [PATCH 4/5] Fix unit tests --- .../android/ui/products/addons/AddonTestFixtures.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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() } From c02705d2aacfe45b39996cd07dd776684069d14f Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Thu, 15 Aug 2024 16:08:08 +0100 Subject: [PATCH 5/5] Bump fluxc --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 026843c8c5a..38680f72cfd 100644 --- a/build.gradle +++ b/build.gradle @@ -99,7 +99,7 @@ tasks.register("installGitHooks", Copy) { } ext { - fluxCVersion = '3074-a62356b48909fe33933b0330c594a04faee34e6f' + fluxCVersion = 'trunk-6c8bfe8b38b9e29649d32dc80b433977e31b4d99' glideVersion = '4.16.0' coilVersion = '2.1.0' constraintLayoutVersion = '1.2.0'