-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
sync inventory policy toggle between top-level variants and child variants #3004
Conversation
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.
One lint problem and a couple of question but this seems to be working well.
@@ -195,6 +199,44 @@ const wrapComponent = (Comp) => ( | |||
Meteor.call("products/updateProductField", variant._id, "isVisible", !variant.isVisible); | |||
} | |||
|
|||
/** | |||
* @method updateInventoryPolicyIfChildVariants | |||
* @description update parent inventory policy if variant has children children |
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.
typo? "children children"
const parent = ReactionProduct.getVariantParent(variant); | ||
|
||
// If this is not a top-level variant, update top-level inventory policy as well | ||
if (parent) { |
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.
Could we combine this into one conditional e.g. if (parent && options && options.length)
?
@@ -6,6 +6,7 @@ import Velocity from "velocity-animate"; | |||
import "velocity-animate/velocity.ui"; | |||
import { Components } from "@reactioncommerce/reaction-components"; | |||
import { formatPriceString } from "/client/api"; | |||
import { Reaction } from "/lib/api"; |
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.
Imported but not used.
So is the default behavior supposed to be that if I create an option for a product it's "disabled" at the top level forever more? |
@zenweasel
yes |
Resolves #2911
ReactionProduct.getSiblings()
to get documents of a variantssiblings
, who have the same ancestor treeReactionProduct.getParent()
to get document of a variants direct parentIf a variant has no child variants, the toggle functionality is unchanged.
If a variant has child variants, the toggle is disabled on the top-level variant, and inherits the following value, based on it's children:
inventoryPolicy === false
, meaning backorders are allowed, then the top-level variant will also be set toinventoryPolicy === false
inventoryPolicy === true
, then the top-level variant will also be set toinventoryPolicy === true