Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 1 votes

Get 1 Free


345 replies to this topic

#321 TCDK

  • Community Member
  • 71 posts
  • Real Name:Torben Christoffersen
  • Gender:Male
  • Location:Ribe, Denmark

Posted 14 March 2011, 10:39

View PostTCDK, on 14 March 2011, 10:10, said:

This addon is fantastic!

Hmm, something diden't work right...


What I would have written, was:

Is it possible, that instead of the product is added in the cart, as another product, it will add the free products under the bought product, like it was a product attribute - Or something else.

The problem for me, is that if the customer would like to delete the product in the cart, the customer will have to write "0" in both the bought product, and the free product, to get it out of the cart.

It would be smarter, that if the customer just delete the bought product, it also will remove the free product.

Possible?

#322 lyonsperf

  • Community Member
  • 265 posts
  • Real Name:Matt
  • Gender:Male
  • Location:CT

Posted 05 July 2011, 17:14

I have spent he last two days trying to get this to work. I have the admin side working and the message on the product info page but the free product does not show up in the cart.
I have added the extra get 1 free mods and have been through the forum and the extra changes to this contribution. Can anyone help?
I am using rc2.2a with php 5.
If the only tool you have is a hammer, all your problems look like nails

#323 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 05 July 2011, 17:29

You've made an error in the installation. It's most likely in the shopping cart class file. Check all of your edits carefully by comparing your files to the ones supplied in the Get 1 Free package.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#324 lyonsperf

  • Community Member
  • 265 posts
  • Real Name:Matt
  • Gender:Male
  • Location:CT

Posted 05 July 2011, 19:29

