Skip to content

Commit

Permalink
Merge pull request #12252 from woocommerce/issue/12212-meta-data-chan…
Browse files Browse the repository at this point in the history
…ges-2

[Custom Fields] Metadata refactor - part 2
  • Loading branch information
hichamboushaba authored Aug 15, 2024
2 parents 82f8500 + e82f073 commit 9520913
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ object ProductHelper {
parentId = 0,
minAllowedQuantity = null,
maxAllowedQuantity = null,
bundleMinSize = null,
bundleMaxSize = null,
groupOfQuantity = null,
combineVariationQuantities = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class ProductDetailRepository @Inject constructor(
}
}

fun getProductMetadata(remoteProductId: Long): List<WCMetaData>? {
return getCachedWCProductModel(remoteProductId)?.parsedMetaData ?: return null
suspend fun getProductMetadata(remoteProductId: Long): List<WCMetaData> {
return productStore.getProductMetaData(selectedSite.get(), remoteProductId)
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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
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

Expand Down Expand Up @@ -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<WCMetaData>::class.java).toList() }
?.let { it[WCMetaData.AddOnsMetadataKeys.ADDONS_METADATA_KEY] }
?.let { RemoteAddonDto.fromMetaDataValue(it.value) }
?.map { RemoteAddonMapper.toDomain(it) }
.orEmpty()
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 9520913

Please sign in to comment.