+
Skip to content

Emitting afterAddTagsToProducts, afterTagDelete, afterRemoveTagsFromProducts #6541

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

6 changes: 6 additions & 0 deletions .changeset/beige-doors-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@reactioncommerce/api-plugin-products": minor
"@reactioncommerce/api-plugin-tags": minor
---

Added afterAddTagsToProducts, afterTagDelete, afterRemoveTagsFromProducts events when respective mutations are called.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import executeBulkOperation from "../utils/executeBulkOperation.js";
*/
export default async function addTagsToProducts(context, input) {
const { productIds, shopId, tagIds } = input;
const { collections: { Products } } = context;
const { appEvents, collections: { Products } } = context;
const totalProducts = productIds.length;

for (const _id of productIds) {
Expand All @@ -39,5 +39,7 @@ export default async function addTagsToProducts(context, input) {

const results = await executeBulkOperation(Products, operations, totalProducts);

await Promise.all(tagIds.map((tagId) => appEvents.emit("afterAddTagsToProducts", { tagId, productIds })));

return results;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import executeBulkOperation from "../utils/executeBulkOperation.js";
*/
export default async function removeTagsFromProducts(context, input) {
const { productIds, shopId, tagIds } = input;
const { collections: { Products } } = context;
const { appEvents, collections: { Products } } = context;
const totalProducts = productIds.length;

for (const _id of productIds) {
Expand All @@ -40,5 +40,7 @@ export default async function removeTagsFromProducts(context, input) {

const results = await executeBulkOperation(Products, operations, totalProducts);

await Promise.all(tagIds.map((tagId) => appEvents.emit("afterRemoveTagsFromProducts", { tagId, productIds })));

return results;
}
4 changes: 3 additions & 1 deletion packages/api-plugin-tags/src/mutations/removeTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ReactionError from "@reactioncommerce/reaction-error";
*/
export default async function removeTag(context, input) {
const { shopId, tagId } = input;
const { Tags } = context.collections;
const { appEvents, collections: { Tags } } = context;

await context.validatePermissions(`reaction:legacy:tags:${tagId}`, "delete", { shopId });

Expand All @@ -22,5 +22,7 @@ export default async function removeTag(context, input) {
throw new ReactionError("not-found", "Tag not found");
}

await appEvents.emit("afterTagDelete", tag);

return tag;
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载