Jump to content
scendent

Seperate Pricing Per Customer v3.5

Recommended Posts

this is the code without hide products portion causing error but puts 2 of each item in shopping cart.

 

<?php
/*
 $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $
 adapted for Separate Pricing Per Customer v4.2 2008/03/07

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 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, $languages_id; // languages_id needed for PriceFormatter - QPBPP

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

// insert current cart contents in database
  if (is_array($this->contents)) {
	reset($this->contents);
// BOF SPPC attribute hide/invalid check: loop through the shopping cart and check the attributes if they
// are hidden for the now logged-in customer
  $this->cg_id = $this->get_customer_group_id();
	while (list($products_id, ) = each($this->contents)) {
				// only check attributes if they are set for the product in the cart
			   if (isset($this->contents[$products_id]['attributes'])) {
			$check_attributes_query = tep_db_query("select options_id, options_values_id, IF(find_in_set('" . $this->cg_id . "', attributes_hide_from_groups) = 0, '0', '1') as hide_attr_status from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . tep_get_prid($products_id) . "'");
			while ($_check_attributes = tep_db_fetch_array($check_attributes_query)) {
				$check_attributes[] = $_check_attributes;
			} // end while ($_check_attributes = tep_db_fetch_array($check_attributes_query))
			$no_of_check_attributes = count($check_attributes);
			$change_products_id = '0';

			foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value) {
				$valid_option = '0';
				for ($x = 0; $x < $no_of_check_attributes; $x++) {
					if ($attr_option == $check_attributes[$x]['options_id'] && $attr_option_value == $check_attributes[$x]['options_values_id']) {
						$valid_option = '1';
						if ($check_attributes[$x]['hide_attr_status'] == '1') {
						// delete hidden attributes from array attributes, change products_id accordingly later
						$change_products_id = '1';
						unset($this->contents[$products_id]['attributes'][$attr_option]);
						}
					} // end if ($attr_option == $check_attributes[$x]['options_id']....
				} // end for ($x = 0; $x < $no_of_check_attributes; $x++)
				if ($valid_option == '0') {
					// after having gone through the options for this product and not having found a matching one
					// we can conclude that apparently this is not a valid option for this product so remove it
					unset($this->contents[$products_id]['attributes'][$attr_option]);
					// change products_id accordingly later
					$change_products_id = '1';
				}
			} // end foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value)

	  if ($change_products_id == '1') {
		   $original_products_id = $products_id;
		   $products_id = tep_get_prid($original_products_id);
		   $products_id = tep_get_uprid($products_id, $this->contents[$original_products_id]['attributes']);
					 // add the product without the hidden attributes to the cart
		   $this->contents[$products_id] = $this->contents[$original_products_id];
				 // delete the originally added product with the hidden attributes
		   unset($this->contents[$original_products_id]);
		}
			  } // end if (isset($this->contents[$products_id]['attributes']))
			} // end while (list($products_id, ) = each($this->contents))
   reset($this->contents); // reset the array otherwise the cart will be emptied
// EOF SPPC attribute hide/invalid check
	while (list($products_id, ) = each($this->contents)) {
	  $qty = $this->contents[$products_id]['qty'];
// BOF QPBPP for SPPC adjust quantity blocks and min_order_qty for this customer group
// warnings about this are raised in PriceFormatter
  $pf = new PriceFormatter;
  $pf->loadProduct(tep_get_prid($products_id), $languages_id);
  $qty = $pf->adjustQty($qty);
// EOF QPBPP for SPPC
	  $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);


// BOF QPBPP for SPPC
  $products_query = tep_db_query("select cb.products_id, ptdc.discount_categories_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " cb left join (select products_id, discount_categories_id from " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . " where customers_group_id = '" . $this->cg_id . "') as ptdc on cb.products_id = ptdc.products_id where customers_id = '" . (int)$customer_id . "'");
// BOF SPPC Hide products and categories from groups
//		  $no_of_products_in_basket = 0;
  while ($products = tep_db_fetch_array($products_query)) {
	$this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity'], 'discount_categories_id' => $products['discount_categories_id']);
// EOF QPBPP for SPPC
// 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;
// BOF Separate Pricing Per Customer 
  $this->cg_id = $this->get_customer_group_id();
// EOF Separate Pricing Per Customer

  $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;
  }
// BOF QPBPP for SPPC
  $pf = new PriceFormatter;
  $pf->loadProduct($products_id);
  $qty = $pf->adjustQty($qty);
  $discount_category = $pf->get_discount_category();
// EOF QPBPP for SPPC

  $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)) {
// BOF SPPC attribute hide check, original query expanded to include attributes
			$check_product_query = tep_db_query("select p.products_status, options_id, options_values_id, IF(find_in_set('" . $this->cg_id . "', attributes_hide_from_groups) = 0, '0', '1') as hide_attr_status from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_ATTRIBUTES . " using(products_id) where p.products_id = '" . (int)$products_id . "'");
			while ($_check_product = tep_db_fetch_array($check_product_query)) {
				$check_product[] = $_check_product;
			} // end while ($_check_product = tep_db_fetch_array($check_product_query))
			$no_of_check_product = count($check_product);

 if (is_array($attributes)) {
			foreach($attributes as $attr_option => $attr_option_value) {
				$valid_option = '0';
				for ($x = 0; $x < $no_of_check_product; $x++) {
					if ($attr_option == $check_product[$x]['options_id'] && $attr_option_value == $check_product[$x]['options_values_id']) {
						$valid_option = '1';
						if ($check_product[$x]['hide_attr_status'] == '1') {
						// delete hidden attributes from array attributes
						unset($attributes[$attr_option]);
						}
					} // end if ($attr_option == $check_product[$x]['options_id']....
				} // end for ($x = 0; $x < $no_of_check_product; $x++)
				if ($valid_option == '0') {
					// after having gone through the options for this product and not having found a matching one
					// we can conclude that apparently this is not a valid option for this product so remove it
					unset($attributes[$attr_option]);
				}
			} // end foreach($attributes as $attr_option => $attr_option_value)
} // end if (is_array($attributes))
// now attributes have been checked and hidden and invalid ones deleted make the $products_id_string again
			$products_id_string = tep_get_uprid($products_id, $attributes);

	if ((isset($check_product) && tep_not_null($check_product)) && ($check_product[0]['products_status'] == '1')) {
// EOF SPPC attribute hide check
	  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, $discount_category);
	  } else {
$this->contents[$products_id_string] = array('qty' => (int)$qty, 'discount_categories_id' => $discount_category);
// EOF QPBPP for SPPC
// 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 = '', $discount_categories_id = NULL) {
// EOF QPBPP for SPPC
  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, 'discount_categories_id' => $discount_categories_id);
// EOF QPBPP for SPPC
// 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);
	}
  }

  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) . "'");
  }

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

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, $languages_id, $pfs; // for QPBPP added: $languages_id, $pfs

  $this->total = 0;
  $this->weight = 0;
  if (!is_array($this->contents)) return 0;
// BOF Separate Pricing Per Customer
// global variable (session) $sppc_customer_group_id -> class variable cg_id
  $this->cg_id = $this->get_customer_group_id();
// EOF Separate Pricing Per Customer

// BOF QPBPP for SPPC
	$discount_category_quantity = array(); // calculates no of items per discount category in shopping basket
  foreach ($this->contents as $products_id => $contents_array) {
	  if(tep_not_null($contents_array['discount_categories_id'])) {
		if (!isset($discount_category_quantity[$contents_array['discount_categories_id']])) {
			$discount_category_quantity[$contents_array['discount_categories_id']] = $contents_array['qty'];
		} else {
			$discount_category_quantity[$contents_array['discount_categories_id']] += $contents_array['qty'];
		}
	  }
  } // end foreach

  $pf = new PriceFormatter;
// EOF QPBPP for SPPC
  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
	$qty = $this->contents[$products_id]['qty'];

// BOF QPBPP for SPPC	   
  if (tep_not_null($this->contents[$products_id]['discount_categories_id'])) {
	$nof_items_in_cart_same_cat = $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
	$nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $qty;
  } else {
	  $nof_other_items_in_cart_same_cat = 0;
  }
// EOF QPBPP for SPPC

// products price

  $pf->loadProduct($products_id, $languages_id);
	if ($product = $pfs->getPriceFormatterData($products_id)) {
	  $prid = $product['products_id'];
	  $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
	  $products_price = $pf->computePrice($qty, $nof_other_items_in_cart_same_cat);
// EOF QPBPP for SPPC
	  $products_weight = $product['products_weight'];

// BOF Separate Pricing Per Customer
/*   $specials_price = tep_get_products_special_price((int)$prid);
  if (tep_not_null($specials_price)) {
 $products_price = $specials_price;
  } elseif ($this->cg_id != 0){
	$customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
	if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
	$products_price = $customer_group_price['customers_group_price'];
	}
	  } */
// EOF Separate Pricing Per Customer

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

// attributes price
// BOF SPPC attributes mod
	if (isset($this->contents[$products_id]['attributes'])) {
	  reset($this->contents[$products_id]['attributes']);
   $where = " AND ((";
	  while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
	 $where .= "options_id = '" . (int)$option . "' AND options_values_id = '" . (int)$value . "') OR (";
	  }
   $where=substr($where, 0, -5) . ')';

   $attribute_price_query = tep_db_query("SELECT products_attributes_id, options_values_price, price_prefix FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = '" . (int)$products_id . "'" . $where ."");

   if (tep_db_num_rows($attribute_price_query)) { 
	   $list_of_prdcts_attributes_id = '';
			 // empty array $attribute_price
			 $attribute_price = array();
	   while ($attributes_price_array = tep_db_fetch_array($attribute_price_query)) { 
	   $attribute_price[] =  $attributes_price_array;
	   $list_of_prdcts_attributes_id .= $attributes_price_array['products_attributes_id'].",";
		}
	   if (tep_not_null($list_of_prdcts_attributes_id) && $this->cg_id != '0') { 
	 $select_list_of_prdcts_attributes_ids = "(" . substr($list_of_prdcts_attributes_id, 0 , -1) . ")";
 $pag_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES_GROUPS . " where products_attributes_id IN " . $select_list_of_prdcts_attributes_ids . " AND customers_group_id = '" . $this->cg_id . "'");
 while ($pag_array = tep_db_fetch_array($pag_query)) {
	 $cg_attr_prices[] = $pag_array;
 }

 // substitute options_values_price and prefix for those for the customer group (if available)
 if ($customer_group_id != '0' && tep_not_null($cg_attr_prices)) {
	for ($n = 0; $n < count($attribute_price); $n++) {
	 for ($i = 0; $i < count($cg_attr_prices); $i++) {
		 if ($cg_attr_prices[$i]['products_attributes_id'] == $attribute_price[$n]['products_attributes_id']) {
			$attribute_price[$n]['price_prefix'] = $cg_attr_prices[$i]['price_prefix'];
			$attribute_price[$n]['options_values_price'] = $cg_attr_prices[$i]['options_values_price'];
		 }
	 } // end for ($i = 0; $i < count($cg_att_prices); $i++)
	  }
	} // end if ($customer_group_id != '0' && (tep_not_null($cg_attr_prices))
  } // end if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0')
// now loop through array $attribute_price to add up/substract attribute prices

  for ($n = 0; $n < count($attribute_price); $n++) {
		if ($attribute_price[$n]['price_prefix'] == '+') {
		  $this->total += $currencies->calculate_price($attribute_price[$n]['options_values_price'], $products_tax, $qty);
		} else {
		  $this->total -= $currencies->calculate_price($attribute_price[$n]['options_values_price'], $products_tax, $qty);
	}
  } // end for ($n = 0; $n < count($attribute_price); $n++)
	  } // end if (tep_db_num_rows($attribute_price_query))
	} // end if (isset($this->contents[$products_id]['attributes'])) 
  }
}
// EOF SPPC attributes mod

// function attributes_price changed partially according to FalseDawn's post
// [url="http://forums.oscommerce.com/index.php?showtopic=139587"]http://forums.oscommerce.com/index.php?showtopic=139587[/url]
// changed completely for Separate Pricing Per Customer, attributes mod
function attributes_price($products_id) {
// global variable (session) $sppc_customer_group_id -> class variable cg_id
$this->cg_id = $this->get_customer_group_id();

  if (isset($this->contents[$products_id]['attributes'])) {
	reset($this->contents[$products_id]['attributes']);
   $where = " AND ((";
	while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
	 $where .= "options_id = '" . (int)$option . "' AND options_values_id = '" . (int)$value . "') OR (";
   }
   $where=substr($where, 0, -5) . ')';

   $attribute_price_query = tep_db_query("SELECT products_attributes_id, options_values_price, price_prefix FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = '" . (int)$products_id . "'" . $where ."");

  if (tep_db_num_rows($attribute_price_query)) {
	   $list_of_prdcts_attributes_id = '';
	   while ($attributes_price_array = tep_db_fetch_array($attribute_price_query)) { 
	   $attribute_price[] =  $attributes_price_array;
	   $list_of_prdcts_attributes_id .= $attributes_price_array['products_attributes_id'].",";
	  }

	   if (tep_not_null($list_of_prdcts_attributes_id) && $this->cg_id != '0') { 
	 $select_list_of_prdcts_attributes_ids = "(" . substr($list_of_prdcts_attributes_id, 0 , -1) . ")";
 $pag_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES_GROUPS . " where products_attributes_id IN " . $select_list_of_prdcts_attributes_ids . " AND customers_group_id = '" . $this->cg_id . "'");
 while ($pag_array = tep_db_fetch_array($pag_query)) {
	 $cg_attr_prices[] = $pag_array;
	  }

 // substitute options_values_price and prefix for those for the customer group (if available)
 if ($customer_group_id != '0' && tep_not_null($cg_attr_prices)) {
	for ($n = 0; $n < count($attribute_price); $n++) {
	 for ($i = 0; $i < count($cg_attr_prices); $i++) {
		 if ($cg_attr_prices[$i]['products_attributes_id'] == $attribute_price[$n]['products_attributes_id']) {
			$attribute_price[$n]['price_prefix'] = $cg_attr_prices[$i]['price_prefix'];
			$attribute_price[$n]['options_values_price'] = $cg_attr_prices[$i]['options_values_price'];
	}
	 } // end for ($i = 0; $i < count($cg_att_prices); $i++)
  }
	} // end if ($customer_group_id != '0' && (tep_not_null($cg_attr_prices))
  } // end if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0')
// now loop through array $attribute_price to add up/substract attribute prices

  for ($n = 0; $n < count($attribute_price); $n++) {
		if ($attribute_price[$n]['price_prefix'] == '+') {
		  $attributes_price += $attribute_price[$n]['options_values_price'];
		} else {
		  $attributes_price -= $attribute_price[$n]['options_values_price'];
		}
  } // end for ($n = 0; $n < count($attribute_price); $n++)
  return $attributes_price;
   } else { // end if (tep_db_num_rows($attribute_price_query))
	 return 0;
}
 }  else { // end if (isset($this->contents[$products_id]['attributes']))
   return 0;
}
  } // end of function attributes_price, modified for SPPC with attributes

