Jump to content

Oop Shopping Cart Empty Issue


masterdrue

Recommended Posts

Hi Gang,

 

I'm somewhere between video 24 and 27 building the display of the cart contents and have run into a snag.

When I put the echo in to see the array that items are being added to the cart, this working as designed.

 

When i comment it out, and hit cart.php?empty.. the cart does not empty, though it does redirect. As I've re-watched the video's a number of times.. I'm sure like last time its some syntax error I'm missing and I've also compared nearly line by line from the source and haven't seen it.

(which doesnt mean I still didnt miss it comparing it)

/**
 * Empties items to the cart
 *
 * @access	public
 * @param	
 * @return	null
 */
public function empty_cart()
{
	unset($_GET['cart']);
}

/*
	Create page parts
*/
/**
 * Return a string containing list items for each product in cart
 *
 * @access	public
 * @param	
 * @return	string
 */
public function create_cart()
{
	//get products currently in cart
	$products = $this->get();

	$data = '';
	$total = 0;

	$data .= '<li class="header_row"><div class="col1">Product Name:</div><div class="col2">Quantity:</div><div class="col3">Product Price:</div><div class="col4">Total Price:</div></li>';

	if($products != '')
	{
		// products to display

	}
	else
	{
		// no products to display
		$data .= '<li><strong>No items in the cart!</strong></li>';

		// add subtotal row
		$data .= '<li class="subtotal_row"><div class="col1">Subtotal:</div><div class="col2">$0.00</div></li>';

		// add total row
		$data .= '<li class="total_row"><div class="col1">Total:</div><div class="col2">$0.00</div></li>';

	}
	echo "<pre>";
	print_r($products);
	echo "</pre>";
	return $data;
}

}

 

Also I do get the alert "items emptied from cart", but I'm fairly certain that their still there in relation to the video because the empty and update cart buttons do not appear as shown in the video once a successful "empty" happens.

 

v_public_cart.php

<div id="content">
<h2>Shopping Cart</h2>

   <ul class="alerts">
   	<?php $this->get_alerts();?>
   </ul>
   <form action="" method="post">
   <ul class="cart">
   	 <?php $this->get_data('cart_rows');?>        
   </ul>
   <div class="buttons_row">
   	<a class="button_alt" href="?empty">Empty Cart</a>
       <input type="submit" name="update" class="button_alt" value="Update Cart">
   </div>

   </form>
   <form action="" method="post">
   	<div class="submit_row">
       	<input type="submit" name="submit" class="button" value="Pay with Paypal">
       </div>
   </form>
</div>

 

Any idea's what to look for? Or is another way to purge the cart aside hitting the URL. Which leaves once the cart is emptied, will the buttons appear again.

 

Any help and feedback as always is greatly appreciated.

Thanks,

Drue

post-61046-055982600 1364592438_thumb.png

post-61046-071919700 1364592917_thumb.png

Link to comment
Share on other sites

Hi Ben.

 

Yes, I was moving along through during the unset of update and revisited that and saw,

 public function empty_cart()
       {
               unset($_GET['cart']);
       }

 public function empty_cart()
       {
               unset($_SESSION['cart']);
       }

 

I think my eyes were crossed for days. All is fine now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...