Commerce Server 2007: Development Tip #6 – Adding Items to your Basket

Commerce Server 2007: Development Tip #6 – Adding Items to your Basket

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 #6 – Adding Items to your Basket

The basic funtionality of the LineItem class has changed little from Commerce Server 2002 and adding an item to your basket works pretty much as it did in the previous version.

public void AddItemToBasket(decimal Qty, 
                    string UnitOfMeasure, 
                    string ProductID, 
                    string DisplayName, 
                    decimal Price, 
                    string Description, 
                    string Catalog, 
                    string GCSPartNumber, 
                    string CustomerPartNumber)
        // If the Basket Doesn't already have an OrderFormCollection
        if (_Basket.OrderForms[OrderForm.DefaultOrderFormName] == null)
            // Add a new OrderForm to the Basket
            _Basket.OrderForms.Add(new OrderForm(OrderForm.DefaultOrderFormName));
        // Create a new LineItem instance
        LineItem item = new LineItem();
        // Set the required LineItem properties
        item.Quantity = Qty;
        item.ProductId = ProductID;
        item.PlacedPrice = Price;
        item.Description = Description;
        item.ProductCatalog = Catalog;
        item.DisplayName = DisplayName;
        // Set any custom weakly typed properties
        item["gcs_part_number"] = GCSPartNumber;
        item["customer_part_number"] = CustomerPartNumber;
        item["unit_of_measure"] = UnitOfMeasure;
        // Add the LineItem to the OrderForm's LineItemCollection
        // Update and Save the Basket

The first thing to do is create a new LineItem instance, set the required and optional (weakly-typed) properties and then add the LineItem to the OrderForm's LineItemCollection.

As with every action taken in the Basket, you should always update the Basket and run the appropriate pipeline as shown here.

public void UpdateBasket(string pipelinename)
        // Run the pipeline
        // Save the Basket
        // Dispose of the PipelineInfo object

In Commerce Server 2007, it's also important to remember to dispose of the PipeLineInfo object to ensure that resources are released in a timely manner.

Also, since Commerce Server 2007 now supports multiple "named" baskets that are active at the same time, you may need to extend your code to accommodate this new feature.

Updated per reader request to include the GetBasketPipelineInfo call:

private PipelineInfo GetBasketPipelineInfo(string pipelinename)
  // Create a PipelineInfo instance
  PipelineInfo info = new PipelineInfo(pipelinename);

  // Set the language property
  info.Language = @"en-US";

  // Add the current user's profile
  info.Profiles.Add("User", CommerceContext.Current.UserProfile);

  // Set a weakly typed property
  info["catalog_language"] = @"en-US";

  // Return the object
  return info;


Technorati Tags:

BPEL support for WF

announced recently a coming CTP [1] that will provide
BPEL 1.1
support to Windows Workflow Foundation. This will provide a set of custom
WF activities that map to BPEL 1.1 constructs as well as tooling to import BPEL processes
into WF XAML workflows and export the other way around.

I think overall this is very good news and, as Paul says, highlights the power and
flexibility offered by the domain-neutrality of the WF runtime. Paul also mentions
that this will, in the end, be supported in a future release of BizTalk Server, once
the orchestration engine is built on top of WF, and by that time the toolkit support
should have already been expanded to provide BPEL 2.0 compatibility in both WF and
BizTalk. Pretty exciting stuff which I’m sure will provide some good selling points
for both products (even if many people don’t use it eventually).

One important aspect of this that is interesting to consider: the WF approach to writing
workflows means that, if BPEL compatibility is an aspect you care about, you’ll
need to restrict yourself to a subset of the power of WF in order to remain compatible
meaning being able to later export your WF workflows into BPEL). This is something
I completely expected and understand (and even welcome, to a point), but it’s something
some people might not realize right away.

[1] Am I the only one getting lost along the miriads of CTPs coming out of Redmond
lately? Seems pretty imposible to keep up if you actually have a day job!

Using the AJAX Control Toolkit in SharePoint

Using the AJAX Control Toolkit in SharePoint

To get started with the ASP.NET AJAX extensions in SharePoint 2007, check out my previous posts:

