Developer forum

Forum » PIM » GroupId and ShopID in Feed Template using Channels

GroupId and ShopID in Feed Template using Channels

Thaw Htun Lynn
Reply

Hello,

We have a PIM project with marketplace integration where I will have multiple channel which are mapped to different dealer accounts in marketplace. Groups under the channels are mapped to different category under different dealer accounts. I will have multiple channels but I am using only one feed template to create the payload xml using ProductListViewModel in the Feed Template. I am not able to get the GroupId and ShopID of the product from this model. Since the Group ID of a channel is not the primary group for product, I am not able to get it using product service unless I know the ShopID. 

Is there a way if I can retrieve the Channel Group ID the product is in and ShopID of the channel from Feed Template?

Thanks and regards,

Thaw


Replies

 
Søren Jensen Dynamicweb Employee
Søren Jensen
Reply

Hi Thaw,

You can in the Feeds UI, select the Channel/Shop you want to use as information background..

and then you can add following in the Feed template, to get the Group informations (example below)

-----------------------------
        var relations = Dynamicweb.Ecommerce.Products.ProductGroupRelation.GetProductGroupRelations(product.Id);
        foreach (var group in relations.GroupCollection.Where(g => g.ShopId == Dynamicweb.Context.Current.Request.GetString("Shopid")))
        {
            productElement.Add(createElement("Group", string.Empty, group.Name, false));
            var parentGroup = group.ParentGroups.FirstOrDefault();
            if (parentGroup != null)
            {
                productElement.Add(createElement("MainGroup", string.Empty, parentGroup.Name, false));
            }
        }
------------------------
 
hopefully you can use it
 
Best regards
Søren
 

 

 

 
Thaw Htun Lynn
Reply

Dear Søren,

Thank you for your code sample. If I can get the ShopId from Dynamicweb.Context, I will be able to get the group id for the product.

Best regards,

Thaw

 
Thaw Htun Lynn
Reply

Dear Søren,

The Dynamicweb.Context.Current.Request.GetString("Shopid")) is working when I call the feed template from the browser using the link in the feed.

But it return null when I try to get the content of the feed by using the code below from scheduleTaskAddIn. I configure the feed context and I can get the correct shop Id from below code but it is return as null in the feed template so feedProvider.GetOutput function return an exception. Is there anything I am missing in my code?

--------------------------------------------------------------------------

Feed feed = Dynamicweb.Ecommerce.Services.Feeds.GetFeed(this.FeedId);
            FeedProvider feedProvider = AddInManager.CreateAddInInstance(feed.Provider) as FeedProvider;
            string output = feedProvider.GetOutput(feed, new FeedContextConfiguration()
            {
                CurrencyId = this.Currency,
                LanguageId = this.Language,
                ShopId = this.Shop                
            });
            feedProvider.GetContentType();

-----------------------------------------------------------------------------

Best regards,
Thaw

 
Thaw Htun Lynn
Reply

Hello,

Any suggestion how I can pass the shop id from schedule task handler using feed provider? I tried passign the shop id as per above code but it doens't seem to be working. Currently, i need to hardcode the shop ID in feed template which required for me to create multiple feeds because we have multiple accounts depending on the different shopID.

 

Best regards,

Thaw

 

You must be logged in to post in the forum