function get_products() {
	   global $languages_id, $pfs; // PriceFormatterStore added
// BOF Separate Pricing Per Customer
$this->cg_id = $this->get_customer_group_id();
// EOF Separate Pricing Per Customer

  if (!is_array($this->contents)) return false;
// BOF QPBPP for SPPC
  $discount_category_quantity = array();
  foreach ($this->contents as $products_id => $contents_array) {
	  if(tep_not_null($contents_array['discount_categories_id'])) {
		if (!isset($discount_category_quantity[$contents_array['discount_categories_id']])) {
			$discount_category_quantity[$contents_array['discount_categories_id']] = $contents_array['qty'];
		} else {
			$discount_category_quantity[$contents_array['discount_categories_id']] += $contents_array['qty'];
		}
	  }
  } // end foreach

  $pf = new PriceFormatter;
// EOF QPBPP for SPPC

  $products_array = array();
  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
// BOF QPBPP for SPPC
  $pf->loadProduct($products_id, $languages_id); // does query if necessary and adds to 
  // PriceFormatterStore or gets info from it next
  if ($products = $pfs->getPriceFormatterData($products_id)) {
   if (tep_not_null($this->contents[$products_id]['discount_categories_id'])) {
	  $nof_items_in_cart_same_cat =  $discount_category_quantity[$this->contents[$products_id]['discount_categories_id']];
	  $nof_other_items_in_cart_same_cat = $nof_items_in_cart_same_cat - $this->contents[$products_id]['qty'];
	} else {
	  $nof_other_items_in_cart_same_cat = 0;
	}












	  $products_price = $pf->computePrice($this->contents[$products_id]['qty'], $nof_other_items_in_cart_same_cat);
// EOF QPBPP for SPPC

	  $products_array[] = array('id' => $products_id,
								'name' => $products['products_name'],
								'model' => $products['products_model'],
								'image' => $products['products_image'],
// BOF QPBPP for SPPC
								'discount_categories_id' => $this->contents[$products_id]['discount_categories_id'],
// EOF QPBPP for SPPC
							   'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'final_price' => ($products_price + $this->attributes_price($products_id)),
								'tax_class_id' => $products['products_tax_class_id'],
								'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'];
  }
}

// added for Separate Pricing Per Customer, returns customer_group_id
function get_customer_group_id() {
  if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
	$_cg_id = $_SESSION['sppc_customer_group_id'];
  } else {
	 $_cg_id = 0;
  }
  return $_cg_id;
}

 }
/*  

###	Class wishlist										###

*/

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

function wishlist_class() {
  $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_WISHLIST . " 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_WISHLIST . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $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_WISHLIST_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_WISHLIST . " set customers_basket_quantity = '" . $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_WISHLIST . " 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_WISHLIST_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_WISHLIST . " where customers_id = '" . (int)$customer_id . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_WISHLIST_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_wishlist, $customer_id;

  $products_id = tep_get_uprid($products_id, $attributes);
  if ($notify == true) {
	$new_products_id_in_wishlist = $products_id;
	tep_session_register('new_products_id_in_wishlist');
  }

  if ($this->in_cart($products_id)) {
	$this->update_quantity($products_id, $qty, $attributes);
  } else {


	$this->contents[] = array($products_id);
	$this->contents[$products_id] = array('qty' => $qty);
// insert into database
	if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_WISHLIST . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')");

	if (is_array($attributes)) {
	  reset($attributes);
	  while (list($option, $value) = each($attributes)) {
		$this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
		if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_WISHLIST_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 . "')");
	  }
	}
  }
  $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;

  if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

  $this->contents[$products_id] = array('qty' => $quantity);
// update database
  if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_WISHLIST . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

  if (is_array($attributes)) {
	reset($attributes);
	while (list($option, $value) = each($attributes)) {
	  $this->contents[$products_id]['attributes'][$option] = $value;
// update database
	  if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_WISHLIST_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' 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_WISHLIST . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_WISHLIST_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);
	}
  }

  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_WISHLIST . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_WISHLIST_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
  }

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

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() {
  $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 += tep_add_tax($products_price, $products_tax) * $qty;
	  $this->weight += ($qty * $products_weight);   
	}

// attributes price
// kumar@farmdev.com
// add-weight-to-product-attributes mod:
// added weight to db query
	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, options_values_weight 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 += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
		} else {
		  $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
		}
		 if(!empty($attribute_price['options_values_weight'])) {
			// kumar@farmdev.com
			// add-weight-to-product-attributes mod:
			$this->weight += ($qty * $attribute_price['options_values_weight']);
		} // END if(!empty($attribute_price['options_values_weight'])) {
	   }
	}
  }
}

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

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)) {
	$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_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_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'],
								'qproduct' => '', // added for Get 1 Free mod
								'model' => $products['products_model'],
								'image' => $products['products_image'],
								'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'final_price' => ($products_price + $this->attributes_price($products_id)),
								'tax_class_id' => $products['products_tax_class_id'],
								'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'];
  }
}

 }  
?>

Edited by Jan Zonjee

Share this post


Link to post
Share on other sites