Once you fell in love with ASP.NET AJAX, you have to check out the ASP.NET AJAX Control Toolkit! The ASP.NET AJAX Control Toolkit provides a set of sample controls and extenders that makes it a snap to spice up your web site with rich functionality. Think about the Control Toolkit as a bunch of sexy controls which use the ASP.NET AJAX extensions, plus a framework to create a new even sexier control on your own. In this post I’ll describe how you can make use of the Control Toolkit in your SharePoint 2007 sites, for example by using the SmartPart.

Actually SharePoint doesn’t differ from any other ASP.NET web site to use the Control Toolit, there are only three things that you need to do:

  1. Make sure SharePoint has access to AjaxControlToolkit.dll
    You can do this in two ways: either you deploy the assembly to the Global Assembly Cache (GAC) or you put in the \BIN folder of the SharePoint site’s folder.
  2. Add an assembly reference in the web.config (note: for the future versions of the Control Tookit, the version number can change!):
        <add assembly=”AjaxControlToolkit, Version=1.0.10201.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e”/>
  3. Add the tagprefix for the Control Toolkit in the web.config:
        <add namespace=”AjaxControlToolkit” assembly=”AjaxControlToolkit” tagPrefix=”ajaxToolkit”/>

That’s it! Now you can make use of the Control Toolkit coolness in your SharePoint 2007 sites! If you want to test if the Control Toolkit is working on your installation: I’ve upload a very small example to CodePlex.



Technorati tags: , , , , ,

ArchCamp 2007 Field Report (part 2)

ArchCamp 2007 Field Report (part 2)

Like I said previously, each team presented their solutions to the Region President and his Assistant, who later asked questions about each approach. All the approaches were very high level, and the view of Architecture was perhaps that of an Enterprise Architect, very close to the business needs. Hugo Ribeiro is posting some pictures, and the event’s blog will contain both the problem statement and the proposed solutions.

The Design Lab ended with an open space for questions by the audience to each of the groups, and the event was wrapped up with a final Debrief and evaluation. Some interesting suggestions were presented to future events, like doing a continuation of the Design Lab to further detail the technical approaches of each team. Also, analysing how each team self-organized to work on the project is something that is worth sharing. If you have a team of 6 Architects, several of them used to being team leaders and point the direction, it’s certainly interesting to share how did they work together.

A final word of thanks to the event’s sponsors, starting with Microsoft which again supported the event, but also Agilior, Create It, Primavera BSS, and PT.COM/Sapo.

New version of SmartPart, now with "AJAX Connections"

New version of SmartPart, now with "AJAX Connections"

As you may know, last week I released a version (still in beta) of the SmartPart which supports the ASP.NET AJAX extensions. For more information about this version of the SmartPart, see my previous blog post.

This weekend I’ve been working on functionality to support “AJAX connection” in the SmartPart. First of all; connectable web parts are web parts that can exchange data. Think for example about a web part which displays a list of invoices, and another one that displays a list of invoice lines. If you select an invoice in the first one, the second one can display the lines of the selected invoice. So with connectable web parts you can create those typical parent/child and parent/details relationships. You can create connectable web parts in SharePoint 2003 and in ASP.NET 2.0/SharePoint 2007, so it’s not a new functionality.

So why are the connections in the new version of the SmartPart (Return of SmartPart v1.2 BETA) so special? Well if you combine web part connections with a little bit of AJAX-magic you have web parts that can exchange data without postbacks! Think about selecting the invoice and displaying the corresponding invoice lines in another web part, all without postbacks. Actually you could do that trick without this new version, but I’ve added some helper and wrapper classes to make your life as a web part developer a little bit easier!

Let’s start with a really basic example: the DemoProvider and the DemoConsumer user controls. The first one has an UpdatePanel (the ASP.NET AJAX control handling the partial-page rendering), a TextBox and a Button. The second one just has an UpdatePanel and a TextBox. The scenario should be like this: the user enters some text in the first text box, clicks the button and the text is transferred to the second text box, all without postbacks.


public partial class DemoProvider : System.Web.UI.UserControl,
  protected void Page_Load(object sender, EventArgs e)

  public string ProviderMenuLabel
    get { return “Send test data to” }

  public object GetProviderData()
    return new SmartPart.AJAXConnectionData(
      TextBox1.Text, Button1, “Click”);

The code above is the code for the DemoProvider user control, notice that the class implements the IConnectionProviderControl interface of the SmartPart which is also used for normal connections. The special thing happens on the GetProviderData method; a new instance of the AJAXConnectioNData class is created. This object contains first of all the value that should be send to the consumer (TextBox1.Text). The second parameter is the control that will cause the UpdatePanel to refresh, the third parameter is the name of the control’s event which will cause the refresh. (This constructor can only have one control as a trigger control, but the class can hold more than one.) The ProviderMenuLabel property returns the value which will be displayed in the web UI of SharePoint when the connection is made. That’s it! Now let’s take a look at the code for the DemoConsumer user control:

public partial class DemoConsumer : System.Web.UI.UserControl,
  protected void Page_Load(object sender, EventArgs e)

  public string ConsumerMenuLabel
    get { return “Receives test data from” }

  public void SetConsumerData(object data)
    SmartPart.AJAXConnectionData ajaxData = data as SmartPart.AJAXConnectionData;
    if (ajaxData != null)
      if (ajaxData.Data != null)
        TextBox1.Text = ajaxData.Data.ToString();

The class implements the normal IConnectionConsumer control of the SmartPart and once again the special thing happens in the SetConsumerDate method. This method receives the instance of the AJAXConnectionData class which was constructed by the provider. First the code checks if the data received is an AJAXConnectionData instance, if so the RegisterTriggerControls method is called with the UpdatePanel to use as a parameter. This method will add every control of the AJAXConnectionData instance as a trigger control for the UpdatePanel, so the two UpdatePanels of the two user controls can trigger eachother. You could do this manually as well, but I provided this functionality since it will be the same for in like 99% of all the cases. Finally the Data property is used to fill the TextBox’s Text property. Done!

I could show the result with some screenshots, but you have to see them in action to get the idea. That’s why I’ve recorded a small screencast of the two user controls. The second part of the screencast shows some other controls which get data from the AdventureWorks database. I already put them on a site, so you can see the Categories web part connected to the Subcategories web part, which is connected to the Products web part. You can download the source code for these demos from CodePlex.


HiMSS 07 day -1 (MS-HUG)

HiMSS 07 day -1 (MS-HUG)

Just wanted to make a few notes on my experience on the first of a few days of the adventures here at the MS-HUG.

Microsoft Connected Health Framework

Upon arriving, I thought that I definately overdressed! Thanks Roberto for setting the bar so high!

Actually, it was good to see the CHF and an actual implementation.

A bit of interesting news is that about 50% of the participants have not downloaded the CHF, so if you don’t know where it is at, click here. If you want to learn more about it, solshare is a good place to start.

Park Nicollet’s Experience with BizTalk

An interesting story of their choosing of Microsoft products. Looks like they are going live with their 270/271 transactions into production. Good luck!

I actually did a cameo during this presentation!

Building a RHIO on Long Island: A Work in Progress

An insteresting approach on the RHIO ocean. An intersting bit of information was that 50% of that audience was not US citizens.

Microsoft Technology Combined with an EMPI Powers e-Prescribing Network

I liked the approach on the patient locator process where they have a seperate process that locates the patient key and thenthey have a seperate datastorethat has all of thedetail about the patient.

Technologies and Techniques for Effective Visualization of a Longitudinal Health Record

Probably my favorite of all of the presentations today. It was not a sales pitch in any way. Just some whiz-bang technology to allow doctors to visualize data in a more graphical wayusing AJAX.

Using Business Activity Monitoring to Improve Reimbursement Rates and Track Patient Satisfaction Criteria

Rumor is that Elizabeth Redding was involved in an accident. Hope she is okay.

A Service Oriented Architecture (SOA) for Interoperability and HIE

Hey, they actually showed some code that was being used! Looks pretty involved and has some interesting approaches to a HIE.

Grrr No More Grandfathering on Flickr!

