Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Restore contents with Attributes problem


Guest

Recommended Posts

Hi

 

I made some extensive modifications as to how classes/shopping_cart.php handles attributes. Basically what I wanted was to be able to make the attribute values factors so that if there are multiple attributes it multiplies them with each other and then divides it by 1000. Over and above that I installed the Seperate Price per Product contribution ... which further complicated things.

 

Eaither way it works now ... except for the restore_contents() function in shopping_cart.php.

 

Here's the modified sections of my shopping_cart.php file:

 

	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 calculate() {
  $this->total = 0;
  $this->weight = 0;
  if (!is_array($this->contents)) return false;
// BOF Separate Pricing Per Customer, Price Break 1.11.3 mod
  global $languages_id;
  $pf = new PriceFormatter;

  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)) 
	if ($product = $pf->loadProduct($products_id, $languages_id)){		
	  $prid = $product['products_id'];
	 $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
 //		$products_price = $product['products_price'];
	  $products_price = $pf->computePrice($this->contents[$products_id]['qty']);
	  if ($this->attributes_price($products_id) > 0) {
		  $temp_total_price = $products_price * $this->attributes_price($products_id);
		  $total_price = $temp_total_price / 1000 * $qty;
	} else {
		$total_price = $products_price * $qty;
	}
	  $products_weight = $product['products_weight'];
// EOF Separate Pricing Per Customer, Price Break 1.11.3 mod
	  $this->weight += ($qty * $products_weight);
	  $this->total += $total_price;
	}
  }
}

function get_products() {
	global $languages_id;
// BOF Separate Pricing Per Customer v4, Price Break 1.11.3 modification
  if (!is_array($this->contents)) return false;
  $pf = new PriceFormatter;

  $products_array = array();
  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
  if ($products = $pf->loadProduct($products_id, $languages_id)) {
	  $products_price = $pf->computePrice($this->contents[$products_id]['qty']);

	  if ($this->attributes_price($products_id) > 0) {
		  $temp_product_price = $products_price * $this->attributes_price($products_id);
		  $total_product_price = $temp_product_price / 1000;
	} else {
		$total_product_price = $products_price;
	}
// EOF Separate Pricing Per Customer v4, Price Break 1.11.3 modification	  
	  $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' => $total_product_price,
								'tax_class_id' => $products['products_tax_class_id'],
								'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
	}
  }

 

Is there anybody who can help me to make the the following code handle attributes in the same way as the above code ... or maybe explain to me which sections of this does what with the attributes?

 

	function restore_contents() {
  global $customer_id;

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

// insert current cart contents in database
  if (is_array($this->contents)) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  $qty = $this->contents[$products_id]['qty'];
	  $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	  if (!tep_db_num_rows($product_query)) {
		tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $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 = '" . $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();
}

 

Many thanks in advance

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...