Kentico custom module for Order Item Properties

Vibhuti Choubey asked on January 29, 2019 14:05


I have to develop a custom module for kentico ecommerce in which I want to display a form (in items tab of order) which lets me update the order item fields added by me in OrderItem module such as ItemStatus and some more. I want those fields to appear in "Order Item Properties - C:\inetpub\wwwroot\Kentico10\CMS\CMSModules\Ecommerce\Controls\ShoppingCart\OrderItemEdit.aspx.cs" form (which appears in the items tab of order) along with the existing fields.

How can I do so using custom module such that it overrides?

Thanks in advance

Correct Answer

Suneel Jhangiani answered on January 29, 2019 14:50

Can you explain a bit more about the workflow you are trying to implement as there may be a better way since this is complicated.

For the most part Kentico handles Ecommerce using the ShoppingCart control, so it becomes quite complex when trying to deal with additional fields in the Order Items. However, the ShoppingCartItemInfo does contain an OrderItem property which is the OrderItemInfo (only loaded if the cart is created from an existing order). Therefore, one way you can go about implementing your custom fields is to clone the ShoppingCartItemEdit alternative form and customise it by adding your additional fields - note as these are on an alternative form they would not have a corresponding field in the database. You then modify the OrderItemEdit.aspx page to use your custom form and modify the code-behind to load the field values to the form and to save them accordingly.

Of course, a downside to this is that you would need to be aware of this change in future upgrades.

1 votesVote for this answer Unmark Correct answer

Recent Answers

Vibhuti Choubey answered on January 30, 2019 14:29 (last edited on January 31, 2019 08:09)

Thanks for your response!

I actually want some additional fields like ItemStatus, QuantityShipped, QuantityRefunded etc. to be displayed in this form "Order Item Properties" below the existing fields which I guess is done in this file -> "~\CMSModules\Ecommerce\Controls\ShoppingCart\OrderItemEdit.aspx.cs". I have added these additional fields in OrderItem Class and I'm also able to update these fields using REST API. But I'm stuck at how to display these custom additional fields in the form I mentioned, so that it can be updated from UI as well.

I think you understood my need and thanks for your explanation! I followed it but now I'm stuck at how to get a custom field from a class and set it as the value to one of the form controls. I'm stuck at this line -> EditForm.FieldControls["CartItemStatus"].Value = item.ItemStatus; As ItemStatus is the field I have manually added to OrderItem class and not one of the properties of OrderItem class, I'm getting the following error:

'OrderItemInfo' does not contain a definition for 'ItemStatus' and no extension method 'ItemStatus' accepting a first argument of type 'OrderItemInfo' could be found (are you missing a using directive or an assembly reference?)

Can you help me with how can I access this field?

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on January 31, 2019 19:18

For that line you would use something like:

EditForm.FieldControls["CartItemStatus"].Value = item.GetValue<MyStatusEnum>("ItemStatus", MyStatusEnum.Shipped);

I used a status enum to highlight that you can get any type you want.

1 votesVote for this answer Mark as a Correct answer

Vibhuti Choubey answered on February 4, 2019 06:41

That did work!! Thanks alot :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.