Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Add product to cart



I've created Model, Controller and View for my specific Products.

Each product has some properties like descriptionpartecipants, etc.

In a StartPage View I list all my products.

Now I need to add a simple "Add to chart" link for each product but, as I can see here

void AddToCart(Entry entry)
    decimal quantity = 5;                       
    CartHelper cartHelper = new CartHelper(Cart.DefaultName);
    cartHelper.AddEntry(entry, quantity, false);

AddToCart method need an Entry type in input.

How can I add my products (of type Product) into the Cart?


Jun 07, 2016 23:47


As I have not received an answer, I changed my approach and transform AddToCart method like this:

public static string AddToCart(Product p)
            OrderForm orderForm;
            LineItem lineItem;

            //If GetCart can't find the cart, it will create it for you
            Cart defaultCart = OrderContext.Current.GetCart(Cart.DefaultName, EPiServer.Security.PrincipalInfo.CurrentPrincipal.GetContactId());

            //manually create an orderform and add a lineitem to it
            orderForm = new OrderForm();
            lineItem = new LineItem();
            lineItem.Quantity = 1;
            lineItem.Code = p.Code;

            lineItem.DisplayName = p.DisplayName;

            //add the orderform to the cart

            //now save the changes to the database

            return String.Empty; // only for test.

Now in my ProductList View I have:


    @foreach (var p in StartPageController.GetProducts())
        <li> @p.Title </li>

and all products in cart are listed properly.

The problem is that in Commerce Manager ->Carts->MyCart-> Order Summary is shown only 1 line

Here a screenshot.

Any idea?

Jun 08, 2016 16:49

By creating a new orderform when you add a product to your cart, and adding it to your cart, every add to cart creates a new orderform. If that's what you mean by 1 line.

You could use something like this in your add to cart method, you have the code available in your product.

Entry entry = CatalogContext.Current.GetCatalogEntry(code);
cartHelper.AddEntry(entry, quantity, false);

Jun 08, 2016 17:47

Thank you Jeroen, bu  CatalogContext.Current.GetCatalogEntry(p.code) return nullMediachase.Commerce.Catalog.Objects.Entry.

In debug I see that p.code is not null and it is set to "p02_1" that is my product code.

Also CatalogContext.Current in debug is not null.

What'is wrong?

Jun 09, 2016 15:09

Is your "Product" is based on VariationContent? If so, you should be able to get your variation by it's code.

btw, it may be that naming your class "product" could create a problem, not sure though, but it is also the ClassTypeId for ProductContent.

Have you looked at Quicksilver?

Jun 09, 2016 16:50

Quicksilver starter kit is a good idea if you don't want to re-implement all shopping workflow.

I'm trying to start with Quicksilver. I rebuild the solution and try to install the database but when I run  Setup\SetupDatabases.cmd  to install the DB this error is shown:

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. .

My Sql Server work fine and MSSQL$SQLEXPRESS Services is running.

Jun 09, 2016 19:31

Maybe you will have to change the connectionstring to fit your version of sql(express)?

Jun 13, 2016 11:28

For quick silver, Go through the steps manually included in Setup.cmd file.

Those will be 
Creating 2 database
Creating Users.
Run a script from cms package
Run a script from commerce package
Run few workflow packages


Jun 13, 2016 13:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.