Friday, June 6, 2014

Creating a SharePoint 2013 Product Catalog

In this blog I will be showing you how to set up a site that is based on the data from a SharePoint 2013 Product Catalog from end to end.  This will detail the cross-site publishing feature, and how to use SharePoint search features to display product data to your site.  At the end we will dive into customizing the product details page that will display the information of each product.

Keep in mind that a product catalog is not only for products and can be used in many different ways. For example, I used a product catalog to show service areas our company services and drill down to the towns/cities that go with those certain areas. Instead of the typical product categories for an electronics store (Cameras, Computers, TV and Video) then drill down into TV and Video to see TV’s, Blu-ray players, Movies, etc.

Note:  most of the features described are not available in SharePoint 2013 Online.

First we will start with creating the site collections needed for the product catalog.  This part mainly deals with Central Admin and is typically a Network Admin role. Basically it all starts with a product catalog site collection to author and store content, and a publishing portal site collection to display the content. A search index will work in between these two site collections to push the data from the catalog to the publishing portal where customers will be able to view the content.

Create your Site Collections


  1.  In Central Admin go to Create Site Collections.
  2.  Enter the details for the site collection:
    1.  Title for the website.
    2. The URL for the website.
    3. Select 2013 for the experience version.
    4. From the Publishing tab, select the Product Catalog template.
  3. In the field Primary Site Collection Site Administrator, enter the site admin’s user name.
  4. Now, to create a Publishing Portal Site Collection. Just repeat the steps above, but this time choose Publishing Portal from the Publishing tab.

Set up your Products list

The first thing you will need to do is create your Site Columns.  This will create Managed Properties to be used in Search Web Parts when displaying products in your product pages. We will then create the Products list with the Site Columns we created.

When we created the Product Catalog it also created a Products List for us automatically. In that list are two default site columns that come with the Product Catalog (Item Number and Group Number), and one Managed Metadata column called (Item Category).  You do not have to use the Products list or any of those columns.  The one thing I will say is that you ABSOLUTELY need a Managed Metadata column that is tied to a Term Set in the Term Store.  The image below describes how the Item Category column ties with the different categories in the Term Store.
Don't worry if this is confusing, we will go through it step by step. To create your Site Columns follow the instructions below:
  1. While in the Product Catalog Site Collection, click on the Gear icon in the top right of the page.
  2. Click on Site Settings.
  3. Under the Web Designer Galleries section, click on Site columns.
  4. Click Create.
  5. Fill in the Column Name.
  6. Choose the Column Type.
  7. Then add them to the Product Catalog Columns group.  You can use any group you want, I am just using this group since SharePoint created it for the Product Catalog and because that is where all the other columns for this project are.
  8. Repeat these steps until you have created all the columns that you will need to search by or display in your search web parts.
Next we are going to manage item hierarchy in the term store.  For that we will add terms to the Product Hierarchy term set. This term set represents how items in the product catalog are categorized (for example: Product Hierarchy => Electronics => Cameras => Camcorders).



The Item Category site column is mapped to this term set. While still in the Product Catalog site collection follow the instructions below:
  1. Click on the Settings icon at the top right of the page.
  2. Choose Site Settings.
  3. Under Site Administration click on Term Store Management.
  4. Here you can choose to either use the Product Hierarchy term set or create your own.  If you create your own, just be sure to use that term set as the term set for the managed metadata column. Whether it be the Item Category column or one your created yourself.

Finally, we are on to setting up the Products list.  Again, this list was already created for you but if you want to create your own list, feel free to do so.  I will not go into how to create a list as that is very basic SharePoint functionality.  Instead I will continue as if we are using the already created Product list.

First things first, we need to bring over the site columns we created to show as columns in the list if they are not already.  To do that you will again want to be in your Product Catalog site collection and follow the instructions below:
  1. Click on the Settings icon at the top right of the page.
  2. Choose Site Contents.
  3. Click on the Products list (or whatever list you are using).
  4. Click on the List tab to open the ribbon.
  5. Click on List Settings.
  6. Under General Settings choose Advanced Settings.
  7. Make sure Allow management of content types is set to Yes and click OK at the bottom of the page.
