Jump to content
scendent

Seperate Pricing Per Customer v3.5

Recommended Posts

First thought I have is to check the end of your files and make sure you don't have a space or extra line after the closing ?> at the bottom of the page

 

if that doesn't fix it, go to google.com and type in site:forums.oscommerce.com "cannot modify header" and go through the various posts of others who have also been through this particular error :thumbsup:

 

Thank you so much for your quick response! These hints have been invaluable. I now am running into a new problems. All of the above fixes have worked perfectly, but I am now getting this error:

I get this after logging in with both my normal login and a test one.

 

Thanks so much again and sorry I am such a pain!


~Tracy
 

Share this post


Link to post
Share on other sites
Nothing SPPC can do about that. Here is the code that does that (if you login coming from advanced_search.php it will send you back to that page after the login):

		if (sizeof($navigation->snapshot) > 0) {
	  $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
	  $navigation->clear_snapshot();
	  tep_redirect($origin_href);
	} else {
	  tep_redirect(tep_href_link(FILENAME_DEFAULT));
	}

 

Hi Jan zonjee

 

Thanks for you reply, i go derectly to index.php, and click login.php, it is still go to advaced_search page, can you tell me where is my falut. or where should i check?

Share this post


Link to post
Share on other sites

Ok, i have fix the problem to advace_search page

 

but i have another problems

 

Sub-Total:

Fatal error: Call to undefined function: calculate_price() in /home/xxxxx/includes/classes/shopping_cart.php on line 360

 

This is my shopping car php file

 

