-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundle quantity rules support #2883
Bundle quantity rules support #2883
Conversation
val hasBundleMinQuantityRule = response.bundle_min_size.isNullOrEmpty().not() | ||
val hasBundleMaxQuantityRule = response.bundle_max_size.isNullOrEmpty().not() | ||
val hasBundleQuantityRules = hasBundleMinQuantityRule || hasBundleMaxQuantityRule | ||
|
||
metadata = if ( | ||
isBundledProduct | ||
&& response.metadata != null | ||
&& hasBundleQuantityRules | ||
) { | ||
response.bundle_max_size?.let { value -> | ||
WCMetaData.addAsMetadata(response.metadata, BUNDLE_MAX_SIZE, value) | ||
} | ||
response.bundle_min_size?.let { value -> | ||
WCMetaData.addAsMetadata(response.metadata, BUNDLE_MIN_SIZE, value) | ||
} | ||
response.metadata.toString() | ||
} else { | ||
response.metadata?.toString() ?: "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: It seems we're adding multiple checks over the bundle rules. I also see one at the top of the asProductModel
call. Maybe we could benefit from a code extraction to a function in this response class to make it easier to concentrate on all the bundle behaviors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested alongside the changes of #2882. Looks good! I only left a comment over code organization as the asProductModel
is getting bigger and more complex.
…antity-rules-support
…41-bundle-variable-support
…to issue/9541-bundle-quantity-rules-support
…41-bundle-variable-support
…41-bundle-variable-support
…able-support Bundle variable support
return applyBundledProductChanges(model) | ||
} | ||
|
||
private fun applyBundledProductChanges(model: WCProductModel): WCProductModel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atorresveiga I'm working on some refactorings to allow extracting the product metadata
to a separate table, and while doing so I stumbled upon this logic that you added to add the properties regarding bundle
to the meta_data
Json instead of exposing them as regular properties in the WCProductModel
.
Can I ask what was the reason for choosing this path? This was causing the WCMetaData
object to be returned with null id
s, Gson allowed this as it doesn't support Kotlin's nullability, but it's still problematic.
With the upcoming PR, I'm intending to remove the meta_data
column completely from the WCProductModel
, and I will need to make changes to this logic too, is it OK if I make these keys as regular properties of the model instead of the current logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Hicham, thanks for the ping
Can I ask what was the reason for choosing this path?
I chose this path with the goal in mind of keeping the product model small.
is it OK if I make these keys as regular properties of the model instead of the current logic?
Yes, feel free to make those regular properties of the product model 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the clarifications @atorresveiga, I'll make those changes.
Why
As part of the support for extensions milestone 2, we are working on support bundle products in the order creation flow.
Description
This PR brings support to the bundle quantity rules in the App. It fetches the bundle min and max quantity rules and saves them as part of the product metadata.
Description
It is better to test these changes in the Woo PR