Skip to main content

How to get Root Categories using Commerce Server 2007 & 2009

using System;
using System.Linq;
using Microsoft.Commerce.Common.MessageBuilders;
using Microsoft.Commerce.Contracts;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.CommerceServer.Catalog;
using Microsoft.CommerceServer.Runtime;

namespace ASPNet3346
{
    public partial class GetCatalogCategories : System.Web.UI.Page
    {
        protected void btnCS2007_Click(object sender, EventArgs e)
        {
            ProductCatalog productCatalog = (ProductCatalog)CommerceContext.Current.CatalogSystem.GetCatalog("Adventure Works Catalog", "en-US");
            // Get the root category.
            Category rootCategory = productCatalog.GetRootCategory();
            CatalogItemsDataSet categories = rootCategory.ChildCategories.DataSet;
            foreach (CatalogItemsDataSet.CatalogItem category in categories.CatalogItems)
            {
                DisplayHelper.DisplayValue("DisplayName",category.DisplayName,Response);
            }

        }

        private void GetRootCategory()

        {

            var catalogQuery = new CommerceQuery("Catalog");

            //catalogQuery.SearchCriteria.Model.Properties["language"] = "en-US";
            catalogQuery.SearchCriteria.Model.Id = "Adventure Works Catalog";

            //Get Root Category
            // Add Related Query Operation for root Category ie. _root_
            {
                CommerceQueryRelatedItem queryRootCategory =
                    new CommerceQueryRelatedItem("RootCategory", "Category");
                queryRootCategory.Model.Properties.Add("Id");
                queryRootCategory.Model.Properties.Add("DisplayName");
                catalogQuery.RelatedOperations.Add(queryRootCategory);
            }

            CommerceResponse response = CommerceFoundationServiceAgent.Execute(catalogQuery);

            // Handle Responses
            CommerceQueryOperationResponse queryResponse = response.OperationResponses.Single() as CommerceQueryOperationResponse;
            CommerceEntity productCatalog = queryResponse.CommerceEntities.SingleOrDefault();

            DisplayHelper.DisplayValue("Catalog ID", productCatalog.Id, Response);
            DisplayHelper.DisplayValue("IdentifyingProductProperty", productCatalog.Properties["IdentifyingProductProperty"], Response);

            var rootCategory = (productCatalog.GetPropertyValue("RootCategory") as CommerceRelationship).Target;

            DisplayHelper.DisplayValue("Category ID", rootCategory.Id, Response);
            DisplayHelper.DisplayValue("Category DisplayName", rootCategory.Properties["DisplayName"].ToString(), Response);

        }

        protected void btnCS2009_Click(object sender, EventArgs e)
        {
            // GetRootCategory(); // Optional for your knowledge

            var catalogQuery = new CommerceQuery("Category");

            catalogQuery.SearchCriteria.Model.Properties["DisplayName"] = "_root_";//this indicates its root category, Please refer GetRootCategory() for more details
            catalogQuery.SearchCriteria.Model.Properties["CatalogId"] = "Adventure Works Catalog";

            //Get Child Categories
            // Add Related Query Operation for child products
            {
                CommerceQueryRelatedItem queryChildProducts =
                    new CommerceQueryRelatedItem("ChildCategories", "Category");

                catalogQuery.RelatedOperations.Add(queryChildProducts);
            }
            CommerceResponse response = CommerceFoundationServiceAgent.Execute(catalogQuery);

            // Handle Responses
            CommerceQueryOperationResponse queryResponse = response.OperationResponses.Single() as CommerceQueryOperationResponse;
            CommerceEntity productCatalog = queryResponse.CommerceEntities.SingleOrDefault();
            var childCategories = productCatalog.GetPropertyValue("ChildCategories") as CommerceRelationshipList;
            foreach (var commerceRelationship in childCategories)
            {
                CommerceEntity childcategory = commerceRelationship.Target;
                DisplayHelper.DisplayValue("Root Category ID", childcategory.Id, Response);
            }

        }
    }
}

Attached Source Code : ASPNet3346

How to get product using Commerce Server 2007 & 2009

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Commerce.Common.MessageBuilders;
using Microsoft.Commerce.Contracts;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.CommerceServer.Catalog;
using Microsoft.CommerceServer.Runtime;

namespace ASPNet3346
{
    public partial class GetAProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnCS2007_Click(object sender, EventArgs e)
        {
            GetCatalog(CommerceContext.Current.CatalogSystem, "Adventure Works Catalog");
        }
        private void GetCatalog(CatalogContext context, string catalogName)
        {
            //Get the catalog with the name specified in catalogName.
            // Return the catalog data in English, as specified by "en-US");
            ProductCatalog productCatalog = (ProductCatalog)context.GetCatalog(catalogName, "en-US");
            Response.Write(productCatalog.Name);
            Response.Write(productCatalog.IdentifyingProductProperty);
        }