Thanks Jan,

 

I had a little look myself this afternoon with limited luck, shall we say :)

 

I did find a php script which validates all 27 EU countries codes here but as you say, that doesn't cover the whole world.

 

Do you think the method of 'applying for a trade account' as in this contrib is the most elegant solution, in your experience?

 

I just need to be able to deal with 'retail' and 'trade' customers differently, in the simplest way... and possibly use some of the more specialised 'per customer' features presented in SPPC422...

 

 

Many thanks for the help

 

Bee


There are 10 types of people in this world, those who understand binary and those who don't...

Share this post


Link to post
Share on other sites
I've loaded price breaks for sppc and I have hide products also installed. My current problem is with the includes/classes/shopping_cart.php. When I try to bring up the store I get this error.

 

Parse error: syntax error, unexpected T_CLASS, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /mnt/blablablabla/catalog/includes/classes/shopping_cart.php on line 714

If you checked what line that was you might have seen that you added a new class to the includes/classes/shopping_cart.php:

// added for Separate Pricing Per Customer, returns customer_group_id
    function get_customer_group_id() {
      if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
        $_cg_id = $_SESSION['sppc_customer_group_id'];
      } else {
         $_cg_id = 0;
      }
      return $_cg_id;
    }

  } // end of class shopping_cart
/*  

###    Class wishlist                                    
    ###

*/

  class wishlist_class { // this is line 714
    var $contents, $total, $weight, $cartID, $content_type;

    function wishlist_class() {
      $this->reset();
    }
etcetera, etcetera

I must admit I never tried adding more than one class to a file but it looks PHP doesn't like it.

Share this post


Link to post
Share on other sites
How do I do that? I'm sorry for my ignorance

Use an FTP client (program) to download that file to your computer and then open it in a text editor (preferably one that can "color" PHP code like JEdit - www.jedit.org but there many editors out there).

Share this post


Link to post
Share on other sites
I did find a php script which validates all 27 EU countries codes here but as you say, that doesn't cover the whole world.

 

Do you think the method of 'applying for a trade account' as in this contrib is the most elegant solution, in your experience?

That script seems to check only if it the VAT number give *could* be valid. Not if the VAT number matches the name of the company that opens an account with you. I believe it is up to you to check they are a genuine company before you deliver them without tax. If you fail to do that and they are an end user the tax service will come after you.

 

So in my opinion this is not something you want to leave to a script or the client to choose for. The financial consequences for you can be severe...

 

Standard behaviour is that you get sent an email if a company fills in something in the tax number id field. That's the moment to go in the admin, make your checks against any database that has that information and put them in another customer group id if all seems OK.

Share this post


Link to post
Share on other sites
If you checked what line that was you might have seen that you added a new class to the includes/classes/shopping_cart.php:

// added for Separate Pricing Per Customer, returns customer_group_id
    function get_customer_group_id() {
      if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
        $_cg_id = $_SESSION['sppc_customer_group_id'];
      } else {
         $_cg_id = 0;
      }
      return $_cg_id;
    }

  } // end of class shopping_cart
/*  

###    Class wishlist                                    
    ###

*/

  class wishlist_class { // this is line 714
    var $contents, $total, $weight, $cartID, $content_type;

    function wishlist_class() {
      $this->reset();
    }
etcetera, etcetera

I must admit I never tried adding more than one class to a file but it looks PHP doesn't like it.

Share this post


Link to post
Share on other sites

Hya All,

 

I have installed version 4.1.4 and everything seems to work perfect (thank you all for this great contrib). Also I would like to add a box which shows the customer after logging in, to what customer_group he belongs to. Probably someone already sorted this out and would like to share the file(s)?

Share this post


Link to post
Share on other sites
That script seems to check only if it the VAT number give *could* be valid. Not if the VAT number matches the name of the company that opens an account with you. I believe it is up to you to check they are a genuine company before you deliver them without tax. If you fail to do that and they are an end user the tax service will come after you.

 

So in my opinion this is not something you want to leave to a script or the client to choose for. The financial consequences for you can be severe...

 

Standard behaviour is that you get sent an email if a company fills in something in the tax number id field. That's the moment to go in the admin, make your checks against any database that has that information and put them in another customer group id if all seems OK.

 

 

Once again Jan, thanks for your help on this.

 

I will take your advice and implement the SPPC422 method of email alert when 'trade' account is requested....

 

Many thanks

 

Bee

:)


There are 10 types of people in this world, those who understand binary and those who don't...

Share this post


Link to post
Share on other sites

I have just loaded Version 2 of the Quantity Price Breaks Per Product for Separate Pricing Per Customer. Congratulations! This is a great update.

I have noticed the price on the first product screen now states "from $--" and uses the lowest price from the price breaks. I want to continue using the gross price of the single product rather than the discounted quantity price. Where do I find this code and what do I change it to?

With Thanks

Ronnie

Share this post


Link to post
Share on other sites
I have noticed the price on the first product screen now states "from $--" and uses the lowest price from the price breaks.

I'm not sure what you mean with "first product screen" but if you mean the product listing then just keep using the "old" sppc product listing if you don't want to do anything with price breaks there.

Share this post


Link to post
Share on other sites
I'm not sure what you mean with "first product screen" but if you mean the product listing then just keep using the "old" sppc product listing if you don't want to do anything with price breaks there.

Thanks Jan

Perfect answer for my muddly question. It was exactly what I needed and has saved me a lot of time.

Ronnie

Share this post


Link to post
Share on other sites

Hello,

 

I'm directing this to Jan or to Marvin Miller (if he is still on these forums). My question concerns the compatibility of SPPC and the X-Sell contribution found here. This was addressed in this forum back in early 2005 when Jan and Marvin worked together to create a modified xsell_products.php file that would correctly display the prices for the differing customer groups in SPPC. A link to that post can be found here.

 

My question is whether or not it is possible to revisit this topic and create a newly modified xsell_products.php file that will work with the current versions of both SPPC and X-Sell. For whatever reason, as the X-Sell contribution evolved, the SPPC modifications were removed and the file from 2005 no longer works with SPPC (at least for me).

 

I have tried to modify and merge the files myself but I'm afraid I have failed in my efforts. If anyone has successfully modified this file to work with SPPC I would be grateful to learn how it was accomplished.

 

Thanks again.

Share this post


Link to post
Share on other sites

If it helps any - this is my includes/modules/xsell_products.php file:

<?php
/*
$Id: xsell_products.php, v1  2002/09/11
// adapted for Separate Pricing Per Customer v4 2005/02/24

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

Copyright (c) 2002 osCommerce

Released under the GNU General Public License
*/
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_XSELL_PRODUCTS);

// BOF Separate Pricing Per Customer
if(!tep_session_is_registered('sppc_customer_group_id')) {
$customer_group_id = '0';
} else {
 $customer_group_id = $sppc_customer_group_id;
}
global $customer_group_id;

if ($HTTP_GET_VARS['products_id']) {

//Cache
$dircache = DIR_FS_CACHE_XSELL . $HTTP_GET_VARS['products_id'] . '/';
$filename = $dircache  . $languages_id . '-' . $customer_group_id . '.php';
$cache = '<?php 
 $info_box_contents = array();
 $info_box_contents[] = array(\'align\' => \'left\', \'text\' => TEXT_XSELL_PRODUCTS);
 new XsellBoxHeading($info_box_contents);
 $info_box_contents = array();';
if (file_exists($filename))
{require $filename;}
else
{
//Fin cache

if ($customer_group_id != '0') {
$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, IF(pg.customers_group_price IS NOT NULL, pg.customers_group_price, p.products_price) as products_price from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_GROUPS . " pg using(products_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and xp.xsell_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' and pg.customers_group_id = '".$customer_group_id."' and find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 order by sort_order asc limit " . MAX_DISPLAY_ALSO_PURCHASED);
} else {
$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and xp.xsell_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' and find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 order by sort_order asc limit " . MAX_DISPLAY_ALSO_PURCHASED);
}
// EOF Separate Pricing Per Customer

$num_products_xsell = tep_db_num_rows($xsell_query);
if ($num_products_xsell > 0) {
?>
<!-- xsell_products //-->
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('align' => 'left', 'text' => TEXT_XSELL_PRODUCTS);
 new XsellBoxHeading($info_box_contents);

 $row = 0;
 $col = 0;
 $info_box_contents = array();
 while ($xsell = tep_db_fetch_array($xsell_query)) {
   $xsell['specials_new_products_price'] = tep_get_products_special_price($xsell['products_id']);

if ($xsell['specials_new_products_price']) {
 $xsell_price =  '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s><br>';
 $xsell_price .= '<span class="productSpecialPrice">' . $currencies->display_price($xsell['specials_new_products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
  } else {
 $xsell_price =  $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
  }
   //Cache
   $text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br>Qty: ' . tep_draw_input_field('Qty_ProdId_' . $xsell['products_id'], '', 'size="4"') .'</a>';
   //Fin cache
   $info_box_contents[$row][$col] = array('align' => 'center',
										  'params' => 'class="XsellBoxContents" width="33%" valign="top"',
										  'text' => $text); //Modifié Cache
   //Cache
   $cache .= '$info_box_contents[' .$row . '][' . $col . '] = array(\'align\' => \'center\',
										  \'params\' => \'class="XsellBoxContents" width="33%" valign="top"\',
										  \'text\' => \'' . str_replace("'", "\'", $text) .'\');';
   //Fin cache	   
   $col ++;
   if ($col > 2) {
	 $col = 0;
	 $row ++;
   }
 }
new XsellBox($info_box_contents);
//Cache
/* Not Using
 $cache .= 'new XsellBox($info_box_contents); ?>';
 if(!is_dir($dircache)) { mkdir($dircache,0777); }
 $fp = fopen($filename , 'w');
 $fout = fwrite($fp , $cache);
 fclose($fp);
*/
}
//Fin Cache

?>
<!-- xsell_products_eof //-->
<?php
  }
}
?>

 

Hello,

 

I'm directing this to Jan or to Marvin Miller (if he is still on these forums). My question concerns the compatibility of SPPC and the X-Sell contribution found here. This was addressed in this forum back in early 2005 when Jan and Marvin worked together to create a modified xsell_products.php file that would correctly display the prices for the differing customer groups in SPPC. A link to that post can be found here.

 

My question is whether or not it is possible to revisit this topic and create a newly modified xsell_products.php file that will work with the current versions of both SPPC and X-Sell. For whatever reason, as the X-Sell contribution evolved, the SPPC modifications were removed and the file from 2005 no longer works with SPPC (at least for me).

 

I have tried to modify and merge the files myself but I'm afraid I have failed in my efforts. If anyone has successfully modified this file to work with SPPC I would be grateful to learn how it was accomplished.

 

Thanks again.


~Tracy
 

Share this post


Link to post
Share on other sites

I have a strange thing happening on our site. I can login (via admin login) without a problem if I choose "Retail", but if I choose "Wholesale" it just brings me back to the login page. If I first login as Retail, then logout and log back in as Wholesale it will allow me in.

 

I have not changed anything in the login.php page - but we did recently change hosting companies. I was wondering if maybe there is a difference in the login.php page script with MySQL 5.0.51a or PHP 5.2.6 and (prior host was running) MySQL 5.0.67 and PHP 4.4.7 ?

 

Any other ideas on what would cause the page to sporadically allow or not allow login of a Wholesale customer? (Had a customer call us today informing us they weren't able to login to the site to place an order last night) :(

 

Any thoughts on what info I should try to print out in order to troubleshoot what is happening on the error when it redirects back to the login page?

 

Any help is greatly appreciated as this is a live shop that just started acting up without any changes being done to the php files :blink:

 

TIA!


~Tracy
 

Share this post


Link to post
Share on other sites
If it helps any - this is my includes/modules/xsell_products.php file:

 

 

Tracy,

 

Thank you for posting that. When I saw it I got a little excited in hope that I might make this work... but I can't :( Normally I'm pretty good at picking apart code and getting things to work together but I just can't seem to make the connection with this one. My xsell_products.php looks completely different than the one you posted (most notably the cache) and I just can't get it.

 

What version is your file from? I have the most recent update...

 

I really do appreciate you taking the time to post that though. I'll just have to keep searching.

 

Thanks again.

Edited by DimeNote

Share this post


Link to post
Share on other sites

I have just added SPPC to my site and now I am getting this error during checkout and I am not sure how to fix it:

 

PHP Fatal error: Call to undefined method: shoppingcart->count_contents_virtual() in /usr/home/mickna/www/htdocs/checkout_payment.php on line 75

 

Here is what is on line 75:

$total_count = $cart->count_contents_virtual(); // CCGV

 

I have looked at checkout_payment.php but I am not sure what I should be looking for.

 

When I reverted back to site without sppc, everything works fine.

 

Can someone tell me where I should be looking?

 

Thanks

Edited by paq1200

Share this post


Link to post
Share on other sites
I have a strange thing happening on our site. I can login (via admin login) without a problem if I choose "Retail", but if I choose "Wholesale" it just brings me back to the login page. If I first login as Retail, then logout and log back in as Wholesale it will allow me in.

Never tried that. Will try it myself in a couple of days (I'm away from home at the moment).

 

Any other ideas on what would cause the page to sporadically allow or not allow login of a Wholesale customer? (Had a customer call us today informing us they weren't able to login to the site to place an order last night) :(

 

Any thoughts on what info I should try to print out in order to troubleshoot what is happening on the error when it redirects back to the login page?

If this is coming up only once in a while it will be hard to trouble shoot. I can't think of anything that might cause that apart from customer error (using wrong password?).

Share this post


Link to post
Share on other sites
PHP Fatal error: Call to undefined method: shoppingcart->count_contents_virtual() in /usr/home/mickna/www/htdocs/checkout_payment.php on line 75

 

Here is what is on line 75:

$total_count = $cart->count_contents_virtual(); // CCGV

 

I have looked at checkout_payment.php but I am not sure what I should be looking for.

 

When I reverted back to site without sppc, everything works fine.

Looks like you added the contribution CCGV to your site and now swapped in the includes/classes/shopping_cart.php from the SPPC package with the one you had. The SPPC version does not contain the function count_contents_virtual that CCGV apparently adds to that file so you should add that to the SPPC one (and perhaps there are more changes needed for CCGV).

Share this post


Link to post
Share on other sites

It seems to be happening more than once in a while now. I am only getting retail customer orders the last few days, and wholesale customers have been calling in to place their order because they can't log in :(

 

This is just bizarre :blink:

 

Never tried that. Will try it myself in a couple of days (I'm away from home at the moment).

 

 

If this is coming up only once in a while it will be hard to trouble shoot. I can't think of anything that might cause that apart from customer error (using wrong password?).


~Tracy
 

Share this post


Link to post
Share on other sites

I used xsell v 2.3

 

ContentBoxHeading changed to XsellBoxHeading and class="SmallText" changed to class="XsellBoxContents" and new contentBox changed to new XsellBox for infobox customizing contrib.

 

The "and find in set" bit in the queries is for the hide products and categories from customer groups for SPPC contrib

 

I commented out the cache section as I don't use it - it made it a complete pain in the butt to change the x-sell product information because then I'd have to go into the server and delete the old cache files before a customer would see the new information. Wasn't worth the tiny bit of load time it may save for our particular site.

 

Tracy,

 

Thank you for posting that. When I saw it I got a little excited in hope that I might make this work... but I can't :( Normally I'm pretty good at picking apart code and getting things to work together but I just can't seem to make the connection with this one. My xsell_products.php looks completely different than the one you posted (most notably the cache) and I just can't get it.

 

What version is your file from? I have the most recent update...

 

I really do appreciate you taking the time to post that though. I'll just have to keep searching.

 

Thanks again.


~Tracy
 

Share this post


Link to post
Share on other sites

Just an update as I go through troubleshooting to the best of my ability: I set one of my accounts to Wholesale and it will not let me log in.

 

I deleted the session ID from the URL on login.php and re-loaded the login.php page and then it let me sign in under a Wholesale account.

 

It seems to have something to do with whether or not there is a session ID in the URL already.

 

This bit of code is at the top of the page - but I don't think it's this as I'm not being redirected to the cookie_usage.php but rather the login.php is simply reloading:

// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled (or the session has not started)
 if ($session_started == false) {
tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
 }

 

The other bit of code I see that maybe would be causing this is:

// Check that password is good
  if (!tep_validate_password($password, $check_customer['customers_password'])) {
	$error = true;
  } else {
	if (SESSION_RECREATE == 'True') {
	  tep_session_recreate();
	}

 

Any new thoughts?

 

It seems to be happening more than once in a while now. I am only getting retail customer orders the last few days, and wholesale customers have been calling in to place their order because they can't log in :(

 

This is just bizarre :blink:


~Tracy
 

Share this post


Link to post
Share on other sites

Tried adding the below to the login.php file just under the application_top include line:

// BOF Separate Pricing Per Customer
global $sppc_customer_group_id;
if(!tep_session_is_registered('sppc_customer_group_id')) { 
$customer_group_id = '0';
  } else {
	$customer_group_id = $sppc_customer_group_id;
}
// EOF Separate Pricing Per Customer

 

Did not make any difference. Still can only login if I delete the session ID from the URL line :blink:

 

Just an update as I go through troubleshooting to the best of my ability: I set one of my accounts to Wholesale and it will not let me log in.

 

I deleted the session ID from the URL on login.php and re-loaded the login.php page and then it let me sign in under a Wholesale account.

 

It seems to have something to do with whether or not there is a session ID in the URL already.

 

This bit of code is at the top of the page - but I don't think it's this as I'm not being redirected to the cookie_usage.php but rather the login.php is simply reloading:

// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled (or the session has not started)
 if ($session_started == false) {
tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
 }

 

The other bit of code I see that maybe would be causing this is:

// Check that password is good
  if (!tep_validate_password($password, $check_customer['customers_password'])) {
	$error = true;
  } else {
	if (SESSION_RECREATE == 'True') {
	  tep_session_recreate();
	}

 

Any new thoughts?


~Tracy
 

Share this post


Link to post
Share on other sites

If it helps any, in my Admin->Configuration->Sessions

 

The directory is /tmp

Everything is set to False except for "Prevent Spider Sessions" which is set to True.

 

Also, the login page is https:// as it is a secure page. Would the SSL combined with the Session ID cause the problem?

 

 

Tried adding the below to the login.php file just under the application_top include line:

// BOF Separate Pricing Per Customer
global $sppc_customer_group_id;
if(!tep_session_is_registered('sppc_customer_group_id')) { 
$customer_group_id = '0';
  } else {
	$customer_group_id = $sppc_customer_group_id;
}
// EOF Separate Pricing Per Customer

 

Did not make any difference. Still can only login if I delete the session ID from the URL line :blink:


~Tracy
 

Share this post


Link to post
Share on other sites

PS - It is not customer id specific - it seems to only have to do with the active session id being in the URL. If the session has timed out then it will allow you to login (wholesale or retail) and if you delete the session id from the URL it will allow login (wholesale or retail). But if the session id is in the URL and is active it will NOT allow you to login (wholesale or retail) :huh:

 

If it helps any, in my Admin->Configuration->Sessions

 

The directory is /tmp

Everything is set to False except for "Prevent Spider Sessions" which is set to True.

 

Also, the login page is https:// as it is a secure page. Would the SSL combined with the Session ID cause the problem?


~Tracy
 

Share this post


Link to post
Share on other sites

I think I found it. I had removed this block of code from login.php, when I put the code back in it seems to work:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">

 

However - on the downside, it now gives me two sections with that information if I view my source from a browser <_<

So I'm off to the STS board to find out where the $htmlparams are pulled from to see if there is a way I can combine this so I don't have this info repeated in my source on the login.php page - LOL

 

OY :blush:

 

PS - It is not customer id specific - it seems to only have to do with the active session id being in the URL. If the session has timed out then it will allow you to login (wholesale or retail) and if you delete the session id from the URL it will allow login (wholesale or retail). But if the session id is in the URL and is active it will NOT allow you to login (wholesale or retail) :huh:

~Tracy
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×