uCommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.
uCommerce 1.5 introduces nice URLs for catalogs, categories, and products. The basic idea is to provide keyword rich URLs for catalog items to increase page rank in search engines like Google and Bing. Really though, who are we kidding here? It’s just for Google :)
To keep maintenance low uCommerce generates URLs based on information already present in the catalog. To support multilingual sites display names are used when present otherwise standard internal names are used. This gives webshops built with uCommerce the ability to rank on search terms specific to the culture the online store services, e.g. English terms for English stores, Spanish terms for Spanish stores, etc..
URLs are structured in three parts:
For a sample URL like www.myonlinestore.com/apparel/c-24 the three pieces are:
Basically Umbraco and uCommerce only need the first and last pieces while the rest is all for Google.
To start using nice URLs in your own uCommerce solution you’ll need to use one of the following XSLT extensions:
GetNiceUrlForCatalog(string catalogName) GetNiceUrlForCategory(string catalogName, string categoryName) GetNiceUrlForProduct(string catalogName, string categoryName, string sku) GetNiceUrlForProduct(string catalogName, string sku) GetNiceUrlForVariant(string catalogName, string sku, string variantSku).
There are multiple extensions for each type of URL you’ll generate as they have slightly different needs for the final result. The method will generate the following URLs:
<xsl:variable name="catalogUrl" select="CommerceLibrary:GetNiceUrlForCatalog('Apparel')"/>
<xsl:variable name="categoryUrl" select="CommerceLibrary:GetNiceUrlForCategory('Apparel', 'TShirts')" />
<xsl:variable name="categoryUrl" select="CommerceLibrary:GetNiceUrlForProduct('Apparel', 'TShirts', 'Green-TShirt')" />
<xsl:variable name="categoryUrl" select="CommerceLibrary:GetNiceUrlForProduct('Apparel', 'Green-TShirt')" />
To generate those same URLs from .NET you’ll use the IUrlService. Using the ObjectFactory class you can resolve the configured instance for the interface. The default implementation is called UrlSerivce. More on that later.
IUrlService urlService = ObjectFactory.Instance.Resolve<IUrlService>(); ProductCatalog catalog = ProductCatalog.SingleOrDefault(x => x.Name == "Apparel"); string catalogUrl = urlService.GetUrl(catalog); Category category = Category.SingleOrDefault(x => x.Name = "TShirts"); string categoryUrl = urlService.GetUrl(catalog, category); Product product = Product.SingleOrDefault(x => x.Sku == "Green-TShirt" && x.ParentProductId == null); string productIncludingCategoryInfoUrl = urlService.GetUrl(catalog, category, product); string productUrl = urlService.GetUrl(catalog, product);
If you wish to customize the default nice URLs you can go ahead and inherit the class UrlService and override any methods you’re not happy with. Should you need to replace the default nice URLs generated by uCommerce you can implement the IUrlService interface from scratch.
If for instance you need complete control over the keywords added to the URL your custom implementation might grab information not from the display name, but from a dedicated field on the category or product.
In any case you have to register your custom implementation via /umbraco/ucommerce/configuration/components.config. Just look for the existing registration of IUrlService.
UrlRewriting.NET contains the set of rules, which define what URL the customer sees and what that URL should look like to the system.
You will not have to change the existing rules even if you implement your own UrlService as long as you keep the last part of the URL the same, i.e. the /c-xx/c-yy/c-zz part. This is the marker used for the rules to pick up a rewritten URL so you can include anything before that part. If you don’t want the marker as part of your URL you’ll have to modify the default rules.
Each rule is automatically deployed when uCommerce is installed and is found in /config/UrlRewriting.config in your website folder. If you wish to modify the default rules this is the place to do it.
Nice URLs help the search engine optimization process for webshops built with uCommerce and will make pages in your webshop rank higher. Any URL scheme is supported by overriding the default implementation found in UrlService.