Product Tag URL Upgrade

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
I upgraded from 3.5 to 4.10 and it looks like at some point product tag URLS switched. They went from mystore.com/producttag/### to mystore.com/[slug] and are now in the URLRecord table.

It doesn't seem that there's a built-in redirect for this unless I'm missing it. Has anyone come up with an automated way to fix all of these /producttag/ urls which are now coming up as 404?
5 years ago
You're aboslutely right. We missed it. But you can easily add its support in BackwardCompatibility2XController file the same way it's done for other entities
5 years ago
Thanks for that! I edited the file but routing is not working. I'm not sure what to look at next.


private readonly IProductTagService _productTagService;
....
public BackwardCompatibility2XController(IBlogService blogService,
            ICategoryService categoryService,
            IManufacturerService manufacturerService,
            INewsService newsService,
            IProductService productService,
            ITopicService topicService,
            IUrlRecordService urlRecordService,
            IVendorService vendorService,
            IProductTagService productTagService)
        {
            this._blogService = blogService;
            this._categoryService = categoryService;
            this._manufacturerService = manufacturerService;
            this._newsService = newsService;
            this._productService = productService;
            this._topicService = topicService;
            this._urlRecordService = urlRecordService;
            this._vendorService = vendorService;
            this._productTagService = productTagService;
        }



public virtual IActionResult RedirectProductTagById(int productTagId)
        {
            var productTag = _productTagService.GetProductTagById(productTagId);
            if (productTag == null)
                return RedirectToRoutePermanent("HomePage");

            return RedirectToRoutePermanent("ProductTag", new { SeName = _urlRecordService.GetSeName(productTag) });
        }


What am I missing? Do I need to reference this somewhere else in the application?
5 years ago
Hi.
Try to use the "ProductsByTag" route name. You can see the definition of such generic routes here.
5 years ago
I changed the code to

public virtual IActionResult RedirectProductTagById(int productTagId)
        {
            var productTag = _productTagService.GetProductTagById(productTagId);
            if (productTag == null)
                return RedirectToRoutePermanent("HomePage");

            return RedirectToRoutePermanent("ProductsByTag", new { SeName = _urlRecordService.GetSeName(productTag) });
        }


but it still isn't working. I apologize...I'm not very good with routing...
5 years ago
You can see how we fixed it.
5 years ago
Thanks! The route provider piece was what I was missing.

For anyone coming at this in the future, you also need to add this to BackwardCompatibility2XRouteProvider.cs


//product tags
            routeBuilder.MapLocalizedRoute("", "producttag/{productTagId:min(0)}/{SeName?}",
                new { controller = "BackwardCompatibility2X", action = "RedirectProductTagById" });


Or, see the full fix in Romanov's link above.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.