Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kieckhafer
Copy link
Member

@kieckhafer kieckhafer commented Dec 12, 2019

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 the simple-pricing package.

Breaking changes

None

Testing

  1. See that you can update price via the updateProductVariantPrices mutation
mutation {
  updateProductVariantPrices(input: {
shopId: "{encoded-shop-id}"
    variantId: "{encoded-product-id}",
    prices: {
      price: 19.99
      compareAtPrice: 29.99
    }
  }) {
    clientMutationId
  }
}

rosshadden and others added 6 commits December 9, 2019 17:52
Signed-off-by: Ross Hadden <[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]>
@kieckhafer kieckhafer force-pushed the feat-kieckhafer-addPriceToUpdateProductVariant branch from b8c75da to 66d38a3 Compare December 12, 2019 20:15
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]>
@kieckhafer kieckhafer changed the title add price to updateProductVariant input feat: add updateProductVariantPrices mutation to API Dec 12, 2019
Signed-off-by: Erik Kieckhafer <[email protected]>
@kieckhafer kieckhafer marked this pull request as ready for review December 12, 2019 22:39
@kieckhafer
Copy link
Member Author

@mikemurray @aldeed all comments addressed

Copy link
Contributor

@aldeed aldeed left a 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 });
Copy link
Contributor

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.js to this:
appEvents.on("afterVariantUpdate", async ({ productId }) => {
    hashRelatedProduct(productId, collections).catch((error) => {
      Logger.error("Error in afterVariantUpdate", error);
    });
  });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldeed I think this takes care of it: 92a2966

Not sure if looping over the object like that is the best way to do it though.

Signed-off-by: Erik Kieckhafer <[email protected]>
@kieckhafer kieckhafer changed the base branch from release-v3.0.0-alpha to release-3.0.0 December 12, 2019 23:29
@kieckhafer
Copy link
Member Author

I updated this to point to release-3.0.0 instead of the alpha branch. This was branched off alpha, so it'll need to wait to be merged until alpha is released and merged back into release-3.0.0

@aldeed
Copy link
Contributor

aldeed commented Dec 13, 2019

Approved code. Didn't test

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mikemurray mikemurray merged commit b8c48cb into release-3.0.0 Dec 16, 2019
@mikemurray mikemurray deleted the feat-kieckhafer-addPriceToUpdateProductVariant branch December 16, 2019 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants