在不同页面上显示SimpleCart数据

时间:2014-12-19 10:18:04

标签: javascript php html web simplecart

我在写一个网站时遇到一个小问题,我希望得到任何人的帮助。

我在网站上实现了一个simpleCart,购买过程非常简单。

我想做的是让用户进入他可以填写表格然后继续结账的页面。 (我不希望用户创建一个帐户,只是为了购买单个项目)

但我似乎无法将simplecart值推到其他页面(我只需要总价)。

我尝试的是以下内容:

  • 以PHP会话存储总价
  • 以Javascript Cookie存储总价
  • 在simplecart上创建新的结帐活动,将用户重定向到自定义页面,在该页面中,他可以填写表单,然后结帐以获取真实内容。

我对所有这些都没有运气,我会感激任何想法或帮助。

这是我已经尝试过的一些代码:  可以通过添加以下内容来显示简单购物车总数: 或(javas)this.returnFormattedPrice(tempItem.getValue('price'))

首先我尝试将输出存储在php会话中:

第1页上的

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

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

其次我尝试使用javas cookie:

这是脚本代码:

`// 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"; } }`

第1页的

我会设置cookie,在第2页我会读它 但要用两者进行设置:    <div class="simpleCart_total"></div> 或(javas)this.returnFormattedPrice(tempItem.getValue('price') )

不起作用(它不会存储总价格)

所以,如果有人采用更简单的方法,我会很感激。

提前致谢

艾哈迈德

1 个答案:

答案 0 :(得分:0)

你使用php会话的方式不会有效,试试这个。 在您想要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 />';
}
?>