Jump to content

Recommended Posts

<?php

I downloaded a cart from wfcart which I assimiliated into my session having a loggin procedure(jpmasters).

The problem is when I shop the details of ones pages transaction are not available in another page and vice versa and then disapppear.

This is my code

 

//Class session

{

  /* Class constructor */

  function Session(){

      $this->time = time();

      $this->startSession();

  }

 

  var $total = 0;

  var $itemcount = 0;

  var $items = array();

  var $itemprices = array();

  var $itemqtys = array();

  var $iteminfo = array();

 

function get_contents()

{ // gets cart contents

$items = array();

foreach($this->items as $tmp_item)

{

    $item = FALSE;

$item['id'] = $tmp_item;

            $item['qty'] = $this->itemqtys[$tmp_item];

$item['price'] = $this->itemprices[$tmp_item];

$item['info'] = $this->iteminfo[$tmp_item];

$item['subtotal'] = $item['qty'] * $item['price'];

            $items[] = $item;

}

return $items;

}

/* end of get_contents */

 

function add_item($itemid,$qty=1,$price = FALSE, $info = FALSE)

{

global $database;

// adds an item to cart

                if(!$price) {  $price = $database->wf_get_price($itemid)*$qty; }

 

                if(!$info) {    $info = $database->CartProductInfo($itemid);}

 

if($this->itemqtys[$itemid] > 0)

                { // the item is already in the cart..

  // so we'll just increase the quantity

$this->itemqtys[$itemid] = $qty + $this->itemqtys[$itemid];

$this->_update_total();

} else {

echo 'itemid query '.$itemid.'<br>';

echo 'qty query '.$qty.'<br>';

echo 'price query '.$price.'<br>';

echo 'info query '.$info.'<br>';

 

$this->items[]=$itemid;

$this->itemqtys[$itemid] = $qty;

$this->itemprices[$itemid] = $price;

$this->iteminfo[$itemid] = $info;

}

$this->_update_total();

}

/* end of add_item */

 

//how I  add into the cart

if($_POST['Submit']) {

$product = $products[$_POST['id']];

$session->add_item($_GET['uID'],$_POST['qty'],$ProductInfo["price"],$ProductInfo["synopsis"]);

}

 

//how I retrieve the cart contents

if($session->itemcount > 0) {

foreach($session->get_contents() as $item) {

echo "<br />Item:<br/>";

echo "Code/ID :".$item['id']."<br/>";

echo "Quantity:".$item['qty']."<br/>";

echo "Price  :$".number_format($item['price'],2)."<br/>";

echo "Info    :".$item['info']."<br />";

echo "Subtotal :$".number_format($item['subtotal'],2)."<br />";

echo "<form method=post><input type='hidden' name='id' value='".$item['id']."'/><input type='submit' name='remove' value='Remove'/></form>";

}

echo "---------------------<br>";

echo "total: $".number_format($cart->total,2);

} else {

echo "No items in cart";

}

 

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.