Multiple catalogs with same url

This is an excerpt from my second book . The first chapter is available to read for free.

A business is having an Episerver Commerce instance with multiple sites and multiple catalogs set up. They want to make sure each site will use one catalog, and all of them will share the same url for catalog structure. So it’ll be “https://site-a.com/products/category/”, and “https://site-b.com/products/category/”. Site A and site B are using different catalogs.

Is this doable? Yes! It’s just a matter of magic with the routing. This time, we would need to do an implementation of HierarchicalCatalogPartialRouter ourselves. First, let’s create a template for it:

    
public class MultipleSiteCatalogPartialRouter : HierarchicalCatalogPartialRouter
    {
        private readonly IContentLoader _contentLoader;

        public MultipleSiteCatalogPartialRouter(Func routeStartingPoint, CatalogContentBase commerceRoot, bool enableOutgoingSeoUri, IContentLoader contentLoader) 
            : base(routeStartingPoint, commerceRoot, enableOutgoingSeoUri)
        {
            _contentLoader = contentLoader;
        }
    }

Continue reading “Multiple catalogs with same url”

Adding backslash ending to your URLs by UrlRewrite

It’s generally a best practice to add a backslash to your URLs, for performance reasons (let’s get back to that later in another post). There are several ways to do it, but the best/simplest way, IMO, is using UrlRewrite module. In most of the case, processing the Urls before it reaching the server code will be most effective, and here by using UrlRewrite we trust IIS to do the right thing. Our application does not even need to know about it. It’s also a matter of reusable. You can simply copy a working, well tested rule to another sites without having to worry much about compatibility.

Before getting started, it’s worth noting that UrlRewrite is an IIS module which is not installed by default, if you want to use it, then you would have to install it explicitly. Download and install it from https://www.iis.net/downloads/microsoft/url-rewrite .

And then we can simple add rules to <system.webServer><rewrite><rules> section in web.config. For the purpose of this post, this rule should be enough:

<rule name="Add trailing slash" stopProcessing="true">
  <match url="(.*[^/])$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>

If you are new to UrlRewrite, may be it’s useful to explain a bit on the rule. Here we want to add a rule which matches every url, except the urls which already end with backslash (/) already.

Continue reading “Adding backslash ending to your URLs by UrlRewrite”

Is PlayStation 4 Pro a worthy upgrade?

PlayStation 4 Pro was a first “mid-gen” upgrade in a very long time. It is an incremental update to the original PS4, keeping the promise of backward compatibility, at the cost of limited power jump. Is it a worthy upgrade?

I got my original PS4 3 years go and that was a massive jump from my previous Xbox 360 (of course that is expected, it’s a different generation). Builtin hard drive, builtin WiFi N, builtin gigabit LAN, builtin Blu-ray drive, the list goes on and on. Needless to say, I have been very happy with my PS4.

When Pro came out, I was a little disappointed. No UHD Blu-ray. Unable to handle native 4K on most games. Old games were not getting a patch. HDR comes to original PS4 as well. Etc. I was not excited to buy one, unless my PS4 fails.

Well, my PS4 did not fail, but my colleague sold his fairly new PS4 Pro at 1/2 new price, and I decided to take the chance. At that price it’s great value, and even if I don’t like it, I can still sell it and even make a profit! Of course there was no “Wow” moments as I had with my old PS4.

Continue reading “Is PlayStation 4 Pro a worthy upgrade?”

Fixing HTTP Error 500.19 – Internal Server Error

When you are trying to setup an IIS website on your local machine/new server, it’s very likely that you are going to get this error

HTTP Error 500.19 – Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module   IIS Web Core
Notification   Unknown
Handler   Not yet determined
Error Code   0x8007000d
Config Error
Config File   \\?\C:\EL\EL\CMS\web.config
Requested URL   http://el:80/
Physical Path
Logon Method   Not yet determined
Logon User   Not yet determined

Config Source:

   -1: 
    0: 

More Information:

This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.View more information »

IIS could have had a better message of what is wrong, but we will have to live with this right now. Here’s the check lists you can go through:

Missing IIS features

