Jump to content

shopping cart quantity refresh defaults to one


duffammo

Recommended Posts

Hi Guys

 

I have a shopping cart where the quantity refresh keeps defaulting to one (i.e. you change it from one to ten and the page refreshes and defaults back to one). This is the automatic refresh, not clicking a button.

 

We have lots of other carts using almost the exact same code and they work fine. I can swap over the code in the html page for something more basic and it works. I have compared the basket.php files (both in the lib folder and the html folder - we are using smarty templates) with working sites and they are identical.

 

Here is the basket.html code:

 

				<form action="basket.html" method="post" name="update" id="update" >
				<table class="basket-table" cellpadding="0" cellspacing="0">
					<tr>
						<th width="64">Item</th>
						<th width="285" class="basket-desc">Item Description</th>
						<th width="47">Quantity</th>
						<th width="82">Price</th>
						<th width="53" class="no-rb">Remove</th>
</tr>
<!--{section name=c loop=$basket.products}-->
<tr class="<!--{cycle values="colour1,colour2"}--><!--{if $smarty.section.c.last}--> no-bb<!--{/if}-->">
<td><!--{if isset($basket.products[c].image) }--><a href="/category/<!--{$basket.products[c].categoryLink}-->/product/<!--{$basket.products[c].link}-->/<!--{if $basket.products[c].hasSiblings}-->?option=<!--{$basket.products[c].productOptionId}--><!--{/if}-->"><img src="<!--{$basket.products[c].image}-->" alt="<!--{$basket.products[c].title}-->" class="img-border" /></a><!--{else}--> <!--{/if}--></td>
<td class="basket-desc"><a href="/category/<!--{$basket.products[c].categoryLink}-->/product/<!--{$basket.products[c].link}-->/<!--{if $basket.products[c].hasSiblings}-->?option=<!--{$basket.products[c].productOptionId}--><!--{/if}-->"><!--{$basket.products[c].prodtitle}--> <!--{if $basket.products[c].hasSiblings}--><!--{$basket.products[c].optiontitle}-->:<!--{$basket.products[c].title}--><!--{/if}--></a></td>
<td><input name="quantity<!--{$smarty.section.c.index}-->" id="<!--{$basket.products[c].prodtitle}-->" value="<!--{$basket.products[c].quantity}-->" maxlength="3" onchange="this.form.submit()" type="text" /></td>
<td>£<!--{$basket.products[c].lineTotal|string_format:"%.2f"}--></td>
<td class="no-rb"><a href="/basket.html?action=delete&po=<!--{$basket.products[c].productOptionId}-->"><img src="/images/btn_bin.gif" alt="Remove" title="Remove" /></a></td>
					</tr>

					<!--{/section}-->

				</table>
				<div class="basket-text">
					Free UK mainland delivery on order value over £150
				</div>
				<div class="basket-shipping">
					<label for="region">Choose Shipping Region</label>
					<select name="region" id="region" onchange="this.form.submit();">
						<!--{html_options options=$region selected=$basket.region}-->
					</select>
				</div>
				<div class="basket-prices">
					<span>Sub-Total:</span><span class="subtotal">£<!--{$basket.totalPrice|string_format:"%.2f"}--></span>
					<span>Delivery:</span><span class="subtotal">£<!--{if isset($basket.shipping.dprice)}--><!--{$basket.shipping.dprice}--><!--{else}-->0.00<!--{/if}--></span>
					<span>VAT:</span><span class="subtotal">£<!--{$basket.totalTaxIncShipping|string_format:"%.2f"}--></span>
				</div>
				<div class="clear"></div>
				<div class="coupon">
					<img src="images/logo_coupon.gif" alt="Radmore & Tucker" align="left" />
					<label for="coupon">Enter Coupon Code</label>
					<input name="coupon" id="coupon" onchange="this.form.submit()" type="text" />
				</div>
				<div class="updatetext">
					After making any changes to the quantity or shipping please use the update button to amend your total<br />
					<input type="image" src="/images/btn_update.gif" alt="update" value="submit" />
				</div>
				<div class="clear"></div>
				<!--{if isset($basket.totalDiscountTaxed) && $basket.totalDiscountTaxed neq '0'}-->
				<div class="total">
					Discount: <span>£<!--{$basket.totalDiscountTaxed|string_format:"%.2f"}--></span>
				</div>
				<div class="clear"></div>
				<!--{/if}-->
				<div class="total">
					Total: <span>£<!--{$basket.totalPriceIncShippingTaxed|string_format:"%.2f"}--></span>
				</div>
				<div class="clear"></div>
				<input type="hidden" name="formAction" value="update"/>
				<a href="/checkout.html" class="btn-continue"><img src="/images/btn_continue.gif" alt="continue" title="Continue To Checkout" /></a>
			</form>

 

