Pages:

Adding quantity +1 when refreshing browser

Swedish

No avatar

2005-05-14 23:33

As the topic says.
When the shoppingcart is updated thru the browsers refresh button all items get +1. So if i refresh 10 times i'll suddenly have 11 of every item in my cart.
The same thing happens when jumping back and forth between the cart and the checkout page when using the browsers back/forward buttons.

Ive read through most of the posts at this board and didnt find anything that would fix the problem.

It looks very lame when it increases the quantity like that and it also adds extra work when customers wonder why i sent 4 of every item instead of 1....

So is there a fix to solve this or should i drop QC?

Wizzud

No avatar

2005-05-15 13:33

I believe there is a way of stopping this. I've tried it on a v0.3.0 loaded version and it seems to work.

When a request comes in for p=ordersBasket the code checks for sOption being set to add/del/save. If any of these are set it does the necessary and drops out of the bottom of the main IF clause. Just before it drops out of that IF clause you could insert

header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersBasket' );
exit;

which causes the browser to re-request the basket page but with no GET or POST fields, ie as if you had hit the basket link on the top menu. A refresh will then simply refresh the basket page, without re-applying any updates. Likewise, hitting the back button from the checkout page will simply display the basket.

For example (v0.3.0 code - actions_client/orders.php - but similar would probably apply to index.php for v0.2.x code):

if($a == 'Basket'){
if(isset($sOption)){
if($sOption=='add'){
...
}elseif($sOption=='del'){
...
}elseif($sOption=='save'){
...
}
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersBasket' );
exit;
}// end of if(isset ...
...
...
}// end of if($a=='Basket ...

PS: Be aware of any plugins that may have redefined parts of that code segment, eg productAttributes, that would also need changing in a similar manner. Also, strictly speaking, its probably safer to use a full URL in the Location statement rather than the relative URL used here - I simply modified existing an existing QC code fragment.

Swedish

No avatar

2005-05-16 20:48

I've tried this and it works, but it makes it impossible to get to the checkout page.
Maybe im doing something wrong?

Wizzud

No avatar

2005-05-17 11:50

Maybe!
Works fine for me on v0.3.0 and v0.2.x (with modifications to suit version).
If you can't get to the delivery page you've probably put the redirect (the header... and exit lines) in the wrong place; they have to go INSIDE the IF statement that begins with 'if(isset($sOption)){' and at the bottom of the statement just before the terminating '}', as indicated above. Match the curly brackets!
(And don't forget productAttributes/actions_client.php, if you have it installed!)

[v0.2.x uses $akcja instead of $sOption, and the page you redirect to is basket instead of ordersBasket, but the principle is still the same.]

Swedish

No avatar

2005-06-02 20:38

Thanks!
This solved the problem!

Swedish

No avatar

2005-06-02 20:39

This is how my code looks now:

if( $a == 'Basket' ){

if( isset( $sOption ) ){

if( $sOption == 'add' ){
if( isset( $iProduct ) && is_numeric( $iProduct ) && isset( $iQuantity ) && is_numeric( $iQuantity ) && $iQuantity > 0 ){
addBasketProduct( $iProduct, $iQuantity );
}
}
elseif( $sOption == 'del' ){
$iOrder = throwOrdersIdTemp( $_SESSION['iCustomer'], null );
if( isset( $iElement ) && is_numeric( $iElement ) )
delBasketElement( $iOrder, $iElement );
}
elseif( $sOption == 'save' ){
extract( $_POST );
if( isset( $aQuantity ) && is_array( $aQuantity ) ){
$iCount = count( $aQuantity );
for( $i = 0; $i < $iCount; $i++ )
if( $aQuantity[$i] != $aQuantityBefore[$i] && is_numeric( $aQuantity[$i] ) && $aQuantity[$i] > 0 )
addBasketProduct( $aProduct[$i], $aQuantity[$i] - $aQuantityBefore[$i] );
}

if( isset( $save ) ){
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersDelivery' );
exit;

header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersBasket' );
exit;

}

}
}

Swedish

No avatar

2005-06-02 20:40

Hmm, now it doesnt work...

Haha..

Swedish

No avatar

2005-06-02 20:42

It works until i start adding products again.

Cant you post the full correct code ?

wizzud

No avatar

2005-06-03 09:15

You didn't count the curlies! The redirect needs moving down by one curly bracket, eg. from your code above ...

...
...
if( isset( $save ) ){
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersDelivery' );
exit;
}
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersBasket' );
exit;
}
}

Swedish

No avatar

2005-06-04 11:00

This is how it looks now:

if( isset( $save ) ){
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersDelivery' );
exit;



}

}
header( 'Location: '.$_SERVER['PHP_SELF'].'?p=ordersBasket' );
exit;
}

$iOrder = throwOrdersIdTemp( $_SESSION['iCustomer'], null );

if( isset( $iOrder ) && is_numeric( $iOrder ) )
$content .= listBasket( $iOrder );
else
$content .= $tpl->tbHtml( 'orders_basket.tpl', 'NOT_FOUND' );
}

And it works just fine...
Thanks!

Ray Floyds

No avatar

2005-06-29 22:10

great this fix did fix my problem aswell... (code v0.3.0) !!

www.quickcart.nl Dutch Support Site

Tom

Avatar: Tom

2005-06-30 04:33

Worked for me too. Excellent! (code v0.3.0)

t

unknown

No avatar

2005-06-30 09:13

dumber php shop i ever seen!

john

Avatar: john

2005-07-14 16:40

to Wizzud
Hi.
Which file do i have to change and where to put the changed code ?

version 0.2.4

john

wizzud

No avatar

2005-07-14 19:58

John ...
index.php, looking for code beginning "if( $p == 'basket' ){" rather than "if( $a == 'Basket' ){", and noting that v0.2.x uses $akcja instead of $sOption, and the redirect points to p=basket instead of p=ordersBasket (as stated in above posts!)

john

Avatar: john

2005-07-14 23:59

Sorry i am a litle heavy in the head ;-)
is it possible that you past the full code here so that i can copy paste it
Thanks

john

zak

No avatar

2005-08-03 10:43

Hello, im using version 0.2.5 and cant solve this problem.

Maybe someone could paste the index.php code here?

Kevin

No avatar

2005-08-04 03:15

I am not that good at php and i dont know were to place this can someone post the complete code and tell me were to put it?

Kevin

Itsme

No avatar

2005-08-11 12:49

please, can anybody answer?

Kev

No avatar

2005-08-27 17:15

anybody?

Pages:
Back to top
about us | contact