Your IIS installation might be missing some critical features that are required to run the website (in this case, to parse the web.config). Make sure your IIS instance has all these features installed:

Missing IIS UrlRewrite module

The website might have URL Rewrite rules and your IIS does not have that installed. Simply go here https://www.iis.net/downloads/microsoft/url-rewrite, download and install it.

Package equivalent promotion type in Episerver Commerce

Recently we got this question on how to create package-equivalent promotion type in Episerver Commerce, from https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2018/2/is-there-a-built-in-group-discount/

I already recommended to use package for such purpose, because of several reasons:

  • Package is a builtin feature, and is fully supported by the framework, both on UI level and API level.
  • It has been well tested and is very reliable to use.

However in a real world implementation, it might not be easy to just add package implementation. One reason would be if you rely on an external PIM to handle your catalog. Configuring it to support package can not be trivial.

So why not try to implement a package equivalent promotion in the promotion engine, to see if it works.

Continue reading “Package equivalent promotion type in Episerver Commerce”

Useful T-SQL snippets for development and troubleshooting

This post is more of a note-to-self. These are the useful T-SQL statements which can be incredibly useful in development and troubleshooting

SET STATISTICS IO ON

Turn on the IO statistics for statements run after that until set to OFF explicitly. We then switch to Messages tab to see how many IO operations were done on each table.

SET STATISTICS TIME ON

Find out about the statements were executed: which statements, its texts, how many reads (logical), how many time was spent on CPU and how many time was spent total

Continue reading “Useful T-SQL snippets for development and troubleshooting”

Speed up your Catalog incremental indexing

As your products are being constantly updated, you would naturally want them to be properly (and timely) indexed – as that’s crucial to have the search results that would influence your customers into buying stuffs. For example, if you just drop the prices of your products , you would want those products to appear in new price segment as soon as possible.

This should be very easy with Find.Commerce – so if you are using Find (which you should) – stop reading, nothing for you here. Things, however, can be more complicated if you are using the more “traditional” SearchProvider.

Continue reading “Speed up your Catalog incremental indexing”

Fixing Cannot find module ‘sync-exec’ error with yarn install

Error message:
clientResources\node_modules\uglifyjs-webpack-plugin: Command failed. Cannot find module ‘sync-exec’
Reason:
uglifyjs-webpack-plugin 0.4.6 defines this command 
“postinstall”: “node lib/post_install.js”
which looks like this
var execSync = require('child_process').execSync;
var fs = require('fs');

// Node 0.10 check
if (!execSync) {
execSync = require('sync-exec');
}

So if your node instance is older than 0.10, it will fallback to require sync-exec . Unlike execSync which is a builtin module, sync-exec is, or was an old module that you have to install explicitly. If your node instance does not have that installed, boom!

Continue reading “Fixing Cannot find module ‘sync-exec’ error with yarn install”

Why you should upgrade to the latest version

I made no secret that I’m a die-hard advocate for upgrading to latest EPiServer CMS/Commerce version. There are several reasons for that, mostly from new shiny features that your businesses dearly need, new big performance improvements that your customers firmly demand.

But there is another, not so obvious reason: support.

Let me tell you a story.

This morning we received a support case from support team. A customer recently upgraded from Commerce 7.5 (Eww) to 11.7 (Yay!), things went well except they had a small problem with data displaying in Catalog UI. Some of the properties were not properly displayed, but they are still showing correct in Commerce Manager.

Continue reading “Why you should upgrade to the latest version”

World forums support vote up/down now, and what does that mean for you

I really wanted to post this in the official blog, however we don’t have a “World” blog, and this does not really fit into “Commerce blog” which we (Commerce development team) usually use for official announcements, so I have to use my personal blog instead.

If you haven’t noticed, then you can now vote up, or down a post in World forum. Thanks to the hard work of my colleagues in World development team, that feature went on live today! (Of which I’m very excited)

If you have been using StackOverflow (as as developer, you likely have), then you know the meaning of voting up and down. The idea is the same here, there are differences in the detail implementations, such as the amount of points given (or taken) from a vote up (down), but basically:

Continue reading “World forums support vote up/down now, and what does that mean for you”