Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

amalgamate 2 add ons in one file...


bigbird_3156

Recommended Posts

Hi I want to amalgamate 2 sections of code so that they work together ... they are from the addons of 'actual attributes price' and 'add weight to product attributes'....

 

I am modifying the includes/classes/shopping_cart.php file... I have narrowed the difference down to the following 2 pieces of code...

 

The first bit is the one I am currently using...

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// BOF - AAP V1.0 - updated to account for no price prefix to equal actual price
// attributes price
	if (isset($this->contents[$products_id]['attributes'])) {
	  reset($this->contents[$products_id]['attributes']);
	  while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		$attribute_price = tep_db_fetch_array($attribute_price_query);
		$price_prefix = $attribute_price['price_prefix'];
		$option_price = $attribute_price['options_values_price'];
		  $products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
		  $products_stuff = tep_db_fetch_array($products_query);
		  $products_price = $products_stuff['products_price'];
		if ($price_prefix == '+') {
		$this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
		}
		  if ($price_prefix == '-') {
		  $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
		}
			if ($price_prefix == '') {
			$this->total += $qty * tep_add_tax(tep_adjust_price($option_price, $products_price), $product_tax);
		}
	  }
	}
  }
}

// subtotal function for attributes price
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);
	  $price_prefix = $attribute_price['price_prefix'];
	  $option_price = $attribute_price['options_values_price'];
		$products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
		$products_stuff = tep_db_fetch_array($products_query);
		$products_price = $products_stuff['products_price'];
	  if ($price_prefix == '+') {
	  $attributes_price += $option_price;
	  }
		if ($price_prefix == '-') {
		$attributes_price -= $option_price;
	  }
		  if ($price_prefix == '') {
		  $attributes_price += tep_adjust_price($option_price, $products_price);
	  }
	}
  }
  return $attributes_price;
}
// EOF - AAP V1.0
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

 

this second bit is the code I want to amalgamate into it...

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

I have bracketed the sections in this section of code with *** to point out the bits I think I need to amalgamate to make this work but as yet I have not been able to make it do so...

 

does anyone want to give it a go or give me some tips on what I could do to get this to work????

 

thanks

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...