Hi all,

I'm porting the dangling carrot mod from OSC and i'm banging my head against a wall here!

Ive got a section of code that seems to have an error in it because it stops the shopping cart from loading correctly.
It's probably something as simple as a } in the wrong place, or missing entirely, but i've been staring at it for so long that i'm going round in circles now.

Another pair of eyes and a fresh mind will help.


<?php
/**
* Dangling Carrot
* Steve Price 01-10-08
* @package page
* @copyright Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: main_template_vars.php 4629 2006-09-28 15:29:18Z ajeh $
*/

$num_in_cart = $_SESSION['cart']->show_total();
$products = $_SESSION['cart']->get_products();
$gift = $db->Execute("SELECT fg.*, p.products_id, p.products_model, p.products_price, p.products_image, p.products_status, pd.products_name FROM (" . TABLE_CARROT . " fg, products p)
LEFT JOIN products_description pd ON (pd.products_id=fg.products_id)
WHERE pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
AND p.products_id = fg.products_id
ORDER BY fg.threshold ASC");
$threshold = 0;
$p=0;
$gift_price=0;
$gift_exists=0;
while (!$gift->EOF) { // loop through the current gifts

if ($gift_exists == 0){
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if ($products[$i]['id'] == $gift->fields['products_id']) { // gift already in cart
$gift_exists = $gift->fields['products_id'];
$gift_price = $gift->fields['products_price'];
$deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
break;

} else {
$deficit = $gift->fields['threshold'] - $num_in_cart;
}
}
} else {
$deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
}
if ( $deficit < 20 && $deficit > 0 ) {
$near_limit = 1;
} else {
$near_limit = 0;
}
if ($num_in_cart >= $gift->fields['threshold'] && $deficit <= 0) {
// cart could qualify for this gift
// check to see if in cart already
// add to gift list if not in cart
if ($gift->fields['products_id'] != $gift_exists && $deficit <= 0) { // this particular gift is not in cart but qualifies
$freebie[$p]['message'] .= sprintf(TEXT_QUALIFIED_FOR_GIFT, $currencies->display_price($gift->fields['threshold'],zen_get_tax_rate($gift->fields['products_tax_class_id'])));
$freebie[$p]['link'] = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $gift->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"' . $gift->fields['products_id'] ) . '</a>';
$freebie[$p]['name'] = $gift->fields['products_name'];
$freebie[$p]['id'] = $gift->fields['products_id'];
$freebie[$p]['image'] = $gift->fields['products_image'];
$p++;

} else if ($near_limit) {
if ($gift->fields['products_id'] != $gift_exists) { // this particular gift is not in cart
$freebie[$p]['message'] .= sprintf(TEXT_CLOSE_TO_FREE_GIFT, $currencies->display_price($deficit,tep_get_tax_rate($gift['products_tax_class_id'])));
$freebie[$p]['link'] = '';
$freebie[$p]['name'] = $gift->fields['products_name'];
$freebie[$p]['id'] = $gift->fields['products_id'];
$freebie[$p]['image'] = $gift->fields['products_image'];
$p++;
} else {
// cart cannot qualify for this gift
// remove if in cart
$cart->remove($gift->fields['products_id']);
}
// } else {
// cart cannot qualify for this gift
// remove if in cart
// $cart->remove($gift->fields['products_id']);
}
$threshold = $gift->fields['threshold'];
}

$gift->MoveNext();
}

require($template->get_template_dir('tpl_shopping_cart_default.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_shopping_cart_default.php');


?>

Thanks

Steve