<?php
/*
 $Id: shopping_cart.php,v 1.35 2003/06/25 21:14:33 hpdl Exp $
 adapted for Separate Pricing Per Customer v4.2 2007/01/01

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

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

  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;

  $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

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

// 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 += $qty * tep_add_tax($attribute_price[$n]['options_values_price'], $products_tax);
		} else {
		  $this->total -= $qty * tep_add_tax($attribute_price[$n]['options_values_price'], $products_tax);
	}
  } // 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
// http://forums.oscommerce.com/index.php?showtopic=139587
// 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;
// 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;

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

// BOF Separate Pricing Per Customer
  $specials_price = tep_get_products_special_price($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

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

 }
?>

Share this post


Link to post
Share on other sites
but i have another problems

 

Sub-Total:

Fatal error: Call to undefined function: calculate_price() in /home/xxxxx/includes/classes/shopping_cart.php on line 360

 

This is my shopping car php file

Yes, I recognize it. If you search that page on calculate_price (line 360 of course) then you will notice that it is in the function calculate and outside of changes by SPPC:

 

	function calculate() {
.
.
.
// EOF Separate Pricing Per Customer
	  $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
	  $this->weight += ($qty * $products_weight);
	}
// attributes price

As a matter of fact this function is new in RC1 (class currencies). So it looks like you are adding files from the package in your shop that is not updated to RC1. With most files that will not be a problem, this is the exception however.

Share this post


Link to post
Share on other sites
I now am running into a new problems. All of the above fixes have worked perfectly, but I am now getting this error:

I get this after logging in with both my normal login and a test one.

Actually, the error message mention line numbers in certain files. It would be rather helpful to know what is on those lines.... (we are not psychic here, at least I haven't run into one here).

Share this post


Link to post
Share on other sites

I've seen several posts regarding percentage discounts. Here is my situation:

 

I have around 15,000 items in my catalog split up into 2 categories in my store (parts, systems.) All prices are currently listed as retail. I want to create 5 different groups with different discounts (5%, 10%, 15%, 20%, 25%) that apply to just the parts category. I want the prices of the items in the other category to always be retail regardless of which group the customer belongs to.

 

How would I go about doing this? Since the category I want the discounts applied to has over 13,000 items is there a way to just automatically apply the various pricing levels to the current prices without having to manually change entries? I have all of the items in a CSV file and there is a column associated with each item that has a "P" or "S" depending on which category the item belongs in (if that is of any help in automating the process.)

 

As it stands now customers that receive a discount have to call and order by phone because I can't get this to work properly. Any help would be greatly appreciated - answering phones and applying customers' discounts to low-dollar parts is becoming a full-time job in itself and I really hope this is the solution!

 

If this won't do what I need what other options do I have? Is there a coupon add-on that can solve this? I can live with giving customers a permanent coupon code they have to enter when they place an order if that's the only solution.

 

Thanks

Edited by brojamma

Share this post


Link to post
Share on other sites
I've seen several posts regarding percentage discounts. Here is my situation:

 

I have around 15,000 items in my catalog split up into 2 categories in my store (parts, systems.) All prices are currently listed as retail. I want to create 5 different groups with different discounts (5%, 10%, 15%, 20%, 25%) that apply to just the parts category. I want the prices of the items in the other category to always be retail regardless of which group the customer belongs to.

The last thing is no problem for SPPC, it always defaults to retail price if there is no group price.

How would I go about doing this? Since the category I want the discounts applied to has over 13,000 items is there a way to just automatically apply the various pricing levels to the current prices without having to manually change entries? I have all of the items in a CSV file and there is a column associated with each item that has a "P" or "S" depending on which category the item belongs in (if that is of any help in automating the process.)

Two queries might be helpfull in this respect (using phpMyAdmin to work directly on your database, backup first :) ). One is a "fill" query that takes all products, calculates the group price with a factor (here 0.9 so 10% discount) and inserts that in the group price table:

insert into products_groups select '4' as customers_group_id, (0.9 * p.products_price) as customers_group_price, p.products_id from products p;

If something goes wrong and you need to do something like that again you can delete all those prices again with:

delete from products_groups where customers_group_id = '4';

Now you mention you have products in categories. You can pick and choose to insert only products from certain categories with:

insert into products_groups select '2' as customers_group_id, (0.9 * p.products_price) as customers_group_price, p.products_id from products p, products_to_categories p2c where p.products_id = p2c.products_id and p2c.categories_id in ( 10, 11, 12, 13, 14, 15);

where 10, 11, 12, 13 etc. are the categories.

If it is all mixed you might have to learn how the Easy Populate contribution works, insert a column in table products for products_type for example. If you can get the "P" and "S" in that table using the csv file you are in business because then the first query adapted for "P" should work:

insert into products_groups select '4' as customers_group_id, (0.9 * p.products_price) as customers_group_price, p.products_id from products p where p.products_type = 'P';

Or else use the first query and import your CSV file in Excel, sort on the P and S, keep the ones with S and delete all other stuff till you only have the products_id's that are in your own table (if you have that) and then export it to to a comma separated file so that you delete those two thousand products from products_groups that do not belong there with:

delete from products_groups where products_id in (122, 145, 155, etcetera);

Share this post


Link to post
Share on other sites

i have started with a new installation of SPPC .. and then added other mods after.

 

Though i have it working i have noticed a change to my formatting of myaccount.. it jumps to my login.php page.. but the main screen has moved dramatically over to the right.

 

i have noticed it in new producst too..

 

http://moderatelypassionate.com/teststore/login.php

 

can someone please help me??

 

 

Lastly when i go to "specials" i get this error

 

1146 - Table 'moderate_teststr.TABLE_PRODUCTS_GROUPS' doesn't exist

 

select products_id, customers_group_price from TABLE_PRODUCTS_GROUPS where (products_id = '139' ) and customers_group_id = '0'

 

 

could anyone advise what went wrong.

Share this post


Link to post
Share on other sites
Though i have it working i have noticed a change to my formatting of myaccount.. it jumps to my login.php page.. but the main screen has moved dramatically over to the right.

Must be an error in the HTML of the page (table rows/table data messed up). Only thing to do about that is go back to a page that did not have the error and implement the changes in the PHP code again.

Lastly when i go to "specials" i get this error

 

1146 - Table 'moderate_teststr.TABLE_PRODUCTS_GROUPS' doesn't exist

Probably it exists but you haven't added the define to includes/database_tables.php (probably in the catalog part, but it also needs to be added to the admin side).

Share this post


Link to post
Share on other sites

With Quantity Price Breaks for SPPC - I have a page that has two different versions of a product and both versions have a price break. I only want the box informing customers of the price break to show up once - but it shows up twice (once for each product version). What bit of code do I need to change so it only shows once?

 

Example: http://www.mountainmeadowherbs.com/gentle-...rmula-p-31.html

Edited by TracyS

~Tracy
 

Share this post


Link to post
Share on other sites

Yes, I recognize it. If you search that page on calculate_price (line 360 of course) then you will notice that it is in the function calculate and outside of changes by SPPC:

 

	function calculate() {
.
.
.
// EOF Separate Pricing Per Customer
	  $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
	  $this->weight += ($qty * $products_weight);
	}
// attributes price

 

====

 

I changed the $this->total... line to:

 

$this->total += tep_add_tax($products_price, $products_tax) * $qty;

 

and it's finally setting the subtotals agains. I used Meld to compare and make the file changes and I think the file I was copying from brought it over. I figure the change is from a previous version or another contribution. A clean install has the correct command.

Edited by pchoi71

Share this post


Link to post
Share on other sites
I figure the change is from a previous version or another contribution. A clean install has the correct command.

Actually, it is from RC1. Older versions don't have that function.

Share this post


Link to post
Share on other sites
What bit of code do I need to change so it only shows once?

I have no clue. Apparently, the code to get the price breaks for each slave product is in a loop. You could add a variable above the loop and increment it at the end of the loop. Then you make the echo'ing of that table dependent on that variable (say you start with zero, it can only be zero). But then the fact remains that nobody knows for sure what price break is actually connected to which product...

Share this post


Link to post
Share on other sites

I have something I have been trying to solve but I have tried editing various sections of PHP in a number of different files to no avail.

 

What I want is to edit the customer group ID assigned to guests. Why? Well, I want to have three sites sharing the same products tables for stock & description purposes. However the three sites (directories) will display 3 different prices - retail, dropship and wholesale. The default price is set as retail which is fine for guests visiting the retail site, however, it is proving confusing for some customers visiting the dropship and/or wholesale site because they are also shown the retail price by default.

 

I presume there is a way to set the customer ID when not logged in? By default it is set to 0, is it possible to change it to '1'?

 

I have tried setting some of the figures from 0 to 1 within various PHP files effected by SPPC but I can't seem to get different prices to display for guests. I was hoping somebody could point me in the right direction?

 

Is it possible to change one variable? I no longer require the variable to be dynamically created from the customer database because I will be using a different folder/files for each pricing method so they can be set within the files themselves (i.e 0 , 1 , 2). The prices will remain the same for guests and logged in customers. However, the prices will be different depending on which directory/store they visit (drawn from the table products_groups).

 

Thanks in advance for any help anyone can provide.

Share this post


Link to post
Share on other sites

I figured something was looping, my guess is with a "while" statement maybe? The price break is the same for both versions of the 4oz product, so it doesn't need repeating. Which page of code to get the price breaks do you think I'd need to look at though? For example, in my master_listing.php I have this bit of code - is there a way to tell this to only show once?

 

<!-- QPB -->
<?php	  
  if (($listing[$x]['products_price1'] == '0.0000') || $customer_group_id != '0'){ 
echo tep_draw_separator('pixel_trans.gif', '100%', '1'); 
}else{
?>
<tr>
<td colspan="3" align="center">
<table width="70%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="3"><h3>Volume Discount on 4oz Bottles!</h3></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="qpbTable">
<tr>
<td colspan="3" align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>3-5 bottles:</td>
<td>Save 5%</td>
<td align="right" valign="top">Only <?php echo $currencies->display_price($listing[$x]['products_price1'], tep_get_tax_rate($listing[$x]['products_tax_class_id'])); ?> each</td>
</tr>
<tr>
<td>6 or more bottles:</td>
<td>Save 10%</td>
<td align="right" valign="top">Only <?php echo $currencies->display_price($listing[$x]['products_price2'], tep_get_tax_rate($listing[$x]['products_tax_class_id'])); ?> each</td>
</tr>
</table></td>
</tr>
</table></td></tr>

 

I have no clue. Apparently, the code to get the price breaks for each slave product is in a loop. You could add a variable above the loop and increment it at the end of the loop. Then you make the echo'ing of that table dependent on that variable (say you start with zero, it can only be zero). But then the fact remains that nobody knows for sure what price break is actually connected to which product...

~Tracy
 

Share this post


Link to post
Share on other sites
I figured something was looping, my guess is with a "while" statement maybe? The price break is the same for both versions of the 4oz product, so it doesn't need repeating. Which page of code to get the price breaks do you think I'd need to look at though? For example, in my master_listing.php I have this bit of code - is there a way to tell this to only show once?

Hard to say because the loop starts outside of this.

 

<!-- QPB -->
<?php	  
  if (($listing[$x]['products_price1'] == '0.0000') || $customer_group_id != '0'){ 
echo tep_draw_separator('pixel_trans.gif', '100%', '1'); 
} elseif ($variable_to_check_on_loop == 0) {
?>

Share this post


Link to post
Share on other sites
I presume there is a way to set the customer ID when not logged in? By default it is set to 0, is it possible to change it to '1'?

It is normally set with this piece of code (found on a lot of places, this is the latest version version):

// BOF Separate Pricing per Customer
 if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
$customer_group_id = $_SESSION['sppc_customer_group_id'];
 } else {
$customer_group_id = '0';
 }
// EOF Separate Pricing per Customer

The whole idea of SPPC was that you wouldn't need different versions of your shop...

Share this post


Link to post
Share on other sites

Thanks Jan. This is the part of the PHP files I have been editing but I must be going wrong somewhere - which 0 needs changing to 1 and in which files? I thought changing the code in product_listings would display the prices for group 1, but maybe there is some key file that controls group_id?

 

Maybe I have just gone wrong editing the code. Any guidance you can offer would be appreciated.

 

I understand that SPPC is so that you don't need different stores - but there is no other way to determine which price a guest sees. Previously we have used 'login to view price' which worked OK but we were asking members to sign in twice which was frustrating for them (logging in to the 'dropship' or 'wholesale' area via protected folders then being asked to sign in to the shopping cart).

 

I suspect what I am trying to do could be done without SPPC by altering which column prices are drawn from for $products_price (i.e. RRP, Dropship, Wholesale) but thought this would be quicker.

 

Out of interest which files and sections would need altering to change which column the price is drawn from? Is there just one variable needs defining or do you need to change all/most of the files altered in SPPC?

 

Thanks for your help, I can see why you're appreciated so much on this forum!

 

It is normally set with this piece of code (found on a lot of places, this is the latest version version):

// BOF Separate Pricing per Customer
 if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
$customer_group_id = $_SESSION['sppc_customer_group_id'];
 } else {
$customer_group_id = '0';
 }
// EOF Separate Pricing per Customer

The whole idea of SPPC was that you wouldn't need different versions of your shop...

Share this post


Link to post
Share on other sites
This is the part of the PHP files I have been editing but I must be going wrong somewhere - which 0 needs changing to 1 and in which files?

In this part (and it is in a lot of files):

  } else {
$customer_group_id = '0'; // change to 1 to use that customer group for guests
 }

I thought changing the code in product_listings would display the prices for group 1, but maybe there is some key file that controls group_id?

No, there is no key file (unless you login of course, that is login.php).

 

I understand that SPPC is so that you don't need different stores - but there is no other way to determine which price a guest sees.

In most shops you don't want your guests to see the dropship or wholesale prices of course. I understand now that there are some scenario's where you want to show more prices for example if want to entice people to become member and also show member prices.

Share this post


Link to post
Share on other sites

I am hoping someone might be able to help me here. I would like to have a dicounted price for only one customer type if more than 3 items are purchased in a particular category.

For example:

Category1 - $10 per item if purchased less than 3 items

Category1 - $8 per item if purchased 3 or more items

Category2 - $32 per item if purchased less than 3 items

Category2 - $28 per item if purchased 3 or more items

and so on....

 

I have taken a look at Quantity Price Breaks for Separate Pricing Per Customer with the Per category modification but I don't think that will work for me. My store hase personalized items. so they may need 5 items from a category but each one will be personalized differently (product attributes) thus it needs to be a different item. Meaning, I cannot go to product A and say I need 4 of these.

 

I was hoping something like this would be possible:

In the shopping cart, if a particular customer type simply gather all products, product prices, category id's and determine if there are 3 or more products from a particular category, and if so update those prices.

 

I know things here always seem more simple than they actually are but any help would be greatly apprecieated.

Share this post


Link to post
Share on other sites
I was hoping something like this would be possible:

In the shopping cart, if a particular customer type simply gather all products, product prices, category id's and determine if there are 3 or more products from a particular category, and if so update those prices.

In principle this is possible. The Per category mod goes in that direction but doing it for only one customer type makes it a modification of a not written yet modification. The per category modification has no problems with attributes (on the contrary) but doesn't look at a customer group. It also has some flaws (the same product can be in different categories, the code doesn't work then).

 

I'm not familiar with the category discount contribution but I suspect it is an order total module. Should work with SPPC but again not customer group aware, unless you add similar code that is used to enable payment and shipping modules for customer groups to the order total code then that might very well work.

Share this post


Link to post
Share on other sites

Jan:

 

I just saw your post! Thanks for the information - I'll give it a whirl this afternoon and let you know how it goes.

 

Brock

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

×