Jump to content

Shopping Cart Video Tutorial


debmc99

Recommended Posts

Hi. I hope I am in the right forum. Sorry if these are dumb questions but I am a beginner.

 

I purchased the PHP Shopping Cart video tutorial, I have wamp and eclipse installed. Everything was going fine up until video #7 - Building the Shopping Cart Object. I am typing the code along with the video. But when it is time to test it I keep getting errors like this:

 

Fatal error: Call to a member function EmptyCart() on a non-object

 

Eclipse is not showing any errors. I have typed everything exactly.

 

When I look at the source file in Firefox I see this:

 

EmptyCart(); echo render_notification('Shopping Cart Emptied'); } set_shopping_cart($shopping_cart); ?>

 

Any advice would be appreciated. Thank you.

Link to comment
Share on other sites

Here is the exact error message:

 

Fatal error: Call to a member function AddItem() on a non-object in C:\wamp\www\my_php\shoppingcart\PaypalShoppingCart\html\addToCart.php on line 14

 

Line 14 is this: $shopping_cart->AddItem($product_id);

 

Here is the code:

 

<?php
require_once '../functions/functions.php';

$shopping_cart = get_shopping_cart();

?>
<?php echo render_header('Pasta Shop: Catalog');?>

<?php 
$product_id= $_REQUEST['id'];

if (product_exists($product_id))
{
$shopping_cart->AddItem($product_id);
}

?>

<?php 
function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter)
{
$quantity = $shopping_cart->GetItemQuantity($product_id);
$output = "
<tr>
	<th>
		$product_id
	</th>
	<th>
		$quantity
	</th>
	<th>
		$ Amount
	</th>

</tr>
";
return $output;
}	
?>

<table class='shoppingCart'>


<?php 
$line_item_counter = 1;
foreach ($shopping_cart->GetItems() as $product_id)
{
	echo render_shopping_cart_row($shopping_cart , $product_id , $line_item_counter);
	$line_item_counter ++;
}


?>	


<tr>
	<td>
		product_id
	</td>

	<td>
		quantity
	</td>

	<td>
		$amount
	</td>
</tr>


</table>

<?php 
set_shopping_cart($shopping_cart);

?>
<?php echo render_footer();?>

 

 

Thank you for your help.

Link to comment
Share on other sites

I don't think there's anything wrong with the code you posted above... no typos or errors that I can see.

 

It's possible the error doesn't have anything to do with this file itself, and maybe the get_shopping_cart() function is wrong somehow. If that function isn't getting the shopping cart correctly, I imagine the addItem() function will throw an error. Perhaps you can post the code to that function?

 

It may be better to simply send me all the files (compress them into one ZIP file, if you can) and I can take a look directly -- ben [at] falkencreative.com. It's a bit hard to figure this out when you're dealing with multiple files and functions all calling each other.

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...