Guest Posted April 10, 2005 Posted April 10, 2005 Anyone able to suggest to change the prefix other than + and -. Would I need to edit some code to do this. I need an option where I need to multiply the cost with a option. Thanks in advance for any help offered.
avoisin Posted April 10, 2005 Posted April 10, 2005 Well, there's no easy way to do it, since because you can have multiple attributes on one product, how you handle the order of operations is going to become important! I took a shot at the functionality you're looking for though. This is all untested, just off the cuff, so let me know. And don't even ask for divide too! In the classes directory, in shopping_cart.php, change this: // attributes price if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); $attribute_price = tep_db_fetch_array($attribute_price_query); if ($attribute_price['price_prefix'] == '+') { $this->total += $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); } } } } } 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; } to this: // attributes price if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); $attribute_price = tep_db_fetch_array($attribute_price_query); if ($attribute_price['price_prefix'] == '+') { $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax); } else if ($attribute_price['price_prefix'] == '*') { $this->total += $qty * tep_add_tax(($products_price * ($attribute_price['options_values_price'] - 1)), $products_tax); } else { $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax); } } } } } function attributes_price($products_id) { $attributes_price = 0; $multiplier = 1; 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 if ($attribute_price['price_prefix'] == '*') { $multiplier *= $attribute_price['options_values_price']; } else { $attributes_price -= $attribute_price['options_values_price']; } } } $attributes_price *= $multiplier; return $attributes_price; }
Guest Posted April 10, 2005 Posted April 10, 2005 Thanks, Ill give this a shot, and let you know how well it performs.
Guest Posted April 10, 2005 Posted April 10, 2005 It seems to minus the * value. Reading your code seems fine, but Im guessing Im over looking something.
avoisin Posted April 10, 2005 Posted April 10, 2005 It seems to minus the * value. Reading your code seems fine, but Im guessing Im over looking something. <{POST_SNAPBACK}> It's possible the * didn't get stored as that in the database, since it's kind of a wildcard flag. Can you check the actual record in the database to see what it looks like there? When I get some more time I can check it out for real.
Guest Posted April 10, 2005 Posted April 10, 2005 True I did not think to look. Ive split my product into 4 diff items for now, as they monthly based ive gone for 1,3,6,12 monthly subcriptions. I think this is the only way Ill be able to do it. My current cart looks like this http://www.fpsclanservers.net/index.php?open=games_shop. Its been written from scratch and I want to move to a more professional looking one.
avoisin Posted April 10, 2005 Posted April 10, 2005 True I did not think to look. Ive split my product into 4 diff items for now, as they monthly based ive gone for 1,3,6,12 monthly subcriptions. I think this is the only way Ill be able to do it. My current cart looks like this http://www.fpsclanservers.net/index.php?open=games_shop. Its been written from scratch and I want to move to a more professional looking one. <{POST_SNAPBACK}> Well, for your situation I think what you did is the right way to go anwyay. They seem like really different products, I think it makes sense to differentiate them as you suggest. osCommerce is pretty easy to get up and running, once you've played with it for a while.
Guest Posted April 11, 2005 Posted April 11, 2005 Yeah I agree its a nice piece of software. I just need to find a suitable template or make my own to fit in with my site. Thanks for your help. I may revisit this issue later when I have more time. Just out of interest is it easy to auto add-up the price on the fly whilst changing the product options? So a customer can see the price addup before they add it to the cart.
avoisin Posted April 11, 2005 Posted April 11, 2005 Just out of interest is it easy to auto add-up the price on the fly whilst changing the product options? So a customer can see the price addup before they add it to the cart. <{POST_SNAPBACK}> No. It would take some effort with javascript to do something like that. I've made modifications like that, and it isn't trivial, there's a few places you need to change the code. Probably take a few hours work.
oscommerceking Posted June 1, 2005 Posted June 1, 2005 No. It would take some effort with javascript to do something like that. I've made modifications like that, and it isn't trivial, there's a few places you need to change the code. Probably take a few hours work. <{POST_SNAPBACK}> Any idea if you got the multiplier functionality to work, i have trouble when adding more than one product to the cart with a attribute that is a multiple or percentage It adds the first item and multiplies it by the first attribute correctly and then the second multiplier is multiplied by that total (which has already been multiplied) and then times the 2nd item and adds them together So it just adds to the problem for each item you add with a muliplier atty Thanks so much J My Contributions: Add Search + Drop Down Anywhere, Eliminate Subcategories in Drop Down
Recommended Posts
Archived
This topic is now archived and is closed to further replies.