Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Tolu Jemilua 39 posts 166 karma points
    Aug 04, 2017 @ 08:31
    Tolu Jemilua

    How to create collections under Products using code

    Is there any way to create a collection under Products Manually using code? Currently I am using IEntityCollectionsService as so.

    var collection = this.MerchelloServices.EntityCollectionService.CreateEntityCollectionWithKey(EntityType.Product, Guid.NewGuid(), "Iconic Collection");

    it saves into the EntityCollectionsTable in the database and doesn't appear under Products even though the entity type set is products, also when I refresh Merchello, its deleted from the table. Anyone have any idea on how to manually create a collection?

  • Puck Holshuijsen 179 posts 712 karma points
    Aug 04, 2017 @ 11:14
    Puck Holshuijsen

    I believe it has to do with the Guid.NewGuid().

    If you change it to:


    it should work I think.


  • Tolu Jemilua 39 posts 166 karma points
    Aug 07, 2017 @ 12:21
    Tolu Jemilua

    Thank you so much, I was battling with this all weekend, who would have thought this is all it took

  • Puck Holshuijsen 179 posts 712 karma points
    Aug 07, 2017 @ 12:35
    Puck Holshuijsen

    Great to hear! Glad I was able to help

  • Tolu Jemilua 39 posts 166 karma points
    Aug 07, 2017 @ 14:26
    Tolu Jemilua

    If you don't mind, I would also like to know how to create child collections, I tried using the collection keys create above as the provider key with no success

    currently I have:

    foreach (var subCollection in sec.Subsections) {
                    var sub = this.MerchelloServices.EntityCollectionService.CreateEntityCollectionWithKey(EntityType.Product, collection.Key, subCollection.Name);

    I had hoped there would be a createChildCollection method against the collection

  • Puck Holshuijsen 179 posts 712 karma points
    Aug 07, 2017 @ 14:31
    Puck Holshuijsen

    Basically what you have to do, is create a second collection, and pass the ParentKey to that collection.

    So in short:

    var parent = merchelloServices.EntityCollectionService.CreateEntityCollection(
                        "parent collection");
            var child = merchelloServices.EntityCollectionService.CreateEntityCollection(
                        "Child collection");
            child.ParentKey = parent.Key;
            // Save the collections
            merchelloServices.EntityCollectionService.Save(new[] { parent, child });

    That should do it

  • Simon 692 posts 1068 karma points
    Jul 02, 2019 @ 12:24


    I tried the exact code below, but when I go and find the new collection, I am getting this error :

    enter image description here

    Any help would much be appreciated what I am doing wrong.

Please Sign in or register to post replies

Write your reply to: