-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add updateProductVariantPrices mutation to API #5910
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
feat: add updateProductVariantPrices mutation to API #5910
Conversation
Signed-off-by: Ross Hadden <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
…issionsOnFirstShop fix: remove check for shopId where not needed
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
b8c75da to
66d38a3
Compare
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
…ub.com:reactioncommerce/reaction into feat-kieckhafer-addPriceToUpdateProductVariant
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
src/plugins/simple-pricing/mutations/updateProductVariantPrices.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Erik Kieckhafer <[email protected]>
src/plugins/simple-pricing/mutations/updateProductVariantPrices.js
Outdated
Show resolved
Hide resolved
src/plugins/simple-pricing/mutations/updateProductVariantPrices.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Erik Kieckhafer <[email protected]>
|
@mikemurray @aldeed all comments addressed |
Signed-off-by: Erik Kieckhafer <[email protected]>
aldeed
left a comment
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.
@kieckhafer One thing, or series of things, I noticed
| const updatedProduct = Products.findOne({ _id: variantId, shopId }); | ||
| if (!updatedProduct) throw new ReactionError("error-occurred", "Unable to update variant prices"); | ||
|
|
||
| appEvents.emit("afterVariantUpdate", { productId: variantId, product: updatedProduct }); |
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.
@kieckhafer It looks like the correct way to emit this as is currently done in reaction admin is
appEvents.emit("afterVariantUpdate", { _id, field, value });
Where _id is the variant ID and it is called once per field that was changed.
I also noticed that in src/core-services/catalog/startup.js, it is looking for productId, which we never even emit, and using it as the variant ID (not product). BUT it actually just uses it to GET the product ID. So...
Can you?
- Change this to emit once per changed field (price and/or compareAtPrice)
- Emit with this signature:
{ _id: variantId, productId: updatedProduct.ancestors[0], variant: updatedProduct, field, value } - Change the event consumer in
src/core-services/catalog/startup.jsto this:
appEvents.on("afterVariantUpdate", async ({ productId }) => {
hashRelatedProduct(productId, collections).catch((error) => {
Logger.error("Error in afterVariantUpdate", error);
});
});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.
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
Signed-off-by: Erik Kieckhafer <[email protected]>
|
I updated this to point to |
|
Approved code. Didn't test |
mikemurray
left a comment
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.
👍
Impact: minor
Type: feature
Issue
There is no way to update price of a variant via the API
Solution
Add a new mutation,
updateProductVariantPrices, to thesimple-pricingpackage.Breaking changes
None
Testing
pricevia theupdateProductVariantPricesmutation