May282010

Basket & Purchase errors bug in Commerce Server 2009

Published by david at 11:29 AM under Commerce Server | SharePoint 2007

While doing an implementation of Commerce Server 2209 and the extensibility kit for a client of mine, we noticed that during a checkout, no error messages are being returned by the pipelines.

Let me explain:

Let say you write a pipeline component that looks like this:

[ComVisible(true)]
    [GuidAttribute ("D452305E-50C9-4031-BC94-6839BE6066EE")]
    public class MyPipelineComponentClass : IPipelineComponent
    {
        // Status codes for pipeline components
        private const Int32 StatusSuccess = 1; // success
        private const Int32 StatusWarning = 2; // warning
        private const Int32 StatusError = 3; // error

        #region IPipelineComponent Members
        void IPipelineComponent.EnableDesign(int fEnable){}

        int IPipelineComponent.Execute(object pdispOrder, object pdispContext, int lFlags)
        {
            Int32 ReturnValue = StatusWarning;
            // TODO: add code for the pipeline
			
			IDictionary Order = (IDictionary)pdispOrder;			

			string ErrorMessage = "Something is wrong"
			((ISimpleList)Order["_Basket_Errors").Add(ref ErrorMessage);
            return ReturnValue;
        }
        #endregion
    }

 

Very simple and to the point. Always return an error.

Now, since the return status is a warning, in the Order Review Page in the extensibility kit, you’ll always have a null Order. Your basket, however, will not have those error messages in its PurchaseErrors and BasketErrors properties.

Clearly, this is a bug (Which I submitted in Connect and waiting for an official fix)

But, there is a relatively simple solution. You can workaroud this issue by creating a simple operation sequence to copy those messages back to the order form like so:

 

 public override void ExecuteUpdate(Microsoft.Commerce.Contracts.Messages.CommerceUpdateOperation updateOperation,
            Microsoft.Commerce.Broker.OperationCacheDictionary operationCache,
            Microsoft.Commerce.Contracts.Messages.CommerceUpdateOperationResponse response)
    {

        OrderGroup cachedCommerceServerOrderGroup = operationCache.GetCachedCommerceServerOrderGroup();
        OrderForm defaultOrderForm = cachedCommerceServerOrderGroup.GetDefaultOrderForm();
        ISimpleList BasketErrorList = defaultOrderForm["_Basket_Errors"] as ISimpleList;
        ISimpleList PurchaseErrorList = defaultOrderForm["_Purchase_Errors"] as ISimpleList;

        if (((BasketErrorList != null) && (BasketErrorList.Count != 0)))
        {
            if (BasketErrorList.Count > 0)
            {
                List<string> basketerrorstringList = new List<string>();

                foreach (string error in BasketErrorList)
                {
                    basketerrorstringList.Add(error);
                }

                foreach (var entity in response.CommerceEntities)
                {
                    if (entity.ModelName == "Basket")
                    {
                        if (!entity.Properties.ContainsProperty("BasketErrors"))
                        {
                            entity.Properties.Add("BasketErrors", basketerrorstringList.ToArray());
                        }
                        else
                        {
                            entity.Properties["BasketErrors"] = basketerrorstringList.ToArray();
                        }
                    }
                }
            }
        }

        if (((PurchaseErrorList != null) && (PurchaseErrorList.Count != 0)))
        {
            if (PurchaseErrorList.Count > 0)
            {
                List<string> basketerrorstringList = new List<string>();

                foreach (string error in PurchaseErrorList)
                {
                    basketerrorstringList.Add(error);
                }

                foreach (var entity in response.CommerceEntities)
                {
                    if (entity.ModelName == "Basket")
                    {
                        if (!entity.Properties.ContainsProperty("PurchaseErrors"))
                        {
                            entity.Properties.Add("PurchaseErrors", basketerrorstringList.ToArray());
                        }
                        else
                        {
                            entity.Properties["PurchaseErrors"] = basketerrorstringList.ToArray();
                        }
                    }
                }
            }
        }
    }



    public override void ExecuteQuery(CommerceQueryOperation queryOperation, 
            Microsoft.Commerce.Broker.OperationCacheDictionary operationCache,
            CommerceQueryOperationResponse response)
    {



    }

 

Now, add your component just before the basket committer operation in your Channelconfiguration.config file int Basket Update Message section.

Voila, your message are now available.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 2 Responses

Jan272010

You cannot target advertisements or discounts to specified page groups by using the Discount Ad Web Part in Commerce Server 2009

Published by david at 4:32 PM under Commerce Server | SharePoint 2007

While working on a Commerce Server 2009 solution, we were trying to create targeted advertisement only on the home page. We noticed that the Page group did not change anything. As it turns out, Microsoft has a fix for that. Here is the link:

http://support.microsoft.com/kb/968758



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 1 Responses

Nov172009

SharePoint, Execution Context & Security

Published by Nicolas at 10:01 AM under C# | SharePoint 2007

At least once in his career, a SharePoint developer is going to be faced with a security problem.

When a user executes an action in SharePoint, i.e. modifies an item in a list, the request on the server executes using the security context of the user. So, if the user does not have the right privileges to accomplish specific actions, the request could fail with a security exception.

A way to overcome this behaviour is to use the RunWithElevatedPrivileges method from the SPUtility class.

An important thing to keep in mind when using this method is the initial context of the object on which you will execute specific actions.

In the example below, even if you use the RunWithElevatedPrivileges method, the security context of the SPWeb object (web variable) is inherited from the user permissions.
This behaviour is normal because the SPSite site variable is a reference to the properties variable which was created with the user’s security context.

public override void ItemUpdated(SPItemEventProperties properties)
{
	SPSecurity.RunWithElevatedPrivileges(delegate(){
		using (SPSite site = properties.ListItem.Web.Site)
		{
			using (SPWeb web = site.RootWeb)
			{
				web.AllowUnsafeUpdates = true;
                                // Do some actions
			}
		}
	});
}

To run in a context with full control, all objects should be instantiated inside the RunWithElevatedPrivileges delegate method.
By doing this, objects will inherit their permission from the RunWithElevatedPrivileges context which is full control:

public override void ItemUpdated(SPItemEventProperties properties)
{
	SPSecurity.RunWithElevatedPrivileges(delegate(){
		using (SPSite site = new SPSite(properties.ListItem.Web.Site.ID))
		{
			using (SPWeb web = site.RootWeb)
			{
				web.AllowUnsafeUpdates = true;
                                // Do some actions
			}
		}
	});
}


[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , ,

E-mail | Permalink | Trackback | Post RSSRSS comment feed 1 Responses

Oct302009

InfoPath Web based form and Windows SharePoint Services SP1 error

Published by Nicolas at 9:38 AM under SharePoint 2007 | InfoPath

Yesterday, I encountered a strange error when I was developping a custom InfoPath enabling some cascading dropdown menus.

Here is the exception I had:

Unexpected end of file while parsing Name has occurred. Line 1, position 708. System.Xml.XmlException: Unexpected end of file while parsing Name has occurred. Line 1, position 708. [...]

After a lot of searches on the Internet, I'd found a very helpful post on the InfoPathDev forums.

To summarise, if the server on which you're developing is running with Windows SharePoint Services SP1 (Service Pack 1), your InfoPath form must not have a useless secondary Data Connection (declared but not used at all on your form).

By the way, if you're interesting to know how to implement cascading dropdown menus in an InfoPath Web based Form, take a look at the Cascading Dropdowns in Browser Forms article from the InfoPath Team Blog).



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses

Jun262009

Modifying the Commerce Server 2009 Contemporary site’s site definition (Part 1)

Published by david at 10:54 AM under SharePoint 2007 | Commerce Server

While building a new site with Commerce Server 2009 SharePoint services, we wanted to redesign the site and modify a lot of pages. The problem is that for us to do that 3 solutions were possible per Microsoft’s documentation:

  1. Use the extensibility kit to edit the pages and master pages
  2. Change the necessary pages directly in the Layouts folder of that SharePoint hive
  3. Modify the pages in SharePoint designer

None of these solutions were suitable for our need and here are the reasons:

  1. I do not recommend using the extensibility kit because we need to re-sign all the assemblies with a new key and change all references to the public key token. Also, if you modify the extensibility kit, you are making it very difficult to upgrade to future versions of CS 09, unless you only add web parts or pages. Finally, the extensibility kit does not include the contemporary site, which is the one we want to keep as a basis.
  2. Changing the pages in the layouts folder is not a good idea because you basically change it for all of your sites. Of course it’s not an issue because usually there is only one CS site per machine. but still it can be an issue in a dev machine or if ever CS 09 should be used as Saas (Software as a service). Finally, this solution is not re-deployable.
  3. Modifying the pages in SharePoint is also a plausible solution but again it is not deployable and it breaks the site definition.

So, what is the solution? It is to repackage the Contemporary site SharePoint solution and adding your custom features and modified pages. The following modifications were done in MOSS and not in WSS. I’m sure it is possible in WSS though. Also, for the packaging in wsp, I’m using WspBuilder.

So, here we go:

1. Un-pack the MicrosoftCommerceMOSSDefaultSiteV2.WSP file to any folder, let’s say “C:\ContemporarySite”. Your contents should look like this:

image 

2. Now you need to restructure the features and files for WspBuilder. So essentially you would have:

Copy the following folders in 12\Templates\Features:

CommerceServerContemporarySiteCheckOutStepsInstance CommerceServerContemporarySiteImages CommerceServerContemporarySiteProvisioner CommerceServerContemporarySiteResourceDeployment CommerceServerContemporarySiteResources CommerceServerContemporarySiteSPListSampleData CommerceServerContemporarySiteXslts CommerceServerMyAccountSiteMapProvider

Copy the following folders in 12\Templates:

1033
CONTROLTEMPLATES
IMAGES
LAYOUTS
SiteTemplates

Copy the following folder in 12:
Resources
Copy the following files in the GAC folder:

Microsoft.Commerce.Portal.ContemporarySite.dll
Microsoft.Commerce.Portal.ContemporarySiteCommon.dll

 

Now that the basic structure is done, you are able to re-create the Contemporary site’s WSP solution and deploy it using Commerce Server SharePoint Services configurations tool. Before that though you will need to modify the SharePointCommerceServicesConfiguration.exe.config to take the new WSP file:

<sharePointSolutionGroup name="DefaultSiteAndWebPartsMoss" sharePointPlatform="moss" defaultInSilentMode="True">
            <sharePointSolutions>
                <sharePointSolution id="7b93b2ca-e1e4-4783-a038-14094933c002" file="MicrosoftCommerceWebParts.wsp" version="1.0.0.0" wspKey="1"/>
                <sharePointSolution id="Your solution ID Here" file="Your Solution Name Here.wsp" version="1.0.0.0" wspKey="2"/>
            </sharePointSolutions>
            <defaultWebApplicationSettings name="SharePoint - 8088" port="8088" extendedName="SharePoint - 8089" extendedPort="8089" appPoolId="SharePoint - Pool 8088" appPoolUser="domain\someone"/>
            <defaultSiteCollectionSettings create="True" title="Home" name="ContemporarySite" admin="domain\someone" template="MOSSCSContemporarySite"/>
            <defaultCommerceServerSiteSettings create="True" name="ContemporarySite" description="Commerce Server Site for Commerce SharePoint Contemporary Web Site" siteWithSampleData="False" databaseServer="."/>
</sharePointSolutionGroup>

 

Now you can use the configuration tool to deploy your site. Please be advised though that your MOSS environement needs to be clean because you are essentially redeploying the same feature as the contemporary site. Also, do not modify the name of the Contemporary Site’s site definition configuration names such as “MOSSCSContemporarySite” because the receivers look for those configurations.

In the next part of my post, I’ll show you how to modify the master pages and add new features to your site.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: ,

E-mail | Permalink | Trackback | Post RSSRSS comment feed 3 Responses

Jun262009

SharePoint Tool Basket

Published by eric at 7:51 AM under SharePoint 2007

Belgian MVP Releases SharePoint Tool Basket on CodePlex!

Picture of SharePoint Tool Basket

MVP Stéphane Eyskens recently produced a new SharePoint project on Codeplex called “SharePoint Tool Basket”. Within two months of launch, the project has appeared in the Top 10 list of the most popular Codeplex Sharepoint projects; the tool basket is proving very popular with the SharePoint community and has already been downloaded over 5,000 times!

This project aims to re-group a number of different SharePoint tools into one single container. The tool basket offers features such as SharePoint Document Rating, Form Designer, Ajax-enabled lookup field, Content Type Explorer, Feature Explorer and Audience to Group convertor.

If you have an interest in Microsoft SharePoint, the Tool Basket is well worth investigating.

Learn more about the project and download the project bits here.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses

Mar312009

Accessing the Variation Labels List of a Site Collection

Published by Nicolas at 10:01 AM under SharePoint 2007

Let's say you want to access each Variation Label of your Site Collection.
A good way to do it should be:

string resxString = SPUtility.GetLocalizedString("$Resources:cmscore,Settings_Publishing_VariationLabels;",null, SPContext.Current.Web.Language);SPList variationLabelsList = rootWeb.Lists[resxString]; 

Where the resource key of the cmscore.xx-XX.resx represents the local name of the variation labels list in your Site Collection.

Simple isn't it?
NO! Indeed, it isn't.

What we experienced on one of our project is that the value of the resource key "Settings_Publishing_VariationLabels" was wrong in the french cmscore resx file (cmscore.fr-FR.resx).
The value in the file was Étiquettes de variante but the name of the list created when the site collection has been created was "Étiquettes de variantes"

Just update the french cmscore resx file will be solved this problem.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses

Feb262009

Workflow association issue

Published by Louis.Philippe at 3:53 PM under SharePoint 2007

We had an issue with our workflow association in our publication site, the following error was logged 

Skipped associating the approval workflow with list 'Pages' because it appears that no SSP has been created. Workflow requires an SSP.

Resolution, it turned out that our Shared Service Provider was not created. After we've setting up our SSP, all new lists had the proper workflow associations.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , , , ,

E-mail | Permalink | Trackback | Post RSSRSS comment feed 2 Responses