Grrr No More Grandfathering on Flickr!

Oh dear… First of all my Pro Account expired last week (yes it’s been 2 years already!) and 90% of my photos have vanished!

“If you have more than 200 photos, only the most recent 200 are displayed.

Your photos are not removed from Flickr, only from the list of your photos.”

I chose to upload more than a hundred private “insurance photos” to the service a few weeks ago so most of my “200 photos” are taken up by photos that aren’t even public facing! That’s right searching my photos’ tagged Auckland now only shows a pitiful 3 photos and a bunch of ads!

Another hidden gotcha… “Note: If your free account is inactive for 90 consecutive days, it will be deleted.”

OUCH… I know other web mail services do this as well but picture this senario (unlikely I know)… You spend 2 years uploading GB’s of photos to Flickr (because you are shy you keep these all private) you are hit by a bus and knocked into a coma… while you are “asleep” your Pro account expires you wake up 4 months later with little memory of the past. Your friend reminds you that you upload your photos to flickr so you go back to flickr hoping to be automatically logged in and “relive” your life through your photos… instead “sorry your account has been deleted… bummer!”.

I actually jumped back into Flickr over the weekend to sign-up for another year… I was feeling a little bereaved but not enough to stop using the service.

When I hit the homepage I got this message…

“Dear Old Skool Account-Holding Flickr Member,
On March 15th we’ll be discontinuing the old email-based Flickr sign in system. From that point on, everyone will have to use a Yahoo! ID to sign in to Flickr.”

Bugger… Now I need to be counted as a Yahoo mail user as well! I guess it had to happen and we do the same with passport (Live ID) but up to now I have avoided it looks like I have to bring all of my 5 Old Skool flickr accounts over as well!

When are we as a community at large solve this “Attention Data” issue (yes I know MSFT is not without blame here as well).

ARCHCAMP 2007 Field Report

ARCHCAMP 2007 Field Report

Great experience! The event started Saturday morning with a keynote done by the main meeting’s organizer, Hugo Batista, setting out the rules and agenda. After this, I did two presentations, on the past and future of GASP – the portuguese Architecture Group. Open presentations, with lots of space for discussion and exchange of ideas, it was extremely fruitful and a lot of valuable feedback was presented. Three things will be defined in the next few months: the group’s Mission, Growth Model, and Objectives. The presentation also included IASA‘s 2.0 chapter model, and the big news: the creation of a chapter in the Center Region of Portugal, based around Coimbra/Leiria/Aveiro/Viseu. There will be news on this soon, and the leadership team was identified and participated in the ArchCamp.

After this, Nuno Costa presented ideas and criteria about a proposed system to measure and value the participation of each member in the community. More exchange of ideas ensued, and alternative or complementary ways of evolution were thought out. Some questions remain open, clearly, but several opinions were expressed that now gives us a more precise idea of where to go in terms of the group’s future.

At the end of the day, 4 teams of 6 were formed and Mr Region President Tiago Pascoal, aided by his assistant Mr Hugo Ribeiro, presented a challenge to the groups, around the notion of a fictional regionalization happening in the country, and the need to provide local infrastructures and essentially support the region’s economical growth. Perhaps the most interesting aspect of this problem was the context, meaning that this is a problem being issued by the region’s President, who is being roleplayed as a purely politic person. In this view, if the President is the one doing the selection, the way the solution is presented must take this in consideration, and technological detail must be limited.

I teamed up with Nuno Costa, Miguel Madeira, Denis H., Pedro Lopes and Ricardo Teixeira (of Coimbra), in the Penguin Team. 🙂

The complete problem statement will be posted soon, and also all the solutions.

The teams worked for the rest of the Saturday and Sunday morning, and will each present their solutions/proposals to the President and his aid. There is a space for questions about each approach, and an open discussion at the end. Regardless of the proposals and their merits, this has been a valuable process, with lots of ideas and different points of view. As to Penguin Team’s work, we decided to completely avoid technical terms (including terms in english and acronyms), and design a 20000 feet high level view, complemented with a series of structural projects surounding ours, to create a web of actions.

More details later.