Hi Jim,
Here is my modified class/shopping_cart.php file.
I have used winmerge to compare the two files and checked it with webuilder. No syntax errors found. I also use MVs but you wrote that so it blends fine with Get 1 Free.
Please have a look and let me know what you see. I've tried everything.
<?php
/*
  $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class shoppingCart {
    var $contents, $total, $weight, $cartID, $content_type;

    function shoppingCart() {
      $this->reset();
    }

    function restore_contents() {
      global $customer_id;

      if (!tep_session_is_registered('customer_id')) return false;

// insert current cart contents in database
      if (is_array($this->contents)) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          $qty = $this->contents[$products_id]['qty'];
          $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
          if (!tep_db_num_rows($product_query)) {
            tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
            if (isset($this->contents[$products_id]['attributes'])) {
              reset($this->contents[$products_id]['attributes']);
              while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
              }
            }
          } else {
            tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
          }
        }
      }

// reset per-session cart contents, but not the database contents
      $this->reset(false);

      $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
      while ($products = tep_db_fetch_array($products_query)) {
        $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
// attributes
        $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
        while ($attributes = tep_db_fetch_array($attributes_query)) {
          $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
        }
      }

      $this->cleanup();
    }

    function reset($reset_database = false) {
      global $customer_id;

      $this->contents = array();
      $this->total = 0;
      $this->weight = 0;
      $this->content_type = false;

      if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
      }

      unset($this->cartID);
      if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
    }

    function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
      global $new_products_id_in_cart, $customer_id;

      $products_id_string = tep_get_uprid($products_id, $attributes);
      $products_id = tep_get_prid($products_id_string);

      if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$qty > MAX_QTY_IN_CART)) {
        $qty = MAX_QTY_IN_CART;
      }

      $attributes_pass_check = true;

      if (is_array($attributes)) {
        reset($attributes);
        while (list($option, $value) = each($attributes)) {
          if (!is_numeric($option) || !is_numeric($value)) {
            $attributes_pass_check = false;
            break;
          }
        }
      }

      if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {
        $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        $check_product = tep_db_fetch_array($check_product_query);

        if (($check_product !== false) && ($check_product['products_status'] == '1')) {
          if ($notify == true) {
            $new_products_id_in_cart = $products_id;
            tep_session_register('new_products_id_in_cart');
          }

          if ($this->in_cart($products_id_string)) {
            $this->update_quantity($products_id_string, $qty, $attributes);
          } else {
            $this->contents[$products_id_string] = array('qty' => (int)$qty);
// insert into database
            if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");

            if (is_array($attributes)) {
              reset($attributes);
              while (list($option, $value) = each($attributes)) {
                $this->contents[$products_id_string]['attributes'][$option] = $value;
// insert into database
                if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$option . "', '" . (int)$value . "')");
              }
            }
          }

          $this->cleanup();

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
          $this->cartID = $this->generate_cart_id();
        }
      }
    }

    function update_quantity($products_id, $quantity = '', $attributes = '') {
      global $customer_id;

      $products_id_string = tep_get_uprid($products_id, $attributes);
      $products_id = tep_get_prid($products_id_string);

      if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$quantity > MAX_QTY_IN_CART)) {
        $quantity = MAX_QTY_IN_CART;
      }

      $attributes_pass_check = true;

      if (is_array($attributes)) {
        reset($attributes);
        while (list($option, $value) = each($attributes)) {
          if (!is_numeric($option) || !is_numeric($value)) {
            $attributes_pass_check = false;
            break;
          }
        }
      }

      if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {
        $this->contents[$products_id_string] = array('qty' => (int)$quantity);
// update database
        if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");

        if (is_array($attributes)) {
          reset($attributes);
          while (list($option, $value) = each($attributes)) {
            $this->contents[$products_id_string]['attributes'][$option] = $value;
// update database
            if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'");
          }
        }
      }
    }

    function cleanup() {
      global $customer_id;

      reset($this->contents);
      while (list($key,) = each($this->contents)) {
        if ($this->contents[$key]['qty'] < 1) {
          unset($this->contents[$key]);
// remove from database
          if (tep_session_is_registered('customer_id')) {
            tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
            tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
          }
        }
      }
    }

    function count_contents() {  // get total number of items in cart 
      $total_items = 0;
      if (is_array($this->contents)) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          $total_items += $this->get_quantity($products_id);
// Get 1 free
          // If this product qualifies for free product(s) add in the number of free products
          if (is_array ($free_product = $this->get1free ($products_id))) {
            $total_items += $free_product['quantity'];
          }
// end Get 1 free
        }
      }

      return $total_items;
    }

    function get_quantity($products_id) {
      if (isset($this->contents[$products_id])) {
        return $this->contents[$products_id]['qty'];
      } else {
        return 0;
      }
    }

    function in_cart($products_id) {
      if (isset($this->contents[$products_id])) {
        return true;
      } else {
        return false;
      }
    }

    function remove($products_id) {
      global $customer_id;

      unset($this->contents[$products_id]);
// remove from database
      if (tep_session_is_registered('customer_id')) {
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
        tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
      }

// Get 1 free
          // If this product qualifies for free product(s) remove the free products
          if (is_array ($free_product = $this->get1free ($products_id))) {
            $pid = (int)$free_product['id'];
            unset($this->contents[$pid]);
            // remove from database
            if (tep_session_is_registered('customer_id')) {
              tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($pid) . "'");
              tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($pid) . "'");
            }
          }
// end Get 1 free

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
      $this->cartID = $this->generate_cart_id();
      return $debug;
    }

    function remove_all() {
      $this->reset();
    }

    function get_product_id_list() {
      $product_id_list = '';
      if (is_array($this->contents)) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          $product_id_list .= ', ' . $products_id;
        }
      }

      return substr($product_id_list, 2);
    }

    function calculate() {
      global $currencies;

      $this->total = 0;
      $this->weight = 0;
      if (!is_array($this->contents)) return 0;

      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $qty = $this->contents[$products_id]['qty'];

// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        if ($product = tep_db_fetch_array($product_query)) {
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
          $this->weight += ($qty * $products_weight);

// Get 1 free
          // If this product qualifies for free product(s) add in the total weight of free products
          if (is_array ($free_product = $this->get1free ($products_id))) {
            $this->weight += $free_product['quantity'] * $free_product['weight'];
          }
// end Get 1 free
        }

// attributes price
        if (isset($this->contents[$products_id]['attributes'])) {
          reset($this->contents[$products_id]['attributes']);
          while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
            $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
            $attribute_price = tep_db_fetch_array($attribute_price_query);
            if ($attribute_price['price_prefix'] == '+') {
              $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
            } else {
              $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
            }
          }
        }
      }
    }


//////
//MVS Start
//  New method to provide cost, weight, quantity, and product IDs by vendor
//////
//Output array structure (example):
//shoppingcart Object
//(
//  [vendor_shipping] => array
//    (
//      [0] => array   //Number is the vendor_id
//        (
//          [weight] => 22.59
//          [cost] => 12.95
//          [qty] => 2
//          [products_id] => array
//            (
//              [0] => 12
//              [1] => 47
//            )
//        )
//      [12] => array
//        (
//          [weight] => 32.74
//          [cost] => 109.59
//          [qty] => 5
//          [products_id] => array
//            (
//              [0] => 2
//              [1] => 3
//              [2] => 37
//              [3] => 49
//            )
//        )
//    )
//)
    function vendor_shipping() {

      if (!is_array($this->contents)) return 0;  //Cart is empty

      $this->vendor_shipping = array();  //Initialize the output array
      reset($this->contents);            //  and reset the input array
      foreach ($this->contents as $products_id => $value) {  //$value is never used
        $quantity = $this->contents[$products_id]['qty'];

//mod IndvShip, added products_ship_price
        $products_query = tep_db_query("select products_id,
                                               products_price,
											   products_ship_price,
                                               products_tax_class_id,
                                               products_weight,
                                               vendors_id
                                        from " . TABLE_PRODUCTS . "
                                        where products_id = '" . (int)$products_id . "'"
                                      );
        if ($products = tep_db_fetch_array($products_query)) {
          $products_price = $products['products_price'];
//mod IndvShip
		  $products_ship_price = $products['products_ship_price'];
          $products_weight = $products['products_weight'];
          $vendors_id = ($products['vendors_id'] <= 0) ? 1 : $products['vendors_id'];
          $products_tax = tep_get_tax_rate($products['products_tax_class_id']);

          //Find special prices (if any)
          $specials_query = tep_db_query("select specials_new_products_price
                                          from " . TABLE_SPECIALS . "
                                          where products_id = '" . (int)$products_id . "'
                                            and status = '1'"
                                        );
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          //Add values to the output array
          $this->vendor_shipping[$vendors_id]['weight'] += ($quantity * $products_weight);
          $this->vendor_shipping[$vendors_id]['cost'] += tep_add_tax($products_price, $products_tax) * $quantity;
          $this->vendor_shipping[$vendors_id]['qty'] += $quantity;
//mod IndvShip
		  $this->vendor_shipping[$vendors_id]['ship_cost'] += ($quantity * $products_ship_price);		  		  
          $this->vendor_shipping[$vendors_id]['products_id'][] = $products_id; //There can be more than one product
        }

        // Add/subtract attributes prices (if any)
        if (isset($this->contents[$products_id]['attributes'])) {
          reset($this->contents[$products_id]['attributes']);
          foreach ($this->contents[$products_id]['attributes'] as $option => $value) {
            $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
            $attribute_price = tep_db_fetch_array($attribute_price_query);
            if ($attribute_price['price_prefix'] == '+') {
              $this->vendor_shipping[$vendors_id]['cost'] += $quantity * tep_add_tax($attribute_price['options_values_price'], $products_tax);
            } else {
              $this->vendor_shipping[$vendors_id]['cost'] -= $quantity * tep_add_tax($attribute_price['options_values_price'], $products_tax);
            }
          }
        }
      }

      return $this->vendor_shipping;
    }
//MVS End

    function attributes_price($products_id) {
      $attributes_price = 0;

      if (isset($this->contents[$products_id]['attributes'])) {
        reset($this->contents[$products_id]['attributes']);
        while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
          $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
          $attribute_price = tep_db_fetch_array($attribute_price_query);
          if ($attribute_price['price_prefix'] == '+') {
            $attributes_price += $attribute_price['options_values_price'];
          } else {
            $attributes_price -= $attribute_price['options_values_price'];
          }
        }
      }

      return $attributes_price;
    }

//MVS - added function to only retrieve specific vendors products
    function get_vendors_products($vendor) {
      global $languages_id;

      if (!is_array($this->contents)) return false;

      $products_array = array();
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_tax_class_id, v.vendors_id, v.vendors_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_VENDORS . " v where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and v.vendors_id = '" . $vendor . "' and p.vendors_id = '" . $vendor . "' and pd.language_id = '" . (int)$languages_id . "'");
        //upsxml dimensions end
        //MVS end
        if ($products = tep_db_fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $products_array[] = array('id' => $products_id,
                                    'name' => $products['products_name'],
                                    'qproduct' => '', 
                                    'model' => $products['products_model'],
                                    'image' => $products['products_image'],
                                    'price' => $products_price,
                                    'quantity' => $this->contents[$products_id]['qty'],
                                    'weight' => $products['products_weight'],
//upsxml dimensions start
                                    'length' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_length']),
          			                    'width' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_width']),
          			                    'height' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_height']),
          			                    'ready_to_ship' => $products['products_ready_to_ship'],
//upsxml dimensions end
                                    'final_price' => ($products_price + $this->attributes_price($products_id)),
                                    'tax_class_id' => $products['products_tax_class_id'],
                                    //MVS start
                                    'vendors_id' => $products['vendors_id'],
                                    'vendors_name' => $products['vendors_name'],
                                    //MVS end
                                    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
// Get 1 free
 if (is_array ($free_product = $this->get1free ($products_id))) {
                // Add the free product to the shopping cart (Customer cannot alter this)
                $products_array[] = array('id' => $free_product['id'],
                                      'name' => $free_product['name'],
					  'qproduct' => '<br><span class="stockWarning">Free with <b>' . $products['products_name'] . '</b> purchase</span>', 
                                      'model' => $free_product['model'],
                                      'image' => $free_product['image'],
                                      'price' => 0,
                                      'quantity' => $free_product['quantity'],
                                      'weight' => $free_product['weight'],
                                      'final_price' => 0,
                                      'tax_class_id' => $products['products_tax_class_id'],
                                      'attributes' => '',
                                      'free' => 1
                                     );
          } //if (is_array
// end Get 1 free
        }
      }

      return $products_array;
    }
//MVS - upsxml end
    
    function get_products() {
      global $languages_id;

      if (!is_array($this->contents)) return false;

      $products_array = array();
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
//MVS
//upsxml dimensions - added  p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, 
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_tax_class_id, v.vendors_id, v.vendors_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_VENDORS . " v where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and v.vendors_id = p.vendors_id and pd.language_id = '" . (int)$languages_id . "'");
        if ($products = tep_db_fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $products_array[] = array('id' => $products_id,
                                    'name' => $products['products_name'],
                                    'model' => $products['products_model'],
                                    'image' => $products['products_image'],
                                    'price' => $products_price,
                                    'quantity' => $this->contents[$products_id]['qty'],
                                    'weight' => $products['products_weight'],
//upsxml dimensions start
                                    'length' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_length']),
          			                    'width' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_width']),
          			                    'height' => ($products['product_free_shipping'] == '1' ? 0 : $products['products_height']),
//uspxml dimensions end
                                    'ready_to_ship' => $products['products_ready_to_ship'],
                                    'final_price' => ($products_price + $this->attributes_price($products_id)),
                                    'tax_class_id' => $products['products_tax_class_id'],
//MVS start
                                    'vendors_id' => $products['vendors_id'],
                                    'vendors_name' => $products['vendors_name'],
//MVS end
                                    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
        }
      }

      return $products_array;
    }

    function show_total() {
      $this->calculate();

      return $this->total;
    }

    function show_weight() {
      $this->calculate();

      return $this->weight;
    }

    function generate_cart_id($length = 5) {
      return tep_create_random_value($length, 'digits');
    }

    function get_content_type() {
      $this->content_type = false;

      if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          if (isset($this->contents[$products_id]['attributes'])) {
            reset($this->contents[$products_id]['attributes']);
            while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
              $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
              $virtual_check = tep_db_fetch_array($virtual_check_query);

              if ($virtual_check['total'] > 0) {
                switch ($this->content_type) {
                  case 'physical':
                    $this->content_type = 'mixed';

                    return $this->content_type;
                    break;
                  default:
                    $this->content_type = 'virtual';
                    break;
                }
              } else {
                switch ($this->content_type) {
                  case 'virtual':
                    $this->content_type = 'mixed';

                    return $this->content_type;
                    break;
                  default:
                    $this->content_type = 'physical';
                    break;
                }
              }
            }
          } else {
            switch ($this->content_type) {
              case 'virtual':
                $this->content_type = 'mixed';

                return $this->content_type;
                break;
              default:
                $this->content_type = 'physical';
                break;
            }
          }
        }
      } else {
        $this->content_type = 'physical';
      }

      return $this->content_type;
    }

    function unserialize($broken) {
      for(reset($broken);$kv=each($broken);) {
        $key=$kv['key'];
        if (gettype($this->$key)!="user function")
        $this->$key=$kv['value'];
      }
    }
// start Get 1 Free
    function get1free ($products_id) {
      global $languages_id;
      $get_1_free_query = tep_db_query("select products_free_id, products_free_quantity, products_qualify_quantity, products_multiple, get_1_free_expires_date from " . TABLE_GET_1_FREE . " where products_id = '" . (int)$products_id . "' and status = '1'");
      if (tep_db_num_rows($get_1_free_query) > 0) {
        $get_1_free = tep_db_fetch_array($get_1_free_query);
        //Check that the offer has not expired
         //MNK bugfix 13.08.2007
        if (($get_1_free['get_1_free_expires_date'] <= date('Y-m-d H:i:s')) && ($get_1_free['get_1_free_expires_date'] != '0000-00-00 00:00:00')) {
          //offer has expired, so update the database and return false
          tep_db_query("update " . TABLE_GET_1_FREE . " set status = '0', date_status_change = now() where products_id = '" . (int)$products_id . "'");
          return false;
        } else {
          // Offer is valid, so check if the quantity qualifies
          $products_quantity = $this->contents[$products_id]['qty'];
          if ($products_quantity >= $get_1_free['products_qualify_quantity']) {
            // Qualifies, so get the quantity of free products
            $free_quantity = 1;
            if ($get_1_free['products_multiple'] > 1) {
           //BOF fischo bugfix 10.04.2009
              //$free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']);
              $free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']) * $get_1_free['products_free_quantity'];
           //EOF fischo bugfix 10.04.2009
              if ($free_quantity > $get_1_free['products_multiple']) {
                $free_quantity = $get_1_free['products_multiple'];
              }
            }
            // Get the info on the free product
            $products_free_query = tep_db_query("select pd.products_name, p.products_model,p.products_image,p.products_weight from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$get_1_free['products_free_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
            $products_free = tep_db_fetch_array($products_free_query);
            // Return an array of free product values
            $output = array ( 'id' => $get_1_free['products_free_id'],
                              'quantity' => $free_quantity,
                              'name' => $products_free['products_name'],
                              'model' => $products_free['products_model'],
                              'image' => $products_free['products_image'],
                              'weight' => $products_free['products_weight']);
            return $output;
          } //if ($products_quantity
        } //else
      }//if (tep_db_num_rows
      // offer was not valid (disabled or expired)
      return false;
    }//function
// end Get 1 Free

  
// get_products_for_packaging is a special function for split product support in the class packing
// assumes that you have added the sql for upsxml, which adds the table products_split
   function get_products_for_packaging() {
      if (!is_array($this->contents)) return false;
      $products_array = array();
      // get the list of product information
      $products = $this->get_products();
      // cycle through list
      foreach ($products as $product) {
        $split_query = tep_db_query("select * from " . TABLE_PRODUCTS_SPLIT . " where products_id = " . (int)$product['id']);
        // is this a split product?
        if (tep_db_num_rows($split_query) > 0) {
          // save the total prices of the split product
          $product_price = $product['price'];
          $product_final_price = $product['final_price'];
          while ($split_info = tep_db_fetch_array($split_query)) {
            // for each piece of the product replace only the information that is unique to the piece
            // other information from the product will remain unchanged
            $product['weight'] = $split_info['products_weight'];
            $product['length'] = $split_info['products_length'];
            $product['width'] = $split_info['products_width'];
            $product['height'] = $split_info['products_height'];
            $product['ready_to_ship'] = $split_info['products_ready_to_ship'];
            $product['price'] = round(($split_info['value_fraction'] * $product_price), 4);
            $product['final_price'] = round(($split_info['value_fraction'] * $product_final_price), 4);
            // save the updated product piece
            $products_array[] = $product;
          } // end while
        } else {
          // not a split product, save it directly
          $products_array[] = $product;
        }
      } // end foreach

      return $products_array;
   }

  }
?>

If the only tool you have is a hammer, all your problems look like nails

#325 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 05 July 2011, 21:38

I don't see anything there. Either I missed it or the error is somewhere else.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#326 lyonsperf

  • Community Member
  • 265 posts
  • Real Name:Matt
  • Gender:Male
  • Location:CT

Posted 06 July 2011, 11:58

Well i'm stumped. I re checked everything and its all there. I did notice that the mods txt file has changes in product_info.php with g1f. db callouts. The sql file does not have these. Could this be the issue?
If the only tool you have is a hammer, all your problems look like nails

#327 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 06 July 2011, 15:18

The product_info.php does call TABLE_GET_1_FREE. That has to be properly defined, and the get_1_free table has to exist. Otherwise I don't know what you mean.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#328 saupe31

  • Community Member
  • 52 posts
  • Real Name:carl

Posted 05 August 2011, 22:13

i have installed this mod but when i go to the admin panel catalog and clcik on get 1 free all i get is a white screen, dont worry i uploaded one of the files wrong

Edited by saupe31, 05 August 2011, 22:20.


#329 saupe31

  • Community Member
  • 52 posts
  • Real Name:carl

Posted 05 August 2011, 23:03

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '// added for Get 1 Free mod g1f.products_free_quantity, ' at line 2

select pd.products_name, pd.products_id, // added for Get 1 Free mod g1f.products_free_quantity, g1f.products_qualify_quantity from get_1_free g1f, products_description pd where g1f.products_id = '238' and pd.products_id = g1f. products_free_id and pd.language_id = '1' and status = '1'
im getting this error on my product pages

#330 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 05 August 2011, 23:34

Remove this from the middle of the SQL string:
// added for Get 1 Free mod

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#331 saupe31

  • Community Member
  • 52 posts
  • Real Name:carl

Posted 06 August 2011, 10:16

View Poststeve_s, on 16 April 2009, 21:53, said:

create a new infobox in includes/boxes/get_1_free.php say now create a template for get_1_free.php you will also need to add this in the includes/modules/sts_inc/sts_column_left.php
in your new box paste the following code
<?php
/*
  $Id: get_1_free.php 1739 2007-12-20 00:52:16Z hpdl $

  Copyright (c) 2003 osCommerce, http://www.oscommerce.com

  Released under the GNU General Public License
*/
//random if more than one free product
	$get_1_free_query = tep_db_query("select products_id 
									  from " . TABLE_GET_1_FREE . " order by rand() limit 0,12");

if (tep_db_num_rows($get_1_free_query) > 0) {
	 $free_product = tep_db_fetch_array($get_1_free_query);

   $product_info_query = tep_db_query("select p.products_id, pd.products_name,  p.products_image, pd.products_url, p.products_price, p.products_tax_class_id  from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$free_product['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
	$product = tep_db_fetch_array($product_info_query);
?>
<!-- get_1_free //-->
		  <tr>
			<td>
<?php
	$info_box_contents = array();
	$info_box_contents[] = array('text' => 'Get 1 Free');

	new infoBoxHeading($info_box_contents, false, false);

	$info_box_contents = array();
	$info_box_contents[] = array('align' => 'center',
								 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $product['products_image'], $product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product['products_id']) . '">' . $random_product['products_name'] . '</a><br><s>' . $currencies->display_price($product['products_price'], tep_get_tax_rate($product['products_tax_class_id']));

	new infoBox($info_box_contents);
?>
			</td>
		  </tr>
<!-- get_1_free_eof //-->
<?php
  }
?>
I havent been able to test it but it should work ok
how would i go about making the box so it has a arrow like the reviews box where you click on it and it opens up a new page and it will show all get1 frees there

#332 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 06 August 2011, 17:32

Replace this line:
        new infoBoxHeading($info_box_contents, false, false);
with this:
        new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_GET_1_FREE));
