November Happy Hour will be moved to Thursday December 5th.

Add Notes dynamically

Vote:
 

    Hi,

How do you add notes dynamically to a Cart?

I have used the following code yet the Notes are never added

 


OrderNote on = new OrderNote(); on.Detail = AnswerRef; on.OrderNoteId = Convert.ToInt32(QuestionRef); on.Title = AnswerRef; on.Type = "Custom"; on.Created = DateTime.Now; ch.Cart.OrderNotes.Add(on);

ch being a new CartHelper - the code comes afer an entry is added to the cart (ch)

eg:

ch.AddEntry(variant, 1, false, warehouseCode, new CartHelper[] { wishList });

    

 

Jon

#83210
Mar 27, 2014 14:49
Vote:
 

Hi,

I looks like you need to call

ch.Cart.AcceptChanges() after that code to make sure it got saved to database. Otherwise it'll be lost when GC kicks in.

Regards.

/Q

#83215
Mar 27, 2014 15:24
Vote:
 

Yes, I do this too and nothing happens - the AddNew() method works but not Add(on).

#83228
Mar 27, 2014 16:54
Vote:
 

AddNew() works but then you can't update the new OrderNote

#83229
Mar 27, 2014 16:55
Vote:
 

AddNew() leaves blank entries into the Notes section and does not save the updates - ch.Cart.AcceptChanges() doesnt update the Notes  - any ideas?

#83231
Mar 27, 2014 17:08
Vote:
 

Have you tried AddNew first and finally AcceptChanges:

OrderNote on = ch.Cart.OrderNotes.AddNew();
on.Detail = AnswerRef;
on.OrderNoteId = Convert.ToInt32(QuestionRef);
on.Title = AnswerRef;
on.Type = "Custom";
on.Created = DateTime.Now;
ch.Cart.AcceptChanges();

#83239
Mar 27, 2014 20:30
Vote:
 

This is great but it still doesnt save the OrderNote. Is there any other way that this can be done?

#83251
Mar 28, 2014 9:06
Vote:
 

Just to be clear, do you want to update an existing OrderNote or create a new one?

I ask because you are trying to set OrderNoteId:

on.OrderNoteId = Convert.ToInt32(QuestionRef);

If you want to update an existing note I think you need to find it by iterating ch.Cart.OrderNotes and change the wanted note and AcceptChanges. If you want to create a new note then don't set the OrderNoteId.

 

#83256
Mar 28, 2014 9:43
Vote:
 
Arrr! I see - yes I want to create a new Note. This sounds good - I'll give it a go :) Thanks
#83257
Mar 28, 2014 9:45
Vote:
 

Yes - just tested it and it works - amazing - many thanks :)

#83260
Mar 28, 2014 10:04
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.