Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Check this code please..error somewhere

    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

  2. #2
    Join Date
    Nov 2005
    Location
    France
    Posts
    600
    Plugin Contributions
    8

    Default Re: Check this code please..error somewhere

    Noticed a commented out section in the above code that shouldn't be:

    } 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'];
    }

    should read:

    } 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'];
    }

 

 

Similar Threads

  1. Zip Code Error Check?
    By powrwrap in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 1 Apr 2011, 12:33 AM
  2. Adding an example on the New Account Console - please check my code
    By starksark in forum Managing Customers and Orders
    Replies: 4
    Last Post: 7 May 2010, 07:04 PM
  3. Please check that your Zip Code is entered correctly...
    By ksolito in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 17 Nov 2009, 12:18 AM
  4. Can someone please check this code!
    By Vood in forum General Questions
    Replies: 4
    Last Post: 3 Nov 2007, 02:04 AM
  5. Please Help, Error in code somewhere
    By stumped in forum General Questions
    Replies: 4
    Last Post: 5 Aug 2006, 11:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg