Kartris User Guide

14. Custom Development

Although Kartris has an extensive array of features and is highly configurable, there will always be some requirements that necessitate customization. Kartris is open source and so the source code to enable virtually any customization is available. But Kartris also includes specific design features to aid customization.

14.1. Adding new pages

One of the most common modifications developers might want to make to extend Kartris is to add new pages. For simple text pages, there is the built in CMS system (see @8. Custom Pages - Basic CMS‍). But if you need to add a functional page that contains some programming logic, you will need to add actual .aspx pages to the site.

 

In order to integrate properly into your Kartris site, you'd want the new page to inherit the Kartris skin and features such as the basket and menus. You will want the new page to appear on menus, and also in the breadcrumb trail.

Here is a guide to adding a new page, which we will call 'Test'.

 

First, create a new page in your root called Test.aspx, with a code behind (Test.aspx.vb). The aspx page content will be as follows:

<%@ Page Language="VB" MasterPageFile="~/Skins/Kartris/Template.master" AutoEventWireup="false"
    CodeFile="Test.aspx.vb" Inherits="Test" %>

<asp:Content ID="cntMain" ContentPlaceHolderID="cntMain" runat="Server">
    <user:BreadCrumbTrail ID="UC_BreadCrumbTrail" runat="server" EnableViewState="False" />
    Your new content can go here
</asp:Content>

The code behind is even simpler, and will look like this:

Partial Class Test
    Inherits PageBaseClass
End Class

Note that this page inherits from PageBaseClass rather than the standard System.Web.UI.Page class. This ensures it picks up all the special Kartris page features, and employs Kartris security. So for example, if your site is set to require people to login to be able to view pages, this page will enforce that rule too.

To get your pages to appear in the navigation menu, and the breadcrumb trail, you will need to add references to them in a couple of places. Firstly, the web_menu.sitemap file (see @8.4. Site menus‍).

 

For the breadcrumb trail, you will need to add references for your new page in web_breadcrumb.sitemap (also located in the root of the web).

14.2. The object config system

Very often when creating new features, you need to set values at the product or version level. We found this ourselves when adding new features to Kartris. Rather than adding new fields in the existing product and version tables, we came up with a better solution - the object config system.

14.2.1. Adding settings

Each new setting required is added as a record to the tblKartrisObjectConfig table in the database. The data type can be string (s), boolean (b) or numeric (n). Once a record has been added here, the new setting is immediately available on the object config tab when editing products. Any values set are stored in the tblKartrisObjectConfigValues table.

There is no Kartris GUI for adding these values; it needs to be done manually within SQL Management Studio. However, it's not something that will be done routinely, and even then only by developers, so it's not something that we'd really want to have a back end page to handle doing anyway.

14.2.2. Reading settings

Of course, as well as setting values, you will also want to read them within whatever new code you write. Fortunately, the functions to support this are already in Kartris. You can call an object config value simply as follows:
Dim strSampleValue As String = ObjectConfigBLL.GetValue("K:product.myobjectname", numProductID)
The numProductID value, which is the database ID of the product (P_ID from the tblKartrisProducts table) is available in some for or another in most places that products are being handled.

You should of course replace K:product.myobjectname with the actual name of your object config setting.

14.3. Custom product controls

Kartris has multiple product types, including 'options' products and text-customizations, which can handle most scenarios. However, some kinds of products, especially ones that are custom made, can't be adequately handled by the built in product types.

14.3.1. When to use custom product controls

A typical case where a customized product interface is required would be a site that makes items such as curtains and blinds. Both height and width could be any value (in centimetres) between perhaps 50 and 300, so it becomes impractical to create every possible width or height as an option. Furthermore, although options can have a price modifier associated with them, this doesn't really help with pricing where width and height are both variable.

Instead, a far more manageable solution would be for pricing to be obtained from a lookup table or a formula.

Situations where a highly customized product interface is also required or where a client side configuration system has already been created may lend themselves to custom product controls. For example, a client side tool that lets you design a t-shirt and add text and/or images, then buy the item.

14.3.2. Creating custom product controls

Kartris ships with a couple of sample custom controls in the /UserControls/Custom/ folder. There are comments within the files to help explain the code. Our examples are very simple in nature, but you can make things as complicated as necessary as long as you can dump a price and item description out of the control.

For example, you could have a control that has textboxes for the width and height of curtains, a dropdown menu of different lining types and then some other checkboxes for some further options. Prices could be looked up in an Excel spreadsheet with a table of curtain costs. This not only allows very fine control of pricing, but also makes it easy to change or update pricing by editing prices in the spreadsheet.

Engineering applications such as industrial fans could use either a 'black box' software component from the manufacturer or a web service to look up pricing based on various performance requirements, and return the fan specification as the item description, as well as the price.

14.3.3. Hooking up custom product controls

Once you have written your custom control, it is simple to incorporate it into Kartris. First, upload it to the /UserControls/Custom/ folder.

Next, create a new single version product. Give it an appropriate name, but price is not important as that will come later from the custom control.

Finally, edit the product and go to the object config tab. Enter the name of the control in the K:product.customcontrolname object config setting. For example: 'SampleCustomControl.ascx' (the .vb part will be linked in automatically).

When you view this product on the front end, you should now see your custom control providing most of the interface.

14.3.4. Further information

You can use a custom control from different products. So for example, in the case of a curtains web site, you can have each curtain set up with an image of the type of fabric, and then use the custom control on each curtain to handle pricing. You can also use per-product settings. So if the price per square metre of fabric is different for each product, you can set that at each product, and then just have the common values within the custom product control.

You can have as many custom controls as you need, so you can for example configure curtains and blinds using different custom controls within the same site, and of course mix in standard Kartris product types too.

As you can see from this simple overview, the custom product control support is extremely flexible and can cope with virtually any scenario.
 
powered by tomehost