tkstock Posted December 11, 2007 Share Posted December 11, 2007 I've created my own shopping cart - stored in session state. Essentially, the cart is an object which contains cartline objects, which contain item objects, etc. Each object has the ability to output details about itself via HTML or plain text (plain text is used in receipt mailings). After the user processes their payment, the receipt is built and then sent in an email. Line breaks put directly into the $message string $message = "Cart information\n" come out as line breaks in the email. Line breaks that are output from the objects return "Item Description\n" come out with the slash-n in the email. I've even tried casting the call (string) $cart->get_cart_line[1]->get_item_description() but this doesn't work either. Does anyone have thoughts on why the \n isn't being used as a line break in the email if it's being returned from an object? Thanks for your help!!! Quote Link to comment Share on other sites More sharing options...
tkstock Posted December 11, 2007 Author Share Posted December 11, 2007 I just had a thought - could this be an issue because I'm serializing the cart before putting it into session state? $_SESSION["cart_name"] = serialize($localcart); So, for the receipt generator, I'm unserializing the cart $localcart = unserialize($_SESSION["cart_name"]); then processing the code to build the receipt into the email...? Although, the receipt text is build after the cart is unserialized... Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 Are you sure your using double quotes around all strings? The \n char is not turned into line feeds unless in double quotes. On a side note, there is no need to serialize an object before placing it into the $_SESSION array. Sessions are automatically serialized / unserialized as required. Quote Link to comment Share on other sites More sharing options...
tkstock Posted December 11, 2007 Author Share Posted December 11, 2007 Are you sure your using double quotes around all strings? The \n char is not turned into line feeds unless in double quotes. You are probably right. I'll check this when I have access to the code again!!! Thanks! I was hoping it was something simple. On a side note, there is no need to serialize an object before placing it into the $_SESSION array. Sessions are automatically serialized / unserialized as required. Does that mean in effect I'm doing serialize(serialize($cart))? Is there much additional overhead for this or any reason why I should go through my code and remove the serialize / unserialize calls? If I do this: $_SESSION["cart_name"] = serialize($localcart); and subsequently do this: $localcart = $_SESSION["cart_name"] would the local cart be OK? I guess I'm not familiar with exactly what the serialize / unserialize do... Thanks for your help! Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 If I do this: $_SESSION["cart_name"] = serialize($localcart); and subsequently do this: $localcart = $_SESSION["cart_name"] would the local cart be OK? I guess I'm not familiar with exactly what the serialize / unserialize do... Thanks for your help! All you need do is... $_SESSION["cart_name"] = $localcart; and... $localcart = $_SESSION["cart_name"] There probably is little overhead doing it the way your doing it, but just letting you know its not needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.