Remove Payments from OrderForm

Vote:
 

Hi all

We use the Cart and related objects to store state during our checkout flow. I would like to use the OrderForm.Payment to temproary stor which payment type the user has selected, but there seems to be a problem removing the Payment entries from the list.

I have tried with this code:

orderForm.Payments.Clear();
orderForm.AcceptChanges();

This does not work. When I load the cart again, any old Payment objects still exist in the collection.

I have resorted to this code instead, and this seems to work:

foreach (MetaObject mo in orderForm.Payments)
{
  mo.Delete(); 
}
orderForm.AcceptChanges();

Is this a bug, or am i doing something wrong?

Regards

Anders

#81099
Feb 10, 2014 11:50
Vote:
 

Hi,

To delete payments from an order form, you need to delete each payment:

foreach(Payment payment in orderForm.Payments)

{

    payment.Delete();

}

Your second code is correct (Payment inherits Delete() from MetaObject). This is intended.

Regards.

/Q

 

#81130
Feb 11, 2014 2:52
Vote:
 

Hi Quan

 

Thank you for your reply.

If it is intended, that you have to deleate each metaobject instead of just removing them from the collection, then why do you have the Clear and RemoveAt methods? I know that they are most likely inherited from some collections interface, but that doesn't change my question. Why have a method on your API that doesn't work?

I know that we have spend a few hours trying to figure out why the Clear and RemoveAt method did not work as expected, before figuring out that we should use the Delete method, which is not a standard Collection API method.

In my opinion, the right way to implement a framework must be, to make sure that all methods behave as expected, or otherwise make sure that the methods are not there to avoid confusion.

I'm new to EPiServer, and in many ways, I very much like the functionality that I find. However, I don't like how difficult it sometimes is to fint the functionality, and that sometimes something does not behave as expected. Please see this as feedback to EPiServer on how to improve an otherwise great product.

Regards

Anders

#81133
Feb 11, 2014 5:36
Vote:
 

Hi,

My comment was, deleting the MetaObject is intended, not something you did wrong. It's not about the Clear, RemoveAt... methods do not work as expected is intended.

From my opinion, the Delete() make sure that caller want to explicitly delete that MetaObject item - why Clear or RemoveAt simply remove it from the list. But those old objects appear again is clearly a problem - I missed that line - I'll take a look at this to see if it's a bug a not. I'll also rise an internal question about how we want to do with Clear() and RemoveAt().

Thank you for your feedback. Your feedbacks are one of reasons why EPiServer products are getting better each iteration.

/Q

#81134
Edited, Feb 11, 2014 7:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.