That will bring you back to the List Settings page, but now you will have a new section called Content Types. Now we will add the content type.  If you already have a Product with Image content type listed then you can skip these steps.  While still under the List Settings, Under Content Types:
  1. Click on Add from existing content types.
  2. Under the Select site content types from: drop down choose Product Catalog Content Types, which is the group we added our site columns to earlier.
  3. In the Available Site Content Types: section select Product with Image and click the Add > button.
  4. Click OK.
Now you should see all the site columns you created under the columns section. Your list should now have all the columns needed.  Now you are ready to populate your list with data. This part is simply creating items in your list and filling our each column. Since this is basic SharePoint functionality, I will not go into the details of creating list items.

Enable your list as a catalog

Next we are going to enable the Product list as a catalog. While still in your list settings, follow the instructions below.
  1. On the Settings page, click Catalog Settings.

    This settings page will be divided into several parts as there are several things that we will be changing.
  2. For Catalog Sharing select Enable this Library as a catalog.


    By selecting this we are confirming that content from this list should be added to the search index.

  3. For Anonymous Access, this can go one of two ways.

    Anonymous access in its very basic essence will allow you to make the products in this list to be visible to people who are not logged into the site.  So what that boils down to in my eyes is, if you are developing this as an external facing site then its a good idea to enable this setting.  What that means is that if I visit the site, and I have never been there before, I would most likely want to view the products before creating an account to the site.

    Now, if your product catalog is only being used in-house, and you are storing sensitive information / products, then I would not enable this option.

  4. The next section is Catalog Item URL Fields. Here you will select the list columns that will be used to create a unique URL to a product.  So if we select the Group Number and Item Number default columns that automatically come with the product catalog. Where Group Number and Item Number will differ between products, it will look something like this:

    http://domain.com/cameras/camcorders/group number/item number
  5. Lastly, for Navigation Hierarchy you will select the Managed Metadata column either you created or the one that was created for you by the product catalog, in this case it was Item Category.
  6. Save the settings on this page. Now its time to crawl the catalog.

Enable crawling of your catalog content

Crawling is where SharePoint scans over the data in your Products list to make the content searchable. In SharePoint 2013 there are two types of crawls that can be run:

Full Crawl - This is the crawl that takes the most time and does a complete scan of everything. Full is the crawl that is needed to be run for the first time. This will read through all of your products one by one, even if they have been previously crawled. Typically the only other time that a full crawl is needed is when you make changes to the structure of the Products list, like adding or removing a column in the list.  This also includes new products that have been added to the list.

Incremental Crawl - This one takes the least amount of time to complete. This crawl will need to be run when a new product is added to the Products list.  This crawl will not pick up on new columns like the full crawl will.

Since this is our first time, we will want to do a full crawl.  There are two ways to do this.  The first one is for people with Central Administration access, usually reserved for Admins. The second is a way to do it through the Products list, which can be initiated by developers who typically do not have access to the Central Administration Tool.

How to start a full crawl in Central Administration

Before you can start a full crawl in Central Admin, you have to specify which content source should be crawled.  I recommend that your product catalog be on its own content source, that way the catalog can be crawled by itself.

For this scenario, we will crawl the Local SharePoint sites content source. In Central Administration do the following:
  1. Click on Manage service applications.
  2. Click on Search Service Application.
  3. Click on Content Sources in the left side menu.
  4. Hover over the Local SharePoint sites content source (or a separate content source created only for the Product Catalog), and select Start Full Crawl from the menu.

The status of the crawl will be shown in the Status column. You can Refresh this page until you see that the Status column is Idle. That will let you know when the crawl has finished. An Incremental Crawl can also be started by choosing that option instead.

How to start a full crawl by re-indexing the catalog

