-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Duplicate existing Product #627
Comments
I think "duplicate product" is probably something I'll include as standard. Maybe we can have an API where you can choose which properties of the current product to duplicate. Thus for your case you could check the "facets" and leave the rest as default (empty). |
Yes, that sounds awesome! If you want you can close this request, if you have it already on your agenda. |
If anyone in need of this right now, here's simple plugin that allows to duplicate product and product variant with all data: |
+1 for this feature, I would find it very important. |
Ideally I would like to be able to offer a generic "duplicate" mutation that is potentially capable of duplicating any entity. Something like this: GraphQL APIinput DuplicateEntityInput {
entityName: String!
entityId: ID!
}
type DuplicateEntitySuccess {
newEntityId: ID!
}
type DuplicateEntityError implements ErrorResult {
errorCode: ErrorCode!
message: String!
duplicationError: String!
}
union DuplicateEntityResult = DuplicateEntitySuccess | DuplicateEntityError
extend type Mutation {
duplicateEntity(input: DuplicateEntityInput!): DuplicateEntityResult
} Server ImplementationThen we need to have a way to provide the actual logic used when duplicating a particular entity. To make this able to also be able to handle custom entities too, we could add a new config option like this: interface VendureConfig {
// ...
entityOptions: {
entityDuplicationStrategy: EntityDuplicationStrategy[];
}
}
interface EntityDuplicationStrategy extends InjectableStrategy {
canDuplicate(entityName: string): boolean;
duplicate(ctx: RequestContext, entityName: string, id: ID): Promise<VendureEntity>;
} this allows us to provide any number of strategies for handling the duplication of given entities. A single strategy for e.g. export class ProductDuplicationStrategy implements EntityDuplicationStrategy {
private connection: TransactionalConnection;
init(injector: Injector) {
this.connection = injector.get(TransactionalConnection);
}
canDuplicate(entityName: string) {
return entityName === 'Product';
}
async duplicate(ctx: RequestContext, entityName: string, id: ID) {
const product = await this.connection.getEntityOrThrow(ctx, Product, id);
// specific logic to duplicate the product omitted;
return newProduct;
}
} PermissionsWe'd need to make sure to restrict the Configurable duplicationIn my comment above I talk about the idea of being able to select which properties of an entity to duplicate. Supporting this in a generic way would introduce quite a bit of complexity, but it is worth considering how it might be supported. Or perhaps allowing a strategy to define a set of options that it is then free to interpret during the duplication process, which could be used to allow selective duplication, or even allow other types of sophisticated duplication. Admin UIWe'd then want some UI controls that allow the admin to duplicate an entity. This could be done from either
I personally think it makes the most sense from the list view, but we'd need to keep in mind what happens if a user has multiple entities selected. Maybe we make the mutation input accept an array of IDs, and on the server we just call the strategy Default strategiesThen Vendure would ship with a set of strategies to handle duplication of the most common entities. We can add to these over time to increase coverage, but initially I would consider (in order of importance):
|
I would suggest adding the option to copy-duplicate a product to a different channel. For us, it's not so much about duplicating a product as much as it is copying instead of referencing a product on another channel |
With the new API you'll be able to write a custom duplicator that will do exactly this, including having a widget where you can specify the target channel in the admin ui. |
Good thing I did a quick search before implementing this as a plugin this time 😆 Some other things that came to mind for duplicating a product:
I think all of these make sense to have as default behaviour, but I might be a bit biased 🙃 We can help on implementing the Product duplicator strategy, but I am unsure wether we have the time to contribute on the generic duplicate interface part. |
@martijnvdbrug the generic duplicate interface is all done already! see the commits referenced above. You can take a look at the current implementation of product duplication - it is less comprehensive than your suggestions so feel free to PR improvements! |
Is this going to be in V2 already? Or only the backend? Or inlcuding admin Ui part? |
v2.2 yeah. It's in there already including the Admin UI part. You can test it quickly with |
@michaelbromley Be aware that copying prices is missing from the copy function when you include variants. Consequently, all prices on a copied product variants are zero. Bug or Intentional? |
@mschipperheyn sounds like a bug, because I believe this line is supposed to take care of making sure a price gets created. |
Is your feature request related to a problem? Please describe.
When adding a product which is similar to existing ones, I often open a product in another tab while creating a new one, so I don't forget to add the same kind of facets.
Describe the solution you'd like
It would be cool if product facets could be taken from an existing product.
Describe alternatives you've considered
Maybe this problem is to specific and writing my own plugin would be better. Or a more general solution, like the ability to duplicate a product as whole.
The text was updated successfully, but these errors were encountered: