+
Skip to content

Set default ff-type for shop to be used in CreateProduct #6543

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const defaultShopManagerRoles = [
"reaction:legacy:products/update:prices",
"reaction:legacy:products/update",
"reaction:legacy:shipping-rates/update:settings",
"reaction:legacy:fulfillmentTypes/update:settings",
"reaction:legacy:fulfillmentTypes/create",
"reaction:legacy:fulfillmentTypes/delete",
"reaction:legacy:fulfillmentTypes/read",
Expand Down
16 changes: 16 additions & 0 deletions packages/api-plugin-fulfillment/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ export default async function register(app) {
},
simpleSchemas: {
MethodEmptyData
},
shopSettingsConfig: {
baseFulfillmentTypesForShop: {
permissionsThatCanEdit: ["reaction:legacy:fulfillmentTypes/update:settings"],
simpleSchema: {
type: {
"baseFulfillmentTypesForShop": {
type: Array,
optional: true
},
"baseFulfillmentTypesForShop.$": {
type: String
}
}
}
}
}
});
}
14 changes: 14 additions & 0 deletions packages/api-plugin-fulfillment/src/schemas/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
extend type ShopSettings {
"""
List of fulfillment types that will be added to each new product by default
"""
baseFulfillmentTypesForShop: [FulfillmentType]
}

extend input ShopSettingsUpdates {
"""
The input for default fulfillment type for shop should be one of the installed fulfillment type plugin
"""
baseFulfillmentTypesForShop: [FulfillmentType]
}

"Allowed fulfillment types, extended by fulfillment-type plugins"
enum FulfillmentType {
"Default fulfillment type when none is decided by user"
Expand Down
12 changes: 11 additions & 1 deletion packages/api-plugin-products/src/mutations/createProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default async function createProduct(context, input) {
throw new ReactionError("invalid-param", "Creating a deleted product is not allowed");
}

// Include the base/shop-level fulfillment types for all products
// if user has provided additional fulfillment types, include them also
const { baseFulfillmentTypesForShop } = await context.queries.appSettings(context, shopId);
const { supportedFulfillmentTypes } = initialProductData;
let combinedSupportedFulfillmentTypes = [];
if (baseFulfillmentTypesForShop) combinedSupportedFulfillmentTypes = [...baseFulfillmentTypesForShop];
if (supportedFulfillmentTypes) combinedSupportedFulfillmentTypes = [...combinedSupportedFulfillmentTypes, ...supportedFulfillmentTypes];
combinedSupportedFulfillmentTypes = [...new Set(combinedSupportedFulfillmentTypes)];
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong. If a product has supportedFulfillmentTypes supplied when creating it, wouldn't you want to keep that as is? I would think it would just be:

supportedFulfillmentTypes: initialProductData.supportedFulfillmentTypes || defaultFulfillmentTypesForShop || []

If the intention is to force every produce to support these, then another prefix like base or global might be a better name than default for the setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aldeed
Yes, my intention was to add the user provided supportedFulfillmentTypes to the base entries defined for the Shop. But either of them could be undefined. That is the reason I did so.
As you mentioned, base would be a better name than default in the shopSettings.


const createdAt = new Date();
const newProduct = {
_id: newProductId,
Expand All @@ -59,7 +68,6 @@ export default async function createProduct(context, input) {
isVisible: false,
shopId,
shouldAppearInSitemap: true,
supportedFulfillmentTypes: initialProductData.supportedFulfillmentTypes || [],
title: "",
type: "simple",
updatedAt: createdAt,
Expand All @@ -68,6 +76,8 @@ export default async function createProduct(context, input) {
},
...initialProductData
};
// Adding this outside to ensure that this is not over-written by the original initialProductData.supportedFulfillmentTypes
newProduct.supportedFulfillmentTypes = combinedSupportedFulfillmentTypes || [];

// Apply custom transformations from plugins.
for (const customFunc of context.getFunctionsOfType("mutateNewProductBeforeCreate")) {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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