CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeff Lynch [MVP]

Everything E-Commerce!

January 2008 - Posts

  • Commerce Server 2007: Development Tip #4 - Returning Site Terms

    I'm going to repost this series of "development tips" related to Commerce Server 2007 to help other folks get started with their development work. All of these "tips" come directly from what I've learned (the hard way) over the past eight months and are intended to save you time and effort. All code samples are now based upon the RTM version and have been tested in our production environment.

    Tip #4 - Returning Site Terms

    One of the really great things about ASP.NET 2.0 is just how easy it is to bind data to server controls like the DropDownList. Commerce Server 2006 includes many new "bindable" collections and custom DataSets which take advantage of this feature of ASP.NET 2.0.

    <asp:DropDownList
      ID
    ="UserRoleDropDownList"
      DataSourceID
    ="UserRolesDataSource"
      DataTextField
    ="Name"
      DataValueField
    ="Value"
      runat
    ="server"
      TabIndex
    ="8">
    </
    asp:DropDownList>

    <asp:ObjectDataSource
      ID
    ="UserRolesDataSource"
      runat
    ="server"
      OldValuesParameterFormatString
    ="original_{0}"
      SelectMethod
    ="GetUserRoles"
      TypeName
    ="UserManager">
    </
    asp:ObjectDataSource>

    In the .aspx code shown above I've created a simple DropDownList bound to an ObjectDataSource which calls the GetUserRoles() select method to return a SiteTermElementCollection (new in CS2007) which can be directly bound to any list control.

    public SiteTermElementCollection GetUserRoles()
        {
            // Get the SiteTermElementCollection for data binding on the site
            return CommerceContext.Current.ProfileSystem.GetSiteTerm("user_role").Elements;       
        }

  • Commerce Server 2007: Development Tip #1 - Returning a User's Catalogs

    I've decided to repost several of my older Commerce Server 2007 posts after spending some time reviewing questions on the Commerce Server forums. Please note: I've edited the code in this post to better explain exactly how to return a user's catalogs in the site.

    Question: "How Do I Return the User's Catalogs in the Commerce Server 2007 Site Code?"

    Tip #1 - Return a User's Catalogs

    Commerce Server 2007 brings many changes and improvements, especially in the "Catalog" subsystem. First and foremost, the "Catalog" subsystem now returns strongly-typed objects in many cases which greatly simplifies your site code.

    The following code returns a strongly-typed "CatalogsDataSet" using the new CatalogSetsContext.GetCatalogs(CatalogSetId) method.

    This example could obviously be extended to fall back to one of the two default CatalogSets (DefaultUserCatalogSet or AnonymousUserCatalogSet) as well and the new strongly-typed DataSet can be directly bound to any number of ASP.NET 2.0 server controls or to (my personal favorite) the ObjectDataSource as it's "Select" method.

  • Off Topic: Quiet Time

    I'd like to apologize to everyone that regularly reads my blog and has been awaiting something (anything) new. I've been having some health issues over the past nine months that culminated in several hosptial stays including emergency surgery on Christmas eve. The bad news is that not all of my conditions have been fully diagnosed so the doctors are treating the symptoms rather than working on a cure. The good news is that my emergency surgery went just fine and I've returned to work this week. I plan to continue blogging as time and energy permits but my posts may be a little more sporatic than usual.

    I'd really like to thank everyone that reads my blog and send in comments. Your continued readership and support really means a lot to me!

    Jeff Lynch

More Posts

This Blog

Syndication

News