Catalog Context
The Catalog context is the most fundamental component to help you build a nice browse flow for your visitors. It will contain a reference to where your visitor are right now and help you make a decision on what to show / query next.
The component is located in the following namespace:
using Ucommerce.Api;
You can grab a reference to the current instance of CatalogContext using:
Ucommerce.Api.ICatalogContext catalogContext = ObjectFactory.Instance.Resolve<ICatalogContext>();
The Catalog Context allows you to grab any part of the catalog your visitor is currently browsing. All of the return types are located under
using Ucommerce.Search.Models;
Ucommerce.Api.ICatalogContext
CurrentCatalogGroup
- Return type
Ucommerce.Search.Models.ProductCatalogGroup
CurrentCatalog
- Return type
Ucommerce.Search.Models.ProductCatalog
CurrentProduct
- Return type
Ucommerce.Search.Models.Product
CurrentCategory
- Return type
Ucommerce.Search.Models.Category
CurrentPriceGroup
- Return type
Ucommerce.Search.Models.PriceGroup
CurrentCategories
- Return type
ICollection<Ucommerce.Search.Models.Category>
Catalog Context and URLs and the CMS
The nature of how Ucommerce + a CMS works is that every page request needs to two things:
- The page in the CMS that needs to be shown e.g a content page with pure content from the CMS or a content page with data coming from Ucommerce.
-
The actual catalog context in Ucommerce e.g:
- The Product Catalog Group (store)
- The Product Catalog
- The categories (one or more depending on the depth of the category structure)
- The product
Consider all this needs to be translated by a single URL. To achieve this URL redirects needs to be in place. These are powered by your IIS where the rules are defined in web.config. You may find them looking like this (or very similar)
<rewrite> <rules> <rule name="UcommerceCategoryRewrite"> <match url="(.*?)/c/(.+/)*(.*)"/> <action type="Rewrite" url="catalog.aspx?catalog={R:1}&categories={R:2}&category={R:3}"/> </rule> <rule name="UcommerceProductRewrite"> <match url="(.*?)/p/(.+/)*(.*)"/> <action type="Rewrite" url="catalog/product.aspx?catalog={R:1}&categories={R:2}&product={R:3}"/> </rule> <rule name="UcommerceVariantRewrite"> <match url="(.*?)/v/(.+/)*(.*)/(.*)"/> <action type="Rewrite" url="catalog/product.aspx?catalog={R:1}&categories={R:2}&product={R:3}&variant={R:4}"/> </rule> </rules> </rewrite>
What it means in reality is that the URL you paste into your browser is in fact caught by the redirect rules and send to the route seen in the rules above, which needs to match a route that the CMS will translate into a page. The context parameters are passed as query strings that help Ucommerce resolve the right context.
Take the following URL:
http://mywebsite.com/demo-store/c/tops/formal
Will be translated into:
http://mywebsite.com/catalog.aspx?catalog=demo-store&categories=tops/formal
The query string will be used by Ucommerce and the path in the URL will be used by the CMS.
IUrlService
To get URLs for your catalog items, you may use the following interface.
Ucommerce.Search.Slugs.IUrlService
Methods
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalog
- Return type
string
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalogIEnumerable<Ucommerce.Search.Models.Category>
categories
- Return type
string
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalogUcommerce.Search.Models.Product
product
- Return type
string
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalogUcommerce.Search.Models.Product
productUcommerce.Search.Models.Product
variant
- Return type
string
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalogIEnumerable<Ucommerce.Search.Models.Category>
categoriesUcommerce.Search.Models.Product
product
- Return type
string
GetUrl
-
Arguments
Ucommerce.Search.Models.ProductCatalog
catalogIEnumerable<Ucommerce.Search.Models.Category>
categoriesUcommerce.Search.Models.Product
productUcommerce.Search.Models.Product
variant
- Return type
string