        protected void btnCS2009_Click(object sender, EventArgs e)
        {
            var productQuery = new CommerceQuery("Product");

            productQuery.SearchCriteria.Model.Properties["CatalogId"] = "Adventure Works Catalog";
            productQuery.SearchCriteria.Model.Id = "AW200-12";

            productQuery.Model.Properties.Add("Id");
            productQuery.Model.Properties.Add("DisplayName");
            productQuery.Model.Properties.Add("Description");
            productQuery.Model.Properties.Add("ListPrice");

            {
                var queryVariants = new CommerceQueryRelatedItem("Variants", "Variant");

                queryVariants.SearchCriteria.SortProperties = new List();
                queryVariants.SearchCriteria.SortProperties.Add(new CommerceSortProperty("Variant", "ProductColor", SortDirection.Ascending));
                queryVariants.SearchCriteria.FirstItemIndex = 0;
                queryVariants.SearchCriteria.ReturnTotalItemCount = true;

                queryVariants.Model.Properties.Add("Id");
                queryVariants.Model.Properties.Add("VariantCode");
                queryVariants.Model.Properties.Add("ProductColor");

                productQuery.RelatedOperations.Add(queryVariants);
            }

            CommerceResponse response = CommerceFoundationServiceAgent.Execute(productQuery);

            // Handle Responses
            CommerceQueryOperationResponse queryResponse = response.OperationResponses.Single() as CommerceQueryOperationResponse;
            CommerceEntity product = queryResponse.CommerceEntities.SingleOrDefault();
            Response.Write(product.Id);
        }
    }
}

Attached Source Code : ASPNet3346

How to get a Catalog using Commerce Server 2007 & 2009

namespace ASPNet3346
{
    public partial class GetACatalog : System.Web.UI.Page
    {

        protected void btnCS2007_Click(object sender, EventArgs e)
        {

            ProductCatalog productCatalog = (ProductCatalog)CommerceContext.Current.CatalogSystem.GetCatalog("Adventure Works Catalog", "en-US");
            DisplayHelper.DisplayValue("Catalog ID", productCatalog.Name, Response);
            DisplayHelper.DisplayValue("IdentifyingProductProperty", productCatalog.IdentifyingProductProperty, Response);

        }

        protected void btnCS2009_Click(object sender, EventArgs e)
        {
            var catalogQuery = new CommerceQuery("Catalog");

            //TODO Theme Microsoft Multi-Channel Commerce Foundation RequestContext object will BindingContainert he user locale information used to get the catalogs in the appropriate language. If the language in the RequestContext is NotFiniteNumberExceptionc urrently supported, the _Defaultl anguage for thec atalog(s) willb e used.
            //catalogQuery.SearchCriteria.Model.Properties["language"] = "en-US";
            catalogQuery.SearchCriteria.Model.Id = "Adventure Works Catalog";

            CommerceResponse response = CommerceFoundationServiceAgent.Execute(catalogQuery);

            // Handle Responses
            CommerceQueryOperationResponse queryResponse = response.OperationResponses.Single() as CommerceQueryOperationResponse;
            CommerceEntity productCatalog = queryResponse.CommerceEntities.SingleOrDefault();

            DisplayHelper.DisplayValue("Catalog ID", productCatalog.Id, Response);
            DisplayHelper.DisplayValue("IdentifyingProductProperty", productCatalog.Properties["IdentifyingProductProperty"], Response);

        }

    }
}

Attached Source Code : ASPNet3346

Microsoft will acquire Skype, the leading Internet communications company, for $8.5

Microsoft Corp. and Skype Global today announced that they have entered into a definitive agreement under which Microsoft will acquire Skype, the leading Internet communications company, for $8.5 billion in cash from the investor group led by Silver Lake. The agreement has been approved by the boards of directors of both Microsoft and Skype.

Microsoft to Acquire Skype

Microsoft Skype Marriage Is All About Communication

Commerce Server 2007 & 2009 Videos / WebCast

image Introducing Commerce Server 2009

image Create Engaging Online Shopping Experiences Using Commerce Server 2009

image Commerce Server 2009: The Site Designer Experience

image Overview of Commerce Server 2009

image http://www.youtube.com/watch?v=intN1_ZB_2c

image Commerce Server “Mojave”: Overview

imageCommerce Server 2009 Web Cast – Using Store Locator Web Part

Microsoft Commerce Server Webcasts on TechNet

http://blogs.msdn.com/b/maxakbar/archive/2007/07/11/microsoft-commerce-server-webcasts-on-technet.aspx

PlayPlay

The search criteria Model must contain exactly one property that maps to a Commerce Server profile property defined as a primary, join, or unique key.

Last week I extended Profile System and added One more unique key for the User Object.
I had done this many times in past and was an easy and simple job but not this time ( because of my silly mistake ).

I had created database field, added Data Member, property in profile definition & finally updated Metadatadefinition file to map to the new field.

image

image

