API Questions on Kentico API.
Version 6.x > API > Custom ShoppingCart provider View modes: 
User avatar
Member
Member
Jim - 1/6/2012 4:50:56 PM
   
Custom ShoppingCart provider
I have a need (or at least I think I do) to extend the ShoppingCart object within the EcommerceProvider library.

We want an option within the ShoppingCartContent control to show a thumbnail image of the product on each line item. We were able to accomplish the addition of the thumbnail by modifying the ShoppingCartContent control. This part was easy.

The hard part is that we need to have some way through the admin tools where we can turn on/off the thumbnail and also set the size of the thumbnail.

My first thought was to modify the ShoppingCart web part with the new properties, but I couldn’t figure out how to pass the information set in the web part down to the actual control that needs the information (ShoppingCartContent).

Then I read about creating a custom provider and I thought "Ah-Ha!", I will create a custom ShoppingCart provider class and add the new properties that I need there. However, when looking into it further, the ShoppingCart class is not a provider class.

So my question is… What is the best way to accomplish what I’m looking for?

Thanks for any help.

Jim Garwacki

User avatar
Member
Member
kentico_michal - 1/9/2012 1:39:52 AM
   
RE:Custom ShoppingCart provider
Hello,

Kentico CMS 6.0 provides a new customization model that allows you to create a custom ShoppingCartInfoProvider quite easily. You just need to create a new class by inheriting from the ShoppingCartInfoProvider class and add new properties according your requirements.

Then, you need to register this new provider as it is described in this blog (the section Custom modules in Kentico CMS 6): Code customization in Kentico CMS 6.

By the way, an example of a custom shopping card info provider can be seen in the ~\App_Code\CMSModules\Ecommerce\Samples\CustomShoppingCartInfoProvider.cs file.

Best regards,
Michal Legen

User avatar
Member
Member
Jim - 1/9/2012 9:39:52 AM
   
RE:Custom ShoppingCart provider
Hi Michal,

Thanks for the info. I'm aware of the ShoppingCartInfoProvider and I know I can customize that, but I don't think that’s what I need.

The ShoppingCartInfoProvider class within the CMS.Ecommerce library has information about the items within the cart, tax, totals, etc., but not really the cart itself.

I looked into it further and noticed that the ShoppingCart class within CMS.EcommerceProvider I was referring to before is actually a CMSAdminControl and not just a class after all. This is really where I want to add the additional properties, but I don’t think this can be extended to do what I want.

I need to add some additional properties to the ShoppingCart web part control to support visibility and size of product thumbnail images. I need a way to pass the information from the ShoppingCart web part down to the control that actually displays the information (ShoppingCartContent.ascx, a ShoppingCartStep control). I can’t see how the ShoppingCartInfoProvider would be the correct place for this.

If you know of another way I can accomplish this, I would appreciate any help.

Thanks,

Jim Garwacki

User avatar
Member
Member
kentico_michal - 1/10/2012 7:31:53 AM
   
RE:Custom ShoppingCart provider
Hi Jim,

In that case, you can add a new property to the Shopping cart web part (~\CMSWebParts\Ecommerce\ShoppingCart\ShoppingCartWebPart.ascx.cs), as demonstrated here:

    
public string CustomProperty
{
get
{
return ValidationHelper.GetString(this.GetValue("CustomProperty"), this.cartElem.CustomProperty);
}
set
{
this.SetValue("CustomProperty", value);
this.cartElem.CustomProperty = value;
}
}

also, the following code needs to be added to the SetupControl method:


this.cartElem.CustomProperty = this.CustomProperty;

where the cartElem is ID of the Shopping cart control being used in this web part.

Of couse, in order to be able to define this property directly in the CMS Desk in the web part properties, you need add this property in the Site manager -> Development -> Web parts -> edit the Shopping cart web part -> Properies -> add a new property called CustomProperty.

Then, you need to create this property also in the Shopping cart control (~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCart.ascx.cs):

    
public string CustomProperty
{
get
{
return ValidationHelper.GetString(this.ShoppingCartInfoObj.ShoppingCartCustomData["CustomProperty"], String.Empty);
}
set
{
this.ShoppingCartInfoObj.ShoppingCartCustomData["CustomProperty"] = value;
}
}

Please notice that the value is stored in the ShoppingCartCustomData property so that you can access in each of the shopping cart step controls ( ShoppingCartContent, ShoppingCartCustomerSelection etc.) if necessary:


string customProperty = ValidationHelper.GetString(this.ShoppingCartInfoObj.ShoppingCartCustomData["CustomProperty"], String.Empty);


I hope this will help you.

Best regards,
Michal Legen

User avatar
Member
Member
Jim - 1/10/2012 9:13:15 AM
   
RE:Custom ShoppingCart provider
Michal,

This is exactly what I was looking for and it works great!

Thanks,

Jim Garwacki