Replace FILENAME_GET_1_FREE with whatever you defined your new filename to be, or just define that. Then create that page (similar to reviews.php) and collect the product IDs from the get_1_free database table.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#333 saupe31

  • Community Member
  • 52 posts
  • Real Name:carl

Posted 06 August 2011, 21:38

sorry to be a pain any chance you can give me some examples or more fuller instructions im still learning all this atm

#334 ckpepper02

  • Community Member
  • 27 posts
  • Real Name:Chris
  • Gender:Male
  • Location:USA

Posted 09 August 2011, 14:25

Instead of Get One Free, is there a way to buy one get one at $x price?

#335 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 09 August 2011, 17:31

Probably, but not with this code. You might be able to modify it to do that if you want the "free" products to sell at a single fixed price.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#336 ckpepper02

  • Community Member
  • 27 posts
  • Real Name:Chris
  • Gender:Male
  • Location:USA

Posted 09 August 2011, 19:27

Ok thank you, I'll give it a try. My package seems to be missing catalog/admin/includes/functions/get_1_free.php, can you tell me where to download it again?

#337 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 09 August 2011, 19:59

There's no such file in Version 1.3, which is the latest one I support. You're on your own with any of the "later" versions.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support

#338 ckpepper02

  • Community Member
  • 27 posts
  • Real Name:Chris
  • Gender:Male
  • Location:USA