Lets say you are a developer on a production environment of SharePoint and do not have access to Central Admin, there is another way to do a full crawl. You can simply go into the settings of the Products list and set it to re-index. That will tell the crawler that the next scheduled crawl will be a full crawl, no matter what crawl was set to run.
  1. In your Products list in the catalog, click the List tab.
  2. Click on List Settings.
  3. Click on Advanced Settings.
  4. Click on the Reindex List button.

How to enable continuous crawls in Central Administration

A full crawl can only be started manually. In order to keep from having to do a full crawl every time a new product is added or changed you can do a continuous crawl.

Continuous crawls start automatically at set intervals, the default is 15 minutes. Any changes that have been made to the catalog since the previous crawl are picked up and added to the search index.

To enable continuous crawls, In Central Admin do the following:
  1. Click on Manage service applications.
  2. Click on Search Service Application.
  3. Click on Content Sources in the left side menu.
  4. Click on the Content Source you want to enable continuous crawl on. (In our case its Local SharePoint sites).
  5. Select the option Enable Continuous Crawls.

Connect your publishing site to a catalog

Now its time to do some work on the publishing portal site that we created way back in the beginning of this blog. First lets navigate to your publishing portal and follow the steps below to connect the catalog:
  1. On your publishing portal site, go to Site Settings.
  2. Click on Manage catalog connections.
  3. Click Connect to a catalog.

  4. You should see your Products list displayed as an available catalog.  Click on Connect to connect your publishing portal to the Products list.
This next part are the settings for setting up the product list to connect to the publishing portal. These settings are very important because if you get this wrong there is a good chance you will have to start over close to the beginning of this whole process. I will go through each part of this separately.
  1. The first section is the Connection Integration, keep the setting selected on Integrate the catalog into my site.



    The reason for this is because we want to use the terms in the Product Hierarchy term set as the navigation for our site. In almost every instance you will want this option.
  2. Next is the Navigation Hierarchy, here you will be selecting the managed metadata column, this will either be the one you created in your site columns or the one that comes with the product catalog titled Item Category. Under that you will select the root term of the Product Hierarchy term set. From our example earlier we would select Electronics as the root term.

    Do not select Include root term in site navigation. This is because in most cases you will not want the root term to be shown in the navigation in your catalog.
  3. The next section is the Navigation Position. This defines where this catalog is integrated into the site navigation. Basically this is where in the Site Navigation term set, the Product Hierarchy term set should be integrated.  Here you will want to set it to Add to navigation root.

  4. The next section is Navigation Pinning. This is if you want the site navigation to reflect changes to the original term set. This is something that you will want to do, so, check the box for Pin terms to site navigation.
  5. Next is Catalog Item URL Behavior. Here you will want to keep it set to Make URLs relative to this site. That means that when visitors browse for a specific product, they will be taken directly to a page in the publishing site collection.
  6. The next section is Catalog Item URL Format. For this leave it on the setting for Use the default URL format provided by the catalog. Since we have already defined this when selecting the catalog source it will use that.
  7. The final part is selecting the Category and Item Pages. The Item pages are the pages that display our products from the Products list. The Category pages will be used for displaying groups of products, for example if you click on Audio in the navigation it will show all products that are included in the Audio category (i.e. speakers, radios, etc...).

    For right now we are going to select Create a new page for both pages.  Later we will customize the Item Page, but for now we will keep it simple.

    Next we will select the master page, I prefer Seattle over Oslo, but that is a personal preference. I encourage you to look at the differences between the two if you are not familiar with them to choose your preference.
  8. Click OK at the bottom to save all of these settings.
Now you should see that your navigation now includes terms from the Product Hierarchy term set. If you pick one of the top categories of that navigation you should see products for that category displayed. Also if you click on one of the products you should see a page with a Catalog-Item Reuse web part that is displaying specific information about the product. This Item Page is pretty plain, but we will spice it up later.

How to create a page-layout for the Item Page

This is the part where we get into customizing the Item Page. At the time of writing this blog post, I was unable to really find a great resource on how to accomplish this.  So this is my stab at treading new ground.

In order to customize the Item Page we first have to map a network drive to the SharePoint Master Page Gallery. 

To find and map the location of the Master Page Gallery
  1. On your publishing portal, go to Settings.
  2. Click on Design Manager (If you do not see Design Manager, then choose Site Settings and under Look and Feel click on Design Manager).
  3. In the numbered list, select Upload Design Files.
  4. At the top of the page you should see a link that should end in /_catalogs/masterpage/.
  5. Copy that link to your clipboard.
  6. Now you will map a drive to that location. This differs depending on what Operating System you are using.
Once the Master Page Gallery has been mapped, you can then view all the files in the gallery. The one we are concerned with is the one that was created for us called CatalogItem-Electronics.html. The second part of the file name (Electronics) comes from the root term we specified when we connected the Publishing Site to the catalog.

Editing the Item Page

Now the real fun begins, this is where we get to edit the code and snippets that make up the Item Page. I used Microsoft Expression 4 as an HTML editor to edit the code. It is a free program.

When you edit the html file and save it, it automatically updates the aspx file of the same name. With the Master Page Gallery open in Windows Explorer:
  1. Right click on the CatalogItem-Electronics.html and click on Edit with Microsoft Expression Web 4, or whatever editor you want to use.
  2. Find the part of commented code that starts with:<!--MS:<asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server">-->

    Inside this tag is where your content goes. This is where you can add html or javascript / jquery.
Here you will also find Snippets.  Snippets will be inside each of the <div> tags and they will also be commented out (this code will be converted to aspx when you save, so leave it commented out). These Snippets are what brings the data from the catalog to be displayed onscreen. Lets examine an example of a snippet, this displays the Item Category managed metadata column:


<div>

        <!--CS: [owstaxIdProductCatalogItemCategory] Start Catalog-Item Reuse Snippet-->

        <!--SPM:<cc1:CatalogItemReuseWebPart runat="server"

              UseServerSideRenderFormat="True" ResultType="" NumberOfItems="1"
              UseSharedDataProvider="True" OverwriteResultPath="False" ResultsPerPage="1"
              SelectedPropertiesJson="[&#34;owstaxIdProductCatalogItemCategory&#34;]"
              Title="$Resources:Microsoft.Office.Server.Search,CBSItem_Title;"
              Description="$Resources:Microsoft.Office.Server.Search,CBSItem_Description;"
              MissingAssembly="Cannot import this Web Part."
              ID="g_ffd855f6_46b2_456d_98cf_183d2b3a79ab" __WebPartId="{ffd855f6-46b2
              456d-98cf-183d2b3a79ab}">-->
        <!--SPM:<RenderFormat>-->
        <!--DC:Renders value from search without any additional formatting.-->
        <!--SPM:</RenderFormat>-->
        <!--SPM:</cc1:CatalogItemReuseWebPart>-->
        <!--CE:End Catalog-Item Reuse Snippet-->
</div>

So, after the <div> tag, the first line shows:

<!--CS: [owstaxIdProductCatalogItemCategory] Start Catalog-Item Reuse Snippet-->

Inside the square brackets is basically the title, it really has no bearing on what shows on the screen. Its basically so you can easily identify the snippet.

On the second line (which is actually the 6th here with word wrapping) you will see the following info:

SelectedPropertiesJson="[&#34;owstaxIdProductCatalogItemCategory&#34;]"

This is actually the data part, this is what shows up on the screen. The owstaxId portion tells us that it is a Managed Property, specifically a Managed Metadata column.  You may also see ProductCatalogItemNumberOWSTEXT, this is also a Managed Property except its not a Managed Metadata column. At the tail end of it we see "TEXT", this tells us its a single line of text column.

The last and final important part of the snippet is the ID and WebPartId. These are unique GUID's for each snippet. You will receive an error if two snippets have the same ID's.

Hopefully with this info you can now edit the Item Page and its Snippets. What I did was use each of the snippets that were currently on the Item Page and just changed the Title and the SelectedPropertiesJson to display the columns info that I wanted.


No comments:

Post a Comment