Jump to content

Issue with the quantity in the shopping cart.


melprok

Recommended Posts

I finish the php shopping cart videos series.

 

I have an issue when I click the PayNow button and immediately press the go back button on the browser.

 

The problem is that when I go back to the shopping cart page, from the paypal page immediately , the quantity adds one automatically.

 

 

How I can fix that?

 

Thanks

Link to comment
Share on other sites

I don't think there is much you can do about that, besides rewriting the functionality. When you visit that specific URL, it will automatically add the specified item to the cart. Probably a better option would be to split up the current shopping cart functionality into two pages: have an "add.php" page which handles adding the item to the cart, and then redirects to the cart page, which would show the items in the cart.

Link to comment
Share on other sites

I don't think there is much you can do about that, besides rewriting the functionality. When you visit that specific URL, it will automatically add the specified item to the cart. Probably a better option would be to split up the current shopping cart functionality into two pages: have an "add.php" page which handles adding the item to the cart, and then redirects to the cart page, which would show the items in the cart.

 

 

 

But the behavior is bad right?

Link to comment
Share on other sites

But the behavior is bad right?

Depends how you look at it, but yes, I'd say you should avoid that if possible.

 

I don't really have any examples of people who have done this in the past unfortunately -- I think this is the first time this particular question has been asked. It shouldn't be too complicated however. Basically, you'd just be splitting up the existing functionality:

 

-- Your main add to cart file would add the product to the cart, and then use the header() function to redirect to the cart page

-- The cart page would just handle displaying the shopping cart.

Link to comment
Share on other sites

Ok, this is the addtocart.php file. You mean redirect to the cart page from this page?

 

 

<?php

 

require_once '../functions/functions.php';

$shopping_cart = get_shopping_cart();

echo render_header();

$product_id = $_REQUEST['id'];

echo $product_id;

 

if (product_exists($product_id))

{

#echo '  product exists!';

$shopping_cart->AddItem($product_id);

}

 

set_shopping_cart($shopping_cart);

echo render_paypal_checkout($shopping_cart);

echo render_footer();

 

?>

Link to comment
Share on other sites

Correct. So you'd have two pages:

 

addtocart.php:

 

<?php

require_once '../functions/functions.php';
$shopping_cart = get_shopping_cart(); 
$product_id = $_REQUEST['id'];

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

heade("Location: cart.php");

?> 

and cart.php:

 

<?php

require_once '../functions/functions.php';
$shopping_cart = get_shopping_cart();
echo render_header(); 

set_shopping_cart($shopping_cart);
echo render_paypal_checkout($shopping_cart); 
echo render_footer(); 

?> 

I haven't tested this, so I can't guarantee it will work, but you'd need to do this or something very similar.

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