The other refreshes work (region and coupon).

 

I think the problem is in the line:

 

<input name="quantity<!--{$smarty.section.c.index}-->" id="<!--{$basket.products[c].prodtitle}-->" value="<!--{$basket.products[c].quantity}-->" maxlength="3" onchange="this.form.submit()" type="text" />

 

this is the basket.php from the html folder:

 

<?php

require_once('../lib/config.php');
require_once(LIBDIR . "app_top.php");
require_once(LIBDIR . "region.php");


$params = processParams();

// get the regions
$region = new region_collection();

$clist = $region->getRegionList();

$smarty->assign("region", $clist);

if (isset($_POST['formAction']) && $_POST['formAction'] == "update") {

updateBasket();

} elseif (isset($_GET['action']) && $_GET['action'] == "delete") {

if (isset($_GET['po']) && is_numeric($_GET['po'])) {

	$basket->edit($_GET['po'], 0);
}
}

if (isset($_POST['region']) && is_numeric($_POST['region'])){
$_SESSION['region'] = intval($_POST['region']);
}

//print_r($basket->output());

if (isset($_SESSION['discountCode'])) {

$message = $basket->coupon($_SESSION['discountCode']);

$smarty->assign('message',$message);

}
//print_r($basket->output());
$smarty->assign('basket', htmlescape($basket->output()));

if(isset($_GET['perror']) && $_GET['perror'] == "1"){

$smarty->assign('message',"There has been a error with the SagePay payment gateway. <br/><br/> Your order has been saved on the system email or phone Radmore and Tucker to proceed with the order.");

}elseif(isset($_GET['perror']) && $_GET['perror'] == "2"){
$smarty->assign('message',"Item/Items in your basket no long have the required quantity, your basket has been updated, plaese check before proceeding with the order.");

}

display('basket.html');

function updateBasket() {

global $smarty, $params, $basket;

for ($i=0;$i<count($_POST);$i++) {

	if (isset($_POST['productOption' . $i]) && is_numeric($_POST['productOption' .$i]) &&
		isset($_POST['quantity' . $i]) && is_numeric($_POST['quantity' . $i])) {

		$backVale = $basket->edit($_POST['productOption' . $i], $_POST['quantity' . $i]);

		if ($backVale !== true){
			$errorsUpdate[] = $backVale;
		}
	}
}

if (isset($_POST['coupon']) && !empty($_POST['coupon'])) {

	$message = $basket->coupon($_POST['coupon']);

	$smarty->assign('message',$message);

}

if(isset($errorsUpdate) && !empty($errorsUpdate)){

	$smarty->assign('errorUpdate',implode("<br />", $errorsUpdate));

}

return;

}

function display($screen) {

global $smarty, $params;

$smarty->assign('backlink', $params['backlink']);

$smarty->display($screen);
exit();

}

function processParams() {

$params = array();

if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], SITEURL) === 0 &&
	strpos($_SERVER['HTTP_REFERER'], "basket") === false && strpos($_SERVER['HTTP_REFERER'], "checkout") === false) {

	$params['backlink'] = "/" . str_replace(SITEURL, "" ,$_SERVER['HTTP_REFERER']);

} elseif (isset($_SESSION['backlink'])) {

	$params['backlink'] = $_SESSION['backlink'];

} else {

	$params['backlink'] = "/index.html";
} 

$params['backlink'] = preg_replace("/\?.*/", "", $params['backlink']);

$_SESSION['backlink'] = $params['backlink'];

return $params;

}

?>

 

Here is a snippet from the basket.php file in the lib folder.I hope I have grabbed the relevant bit (have attached the full file just in case).

 

	/**
* adds product to the basket 
* @params int $option the product option id 
* @params int $quantity the quantity of the products to add
  	*/ 	
function add($product, $option, $quantity) {

	if (!isset($option) || !is_numeric($option)) {

		//trigger_error("No options selected");
		return false;
	}	

	if (!isset($quantity) || !is_numeric($quantity) || $quantity < 1 ) {

		trigger_error("No quantity selected");
		return false;
	}	

	if (!isset($product) || !is_numeric($product) || $product < 1) {

		trigger_error("No product selected");
		return false;
	}	

	/**
	* if the session var doesn't already exist recreate it
	*/
	if (!isset($_SESSION['basket']) || !is_array($_SESSION['basket'])) {

		$_SESSION['basket'] = array();
		$_SESSION['basketinfo'] = array();
	}

	sort($_SESSION['basket']); 

 

Any help the community can give would this would be much appreciated.

17413_.php

Link to comment
Share on other sites

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.