0

I have a small issue with a website i'm writing and i hope for anyone's help.

I'm implementing a simpleCart in a website, the buying process is pretty simple.

What i wish to do is to proceed the user to a page where he can fill in a form and then proceed to checkout. (i don't want users to create an account and everything just for the sake of buying a single item)

But i can't seem to push the simplecart value to that other page (i only need the total price).

what i tried is the following:

  • store total price in PHP session
  • store total price in Javascript Cookie
  • create new checkout event on simplecart to redirect the user to a custom page where he can fill the form and then checkout for real.

i had no luck with all of these and i wold appreciate any ideas or help.

here's some of the code i already tried: the simple cart total can be displayed either by adding: or (javas) this.returnFormattedPrice(tempItem.getValue('price') )

First i tried storing the out put in php sessions:

on Page1:

<?php session_start(); $_SESSION['variable_name'] = '<div class="simpleCart_total"></div>'; ?> on Page 2:

<?php session_start(); echo $_SESSION['variable_name']; ?>

Second i tried using a javas cookie:

here's the script code:

`// JavaScript Document

function getCookie(NameOfCookie) {

if (document.cookie.length > 0) {

begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1) {

begin += NameOfCookie.length+1; end = document.cookie.indexOf(";", begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null;

}

function setCookie(NameOfCookie, value, expiredays) {

var ExpireDate = new Date (); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); }

function delCookie (NameOfCookie) {

if (getCookie(NameOfCookie)) { document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } `

on page 1 i would set the cookie and on page 2 i would read it but setting it up with both : <div class="simpleCart_total"></div> or (javas) this.returnFormattedPrice(tempItem.getValue('price') )

didn't work ( it would'nt store the total price)

so if anyone has a simpler approach i would appreciate it.

thanks in advance

Ahmad

Ahmad
  • 1
  • 1
  • When you don't post any code it looks suspiciously like you want someone to do all your coding for you without even trying. post some of what you've tried. What didn't work in the php session ? why didn't the cookie work ? – Billy Dec 19 '14 at 10:23
  • I stated clearly that even proposing some ideas would work so i can try them myself. But you're right here some of what i tried: – Ahmad Dec 20 '14 at 08:07

1 Answers1

0

The way you had the php session would not have worked, try this. On the top of all the pages where you want the var put

<?php
session_start();
if(isset($_SESSION['total_price'])){$total_price=htmlentities($_SESSION['total_price']);
echo ' The total price of all items in your cart is $'. $total_price.'<br />';
}
?>
Billy
  • 2,448
  • 1
  • 10
  • 13
  • Thank you for your help i appreciate it. But i put the code on both the page where i'm generating the total and on the page where i want to display it again.But it didn't work. I feel i should define what to store in the $_SESSION ? – Ahmad Dec 20 '14 at 15:52