Gift Message & Delivery Instructions Disappear
-
- Lieutenant (LT)
- Posts: 80
- Joined: Fri Sep 19, 2008 11:39 am
Gift Message & Delivery Instructions Disappear
Hi Mazhar,
Me again. not quite sure if you can help with this. Some of our customers seem to be making the same mistake:
1) They would like to have a Delivery Message and Gift Message attached and have proceeded to the final screen <Checkout/Payment.aspx>
a) When they get to the Final review screen they go into 'Change Shipping Method' <ShipMethod.aspx> (at this point the delivery message/special instructions they have entered previously is gone>>> assumming they re-enter the delivery/message and press continue>>>they land on the Final checkout screen <Checkout/Payment.aspx> and the Gift Message is gone as well...a lot people don't realize that their message has disappeared and proceed to checkout. Wondering if this is a bug or something we could do about to fix.
Thanks Mazhar!
Serge
Me again. not quite sure if you can help with this. Some of our customers seem to be making the same mistake:
1) They would like to have a Delivery Message and Gift Message attached and have proceeded to the final screen <Checkout/Payment.aspx>
a) When they get to the Final review screen they go into 'Change Shipping Method' <ShipMethod.aspx> (at this point the delivery message/special instructions they have entered previously is gone>>> assumming they re-enter the delivery/message and press continue>>>they land on the Final checkout screen <Checkout/Payment.aspx> and the Gift Message is gone as well...a lot people don't realize that their message has disappeared and proceed to checkout. Wondering if this is a bug or something we could do about to fix.
Thanks Mazhar!
Serge
Re: Gift Message & Delivery Instructions Disappear
Hi Serge. My customer wanted the same thing but we're only using the delivery instructions field (which we relabeled as gift message) because we only want it per destination.
What I did was save the messages from the ShipMethod page to a session variable. Then, when ShipMethod page is loaded, I initialize the textboxes with the stored values if they are blank.
Here's the code I used to save and restore the delivery instructions:
In ShipMethod.ascx, modify the PageLoad as follows:
and in ContinueButton_Click:
I don't promise that this will work as is since my checkout process is partially customized but it should at least get you going in the right direction.
Regards.
What I did was save the messages from the ShipMethod page to a session variable. Then, when ShipMethod page is loaded, I initialize the textboxes with the stored values if they are blank.
Here's the code I used to save and restore the delivery instructions:
Code: Select all
private struct sgShipMessage
{
public int shipmentNumber;
public int addressId;
public string shipMessage;
}
/// <summary>
/// Restore Basket Shipment Messages. Used to reapply retained ship messages if user views cart
/// and returns to checkout process.
/// </summary>
public static void RestoreBasketShipMessages(RepeaterItemCollection items, string shipMessageId)
{
HttpSessionState session = HttpContext.Current.Session;
ArrayList shipMessages = (ArrayList)session["SG_BasketShipMessages"];
if (shipMessages != null)
{
BasketShipmentCollection shipments = Token.Instance.User.Basket.Shipments;
// arraylist - number and addressid
// repeater - current order number
// basket - current shipments
// First Pass - match order number and address
int matchCount = 0;
int shipmentNumber = 0;
foreach(RepeaterItem item in items)
{
shipmentNumber++;
foreach(BasketShipment shipment in shipments)
{
if (shipment.ShipmentNumber == shipmentNumber)
{
foreach (sgShipMessage sm in shipMessages)
{
if ((sm.shipmentNumber == shipmentNumber) && (sm.addressId == shipment.AddressId))
{
((TextBox)item.FindControl(shipMessageId)).Text = sm.shipMessage;
matchCount++;
break;
}
}
}
}
}
if (matchCount < shipments.Count)
{
// Second Pass - match address only
shipmentNumber = 0;
foreach (RepeaterItem item in items)
{
shipmentNumber++;
BasketShipment shipment = shipments[shipmentNumber - 1]; // assumes in shipment order number
foreach (sgShipMessage sm in shipMessages)
{
if (sm.addressId == shipment.AddressId)
{
TextBox txt = (TextBox)item.FindControl(shipMessageId);
if (txt.Text.Length == 0)
{
txt.Text = sm.shipMessage;
break;
}
}
}
}
}
}
}
Code: Select all
protected void Page_Load(object sender, EventArgs e)
{
Token.Instance.User.Basket.Recalculate();
weightFormat = "{0:0.##} " + Token.Instance.Store.WeightUnit;
if (!Page.IsPostBack)
{
ShipmentRepeater.DataSource = Token.Instance.User.Basket.Shipments;
ShipmentRepeater.DataBind();
ShowGiftOptions.Checked = HasGiftOptions();
}
// SG Customization - ZLA 2009-07-13 - Repopulate Ship Message if necessary
SG_OrderHelper.RestoreBasketShipMessages(ShipmentRepeater.Items, "ShipMessage");
// SG End Customization - ZLA 2009-07-13
foreach (RepeaterItem item in ShipmentRepeater.Items)
{
Code: Select all
if (allMethodsValid)
{
if (ShowGiftOptions.Checked) Response.Redirect("GiftOptions.aspx");
basket.ResetGiftOptions(true);
// SG Customization - ZLA 2009-07-13
// Remember ship (gift) message if we go back to shopping and return.
SG_OrderHelper.StoreBasketShipMessages();
// SG Customization - ZLA 2009-07-13
Response.Redirect("Payment.aspx");
}
Regards.
-
- Lieutenant (LT)
- Posts: 80
- Joined: Fri Sep 19, 2008 11:39 am
Re: Gift Message & Delivery Instructions Disappear
Hi ZLA,
thanks - that's smart. Do you do programming? If so can I have your contact info please?
Regards,
Serge
thanks - that's smart. Do you do programming? If so can I have your contact info please?
Regards,
Serge
-
- Ensign (ENS)
- Posts: 11
- Joined: Wed Sep 23, 2009 11:08 am
Re: Gift Message & Delivery Instructions Disappear
Hello.
I tried this and I get the following error:
error CS0117: 'ConLib_ShipMethodPage.SG_OrderHelper' does not contain a definition for 'StoreBasketShipMessages'
Any Suggestions?
I tried this and I get the following error:
error CS0117: 'ConLib_ShipMethodPage.SG_OrderHelper' does not contain a definition for 'StoreBasketShipMessages'
Any Suggestions?
Re: Gift Message & Delivery Instructions Disappear
The first section of code that begins with
is contained in a separate class file called SG_OrderHelper that is defined as:
It doesn't matter where you put the code I used to save and restore the delivery instructions as long as you call that code correctly. In my project, that code resides in the class file I mentioned and thus my calls to it are as follows:
But if you put that code in your own class then you might call it as follows:
Note that the above calls are shown together just for explanation. They are actually called from different sections of code.
Regards,
ZLA
Code: Select all
private struct sgShipMessage
Code: Select all
public class SG_OrderHelper
{
// insert private struct sgShipMessage... code here
}
Code: Select all
SG_OrderHelper.RestoreBasketShipMessages(ShipmentRepeater.Items, "ShipMessage");
SG_OrderHelper.StoreBasketShipMessages();
Code: Select all
PeaShooterClass.RestoreBasketShipMessages(ShipmentRepeater.Items, "ShipMessage");
PeaShooterClass.StoreBasketShipMessages();
Regards,
ZLA
-
- Ensign (ENS)
- Posts: 11
- Joined: Wed Sep 23, 2009 11:08 am
Re: Gift Message & Delivery Instructions Disappear
Yes, I understand that.
But when you look at this code that you posted above (that I have just put below), there is nothing in there that refers to StoreBasketShipMessages
and if this code below is supposed to be in SG_OrderHelper class file, and you are refering to a Sg_OrderHelper.StoreBasketShipMessages();
It is only right that it creates an error....
But when you look at this code that you posted above (that I have just put below), there is nothing in there that refers to StoreBasketShipMessages
and if this code below is supposed to be in SG_OrderHelper class file, and you are refering to a Sg_OrderHelper.StoreBasketShipMessages();
It is only right that it creates an error....
Code: Select all
private struct sgShipMessage
{
public int shipmentNumber;
public int addressId;
public string shipMessage;
}
/// <summary>
/// Restore Basket Shipment Messages. Used to reapply retained ship messages if user views cart
/// and returns to checkout process.
/// </summary>
public static void RestoreBasketShipMessages(RepeaterItemCollection items, string shipMessageId)
{
HttpSessionState session = HttpContext.Current.Session;
ArrayList shipMessages = (ArrayList)session["SG_BasketShipMessages"];
if (shipMessages != null)
{
BasketShipmentCollection shipments = Token.Instance.User.Basket.Shipments;
// arraylist - number and addressid
// repeater - current order number
// basket - current shipments
// First Pass - match order number and address
int matchCount = 0;
int shipmentNumber = 0;
foreach(RepeaterItem item in items)
{
shipmentNumber++;
foreach(BasketShipment shipment in shipments)
{
if (shipment.ShipmentNumber == shipmentNumber)
{
foreach (sgShipMessage sm in shipMessages)
{
if ((sm.shipmentNumber == shipmentNumber) && (sm.addressId == shipment.AddressId))
{
((TextBox)item.FindControl(shipMessageId)).Text = sm.shipMessage;
matchCount++;
break;
}
}
}
}
}
if (matchCount < shipments.Count)
{
// Second Pass - match address only
shipmentNumber = 0;
foreach (RepeaterItem item in items)
{
shipmentNumber++;
BasketShipment shipment = shipments[shipmentNumber - 1]; // assumes in shipment order number
foreach (sgShipMessage sm in shipMessages)
{
if (sm.addressId == shipment.AddressId)
{
TextBox txt = (TextBox)item.FindControl(shipMessageId);
if (txt.Text.Length == 0)
{
txt.Text = sm.shipMessage;
break;
}
}
}
}
}
}
}
Re: Gift Message & Delivery Instructions Disappear
Apologies. I didn't see your post until today. Somehow my original cut and paste left off that method. Here's the missing code:
Code: Select all
/// <summary>
/// Store Basket Shipment Messages. Used to retain and reapply ship messages if user views cart
/// and returns to checkout process.
/// </summary>
public static void StoreBasketShipMessages()
{
ArrayList shipMessages = new ArrayList();
BasketShipmentCollection shipments = Token.Instance.User.Basket.Shipments;
foreach (BasketShipment shipment in shipments)
{
sgShipMessage sm = new sgShipMessage();
sm.shipmentNumber = shipment.ShipmentNumber;
sm.addressId = shipment.AddressId;
sm.shipMessage = shipment.ShipMessage;
shipMessages.Add(sm);
}
HttpSessionState session = HttpContext.Current.Session;
session["SG_BasketShipMessages"] = shipMessages;
}
-
- Ensign (ENS)
- Posts: 20
- Joined: Tue Jan 13, 2009 11:11 am
Re: Gift Message & Delivery Instructions Disappear
Thanks for the solution!
I know this was posted 2 years ago, but hopefully you can still help.
Using this, if the user goes back and edits their ship message, it does not update. So, after editing their message and continuing to the payment.aspx page, they will see their original (not edited) message. If they return to the shipmethod.aspx page, they will also still see the original message, not the edited version.
So, how would I make it so when the user edits their ship message it overwrites their current version stored in the session?
Thanks!
I know this was posted 2 years ago, but hopefully you can still help.
Using this, if the user goes back and edits their ship message, it does not update. So, after editing their message and continuing to the payment.aspx page, they will see their original (not edited) message. If they return to the shipmethod.aspx page, they will also still see the original message, not the edited version.
So, how would I make it so when the user edits their ship message it overwrites their current version stored in the session?
Thanks!
Give More Media
http://www.givemore.com/
http://www.givemore.com/