Posted 10 August 2011, 17:00

View Postkymation, on 09 August 2011, 19:59, said:

There's no such file in Version 1.3, which is the latest one I support. You're on your own with any of the "later" versions.

Regards
Jim

Ok, thanks. I just downloaded 1.3 and I'm attempting to modify catalog/admin/includes/boxes/catalog.php but it looks like the structure is different than specified in the installation instructions. The install.txt says to look for this:

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>';

But that is not found, I only have this:

array(
        'code' => FILENAME_PRODUCTS_EXPECTED,
        'title' => BOX_CATALOG_PRODUCTS_EXPECTED,
        'link' => tep_href_link(FILENAME_PRODUCTS_EXPECTED)
      )

Any suggestions? Could I simply skip this step?

Edited by ckpepper02, 10 August 2011, 17:01.


#339 ckpepper02

  • Community Member
  • 27 posts
  • Real Name:Chris
  • Gender:Male
  • Location:USA

Posted 10 August 2011, 17:32

I think I figured it out.

array(
        'code' => FILENAME_GET_1_FREE,
        'title' => BOX_CATALOG_GET_1_FREE,
        'link' => tep_href_link(FILENAME_GET_1_FREE)
      )


#340 kymation

  • Community Sponsor
  • 5,658 posts
  • Real Name:Jim Keebaugh
  • Gender:Male
  • Location:Aberdeen WA USA

Posted 10 August 2011, 17:35

The instructions are for osC version 2.2x. You'll need to convert to 2.3.1.

Regards
Jim
My Addons

Banners Box 2.3.1 Support
Categories Accordion Box 2.3.1 Support
Categories Images Box 2.2x 2.3.1 Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box 2.3.1 Support
Get 1 Free 2.2x Support
Include HTML and Text Boxes 2.2x
jQuery Banner Rotator 2.2x 2.3.1 Support
Modular Front Page 2.3.1 Support
Modular SEO Header Tags 2.3.1 Support
More Pics 2.2x Support
MVS 2.2x Support
osC Catalog 2.2x Support
PDF Datasheet 2.3.1 Support
Price Updater 2.2x
Products Specifications 2.2x 2.3.1 Development Version Support Bugs/Suggestions
Request a Review 2.2x - 2.3.1 Support
Similar Products Box 2.2x
Theme Switcher 2.3.1 Support