Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > need shopping preview w product list + price View modes: 
User avatar
Member
Member
eagleag - 8/31/2009 3:01:29 AM
   
need shopping preview w product list + price
Hi,

I want to create a webpart that will display a preview of the shopping cart.
it should be something like this:

Banana 4Kg $20
Apples 0.5Kg $10
Beer 25L $5

I want this "shopping cart preview to appear on my sites sidebar.
It shouls show the latest 10 items added to the shopping cart. last item added should show at top of list.
+ I would like to remove the link that send a customer to the actual shopping cart each time they add a item.

MANY THANKS :)
HOPE I CAN GET THIS WORKING

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/8/2009 5:07:59 AM
   
RE:need shopping preview w product list + price
Hello,

You can take a look, how the standard shopping cart is displayed and create a webpart, which would behave similar. The code can be found under ~\CMSModules\Ecommerce\CMSPages\ShoppingCartSKUPriceDetail.aspx.cs or~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartPreview.ascx. There is also a Mini Preview Shopping cart located in ~\CMSWebParts\Ecommerce\ShoppingCartMiniPreviewWebPart.ascx.cs.

The products are added to the shopping cart via query strings. By default it isn't possible to change this behavior. You would have to change the~\CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs
and add the product through the API. You can find an example bellow.


// Get current shopping cart

ShoppingCartInfo cart = CMSContext.CurrentShoppingCart;

if (cart == null)

{

// If current shopping cart hasn't been created yet -> create new empty one

cart = ShoppingCartInfoProvider.CreateShoppingCartInfo(CMSContext.CurrentSite.SiteID);



// Associate new shopping cart with the current session

CMSContext.CurrentShoppingCart = cart;

}



int skuId = 10;

int quantity = 1;



// Ensure shopping cart is saved to DB

if (cart.ShoppingCartID == 0)

{

ShoppingCartInfoProvider.SetShoppingCartInfo(cart);

}



// Add product to shopping cart - you can call this method to add multiple products as you need

cart.AddSKUUnitsToShoppingCart(skuId, quantity);



// Save shopping cat products

ShoppingCartInfoProvider.SetShoppingCartItems(cart.ShoppingCartID, cart.CartItems);


Best Regards,
Boris Pocatko

User avatar
Certified Developer 8
Certified Developer 8
richard - 9/16/2009 4:16:23 AM
   
RE:need shopping preview w product list + price
Hi Boris

I cannot seem to get this to work (4.1) CMSContext.CurrentShoppingCart is not available

Is there an alternative?

Regards

Richard

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/22/2009 8:53:00 AM
   
RE:need shopping preview w product list + price
Hello,

If there is no shopping cart available in the current context, you need to create one. You can find the code on the creation of an shopping cart in the file ~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCart.ascx.cs. The mentioned code is around the line 84 in the Page_Load method.

Best Regards,
Boris Pocatko

User avatar
Member
Member
eagleag - 9/22/2009 5:13:25 AM
   
RE:need shopping preview w product list + price
Hi,
I looked at ~\CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs
but not sure what I need to take out/replace/ delete or where to put the new code to add products throw API.

+ After I would get that part working. how could I get the "add to cart" button to stop linking over to shopping cart.
THANKS :)

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/25/2009 1:36:28 AM
   
RE:need shopping preview w product list + price
Hello,

There is no specific "place" where you can add products to the shopping cart. As you can see in my previous post, you can add products to the shopping cart anywhere, if you can obtain the current shopping cart of the user.

The code which is redirecting the user to the shopping cart and adding products to it is located in the method AddProductToShoppingCart(...). More specifically, the code is located around the line 593 (4.1 version):

            // Add product to the shopping cart
UrlHelper.Redirect(url.ToString());


Best Regards,
Boris Pocatko

User avatar
Member
Member
eagleag - 9/27/2009 3:20:29 AM
   
RE:need shopping preview w product list + price
thanks for your reply.

I tried playing around with the redirect but I couldn't get it to add the product to shopping cart but not actually be redirected to the shopping cart.

Is there any chance that someone can post exact instructions on how to achieve this?

I would be MOST THANKFUL

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/28/2009 9:05:59 AM
   
RE:need shopping preview w product list + price
Hello,

Have you tried to add the products with the following code?

// Add product to shopping cart - you can call this method to add multiple products as you need

cart.AddSKUUnitsToShoppingCart(skuId, quantity);


// Save shopping cat products

ShoppingCartInfoProvider.SetShoppingCartItems(cart.ShoppingCartID, cart.CartItems);


After that you need to disable the redicerting to the shopping cart by deleting the following line of code from the file ~\CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs:

// Add product to the shopping cart
UrlHelper.Redirect(url.ToString());


Best Regards,
Boris Pocatko