Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Upgrading to DW 9.6.1 Concrete Ecom Product Urls to Catalog Module (App)

Upgrading to DW 9.6.1 Concrete Ecom Product Urls to Catalog Module (App)

Kevin O'Driscoll
Reply

In my DW8 version I can do this:
        /// <summary>
        /// Looks up the Url for the Product in a site (Area) having searched through all the eCom_Catalog modules in the site
        /// finding the first availability of the Product in a Group attached to a correct eCom_Catalog module. Returns the Url to the module to find the Product.
        /// </summary>
        /// <param name="Product">The Product Object you need the Url to.</param>
        /// <param name="areaId">The Area.ID from the Page.</param>
        /// <returns>The Url.</returns>
        public static string GetProductUrl(Product product, int areaId)
        {
            IEnumerable<Paragraph> areaModuleParagraphs = Paragraph.GetParagraphsByModuleName("eCom_Catalog")
                .Where(n => n.Page.AreaID == areaId && !n.Page.Hidden && n.Page.Active);  // There are 130 in Area 1

            Dynamicweb.eCommerce.Products.GroupCollection productGroups = product.Groups;

            var productPageUrl = string.Empty;
            var productPageLink = string.Empty;

            foreach (var paragraph in areaModuleParagraphs)
            {
                Dynamicweb.Properties properties = Dynamicweb.Base.GetParagraphModuleSettings(paragraph.ID);
                ProductsAndGroupsHandler productGroupSelector = new ProductsAndGroupsHandler(properties["ProductAndGroupsSelector"]);

                foreach (var group in productGroups)
                {
                    if (productGroupSelector.GroupsSelected.Contains(group))
                    {
                        // DW throws a null ref exception at .GetFriendlyUrl if there is no pageview loaded in context
                        Dynamicweb.Frontend.PageView pw = Dynamicweb.Frontend.PageView.GetPageviewByPageID(paragraph.PageID);
                        pw.Load();

                        if (!string.IsNullOrEmpty(product.VariantID))
                        {
                            productPageUrl = "Default.aspx?ID=" + paragraph.PageID + "&ProductID=" + product.ID + "&VariantID=" + product.VariantID;
                        }
                        else
                        {
                            productPageUrl = "Default.aspx?ID=" + paragraph.PageID + "&ProductID=" + product.ID;
                        }

                        productPageLink = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(productPageUrl);

                        if (!String.IsNullOrEmpty(productPageLink))
                        {
                            return productPageLink;
                        }
                    }
                }
            }

            return productPageLink;
        }
Its a bit verbose and convaluted but it works well. (Does not work for Smart Searches)
In 9 I try:
List<Paragraph> areaModuleParagraphs = Dynamicweb.Extensibility.ServiceLocator.Current.GetParagraphService().GetParagraphsByModuleName("eCom_Catalog")
                .Where(n => n.Page.AreaId == areaId && !n.Page.Hidden && n.Page.Active).ToList();
But there are no Groups selected in productGroupSelector.GroupsSelected. "{all}"

Could my approach be better here or am I missing something new in DW9??

Rgds
Kevin


Replies

 
Kevin O'Driscoll
Reply

And now in Admin what seems to be a related problem. If we want to edit an eCom_Catalog module in a paragraph it does not load and our languages are messed up:

Ive attached a screenshot and the event error

 

Rgds

Kevin

 

ModuleError.JPG
 
Nicolai Pedersen
Reply

That language dropdown indicates that your data is f***cked up...

I cannot give you a pointer to what is wrong - I am affraid that requires some investigation on your database to see what is wrong. That is out of scope for the forums...

 
Kevin O'Driscoll
Reply

Hi Nicolai. Just that ******** comment will do.
We now found same issues in Live and staging (DW8), but all frontend functionalities work ok.
So we now investigate the latest data integrations from the client.

 
Nicolai Pedersen
Reply

Glad you found something and pardon my french smiley

 

You must be logged in to post in the forum