When I queried user object with MCCF by the Key SSN, I got following error.

An exception of type ‘Microsoft.Commerce.Providers.Exceptions.InvalidOperationRequestException’ occurred and was caught.
————————————————————————————————————————
12/21/2010 03:28:37
Type : Microsoft.Commerce.Providers.Exceptions.InvalidOperationRequestException, Microsoft.Commerce.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : The operation could not be performed because the search criteria Model is not valid. The search criteria Model must contain exactly one property that maps to a Commerce Server profile property defined as a primary, join, or unique key.
Source : Microsoft.Commerce.Providers
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ValidateSearchCriteria(Microsoft.Commerce.Contracts.Messages.CommerceModelSearch)
Stack Trace : at Microsoft.Commerce.Providers.Components.ProfileOperationSequenceComponent.ValidateSearchCriteria(CommerceModelSearch searchCriteria)
at Microsoft.Commerce.Providers.Components.ProfileOperationSequenceComponent.GetMatches(CommerceModelSearch searchCriteria, Nullable`1& totalItemCount, Boolean throwIfNotFound)
at Microsoft.Commerce.Providers.Components.ProfileOperationSequenceComponent.GetMatches(CommerceModelSearch searchCriteria, Nullable`1& totalItemCount)
at Microsoft.Commerce.Providers.Components.ProfileLoaderBase.ExecuteQuery(CommerceQueryOperation queryOperation, OperationCacheDictionary operationCache, CommerceQueryOperationResponse response)
at Microsoft.Commerce.Providers.Components.OperationSequenceComponent.Execute(CommerceOperation operation, OperationCacheDictionary operationCache, CommerceOperationResponse response)
at Microsoft.Commerce.Providers.Components.ProfileOperationSequenceComponent.Execute(CommerceOperation operation, OperationCacheDictionary operationCache, CommerceOperationResponse response)
at Microsoft.Commerce.Broker.OperationSequence.ExecuteComponentTree(List`1 executionTreeList, CommerceOperation operation, OperationCacheDictionary operationCache, CommerceOperationResponse response)
at Microsoft.Commerce.Broker.OperationSequence.Execute(CommerceOperation operation)
at Microsoft.Commerce.Broker.MessageHandler.ProcessMessage(String messageHandlerName, CommerceOperation operation)
at Microsoft.Commerce.Broker.OperationService.InternalProcessRequest(CommerceRequest request)
at Microsoft.Commerce.Broker.OperationService.ProcessRequest(CommerceRequest request)
Additional Info:

MachineName : VPC-MYMachine-BASE
TimeStamp : 12/21/2010 9:28:37 AM
FullName : Microsoft.Commerce.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : /LM/W3SVC/483061927/ROOT-1-129373971773508707
ThreadIdentity :
WindowsIdentity : VPC-MYMachine-BASE\Administrator

I recheck that all the bindings are correct and the property is defined as Unique Key. Every thing seems to be OK but still I was facing error. 🙁

On a closer look I found that I had made a mistake with the group name in the MetadataDefinition file.
The name of the CS Property is case sensitive and my MetadataDefinition file was not in Sync with the Case in Commerce Server Manager.

image

image

Change To

image

I faced the same error On my initial trial of extending profile system when CS 2009 CTP was release ( around 2 year back ) and I had made the same mistake of case. Thus I decided to document the issue and the solution.

The Execute method of job definition “SPSolutionDeploymentJobDefinition” threw an exception, Value cannot be null.

I have developed an Timer Job Definition,feature & feature receiver to create the timer job.

On WSP deployment on my local machine it install with no issue 🙂

Now when deploying on the WebFarm environment with a Front end server , I faced following error.

The Execute method of job definition “SPSolutionDeploymentJobDefinition” (id “030bb074-94a8-4f5d-bf34-b4ca735c1693”) threw an exception. Failed to create feature receiver object from assembly “Company.Project.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1f12345e9c67bc89”, type “Company.Project.Business.EventReceivers.MyTimerJobFeatureReceiver” for feature C0857DB8-1636-11E0-AC62-40DFDED72085: System.ArgumentNullException: Value cannot be null.
Parameter name: type
at System.Activator.CreateInstance(Type type, Boolean nonPublic)

at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Initially I thought It is something wrong with the Event Receiver Class and the application could not find the class. Changed the scope of Class, changed the name of the class, restarted IIS, But I no result.

After two hours of troubleshooting, I restarted

IPhone integration with Microsoft Commerce Server 2009

A wonderful demonstration of the IPhone integration with CS 2009 (Commerce Server Multichannel).

Source : decaresystems

This iPhone application integrates with Microsoft Commerce Server 2009, also known as CS09. Its a unique extension to the CS09 platform that provides retailers with a seamless route to mobile retailing.

Daily Deal iPhone applications seamless integration with CS09 allows retailers to centrally manage their multichannel strategy. For more information on how your organization can take a short and simple route to mobile retailing, go to decaresystems.com