Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How do I create a new order total module?


hb_cmcl

Recommended Posts

I've added a custom field to the "products" and "orders_products" table -- it's a field to associate a certain dollar amount with each product (it's NOT the item's cost, price, any kind of discount, special pricing, or the profit amount -- it's a custom thing for a client). For example, Item Whatever has a selling price of $15.00, but an additional field showing a value of $2.50 associated with that item. If somebody buys two of them, they will pay $30.00, but the "orders_products" table will also log a value of $5.00 in that custom field. Item Someotherthing is $12.00 with a custom field amount of $1.25. Somebody buys three of them, they'll pay $36.00 but the total custom field amount will be $3.75.

 

I would like to add a new order total module so that the total of those particular dollar amounts in the custom field will appear in the "orders_totals" table along with the subtotal, ot_total, etc. amounts for each order that is placed. It's totally separate from the order total but I want to be able to display the amount at checkout. Like, if somebody bought all five items mentioned above, their order total would be $66.00 and their custom field total would be $8.75. This is totally separate from the order total and doesn't need to be added or subtracted or calculated against any other values in any way.

 

I've looked at the contributions for order total modules, but they all seem to be either based on the order total in some way, or based on shipping/tax/discounts of some sort. Is there a simple way (oh please, let there be a simple way) for me to basically just copy the order total module for this custom field, so that I can get per-order totals of this field?

Link to comment
Share on other sites

Can you explain a little about what you are actually trying to get from this?

 

I think there may be another way depending on what you need from it.

 

Rob

Rob Bell - Inspired Graphix

Customising osCommerce in Australia, and the world!

View my profile for web and email links.

 

I'm sorry, but i cannot offer Free support via PM etc, and osCommerce forums prohibit me from putting any reference to paid support in my signauture.

However viewing my profile may provide links to my website or something like that which you may find useful.

Link to comment
Share on other sites

It sounds strange, I know. Each product in the store has a price, and also a separate dollar amount associated with it -- like I said, it's a custom thing for the client. It's not related to the price or cost of the item at all, it's just this totally separate thing floating out there for each product. It's not included in the order total, and the customer doesn't pay it.

 

So Item Whatever sells for $15.00 and its associated "custom" amount is $2.50. That field has been added to the "products" table, and it's part of the entry form when we add a new product to the catalog, along with the product's price.

 

Also, every time somebody buys Item Whatever, the "orders_products" table logs both of those values (the price and the custom amount), along with the number of items the person bought. (I modified the update query in checkout_process.php so it would include that field.)

 

Come checkout time, the total price of all the items purchased is logged in the "orders_totals" table -- the "class" field being "ot_subtotal" and the "value" field being the actual dollar amount total. Shipping charges are also logged and all those are totaled up in "ot_total."

 

I want the "orders_total" table to also record the total of this custom field, but separately from the "ot_subtotal" and "ot_total." So if somebody buys three of Item Whatever, the "ot_subtotal" will be $45.00, there'll be shipping charges, and the "ot_total" field will be the actual total amount the customer will pay. The other field, let's say "ot_custom," will be $7.50 (customer does not pay this amount). Again, it's totally separate from the actual order and must not be added to the order total, or calculated in relation to the order total in any way.

 

And ideally, this custom total will be displayed to the customer on checkout, alongside (but still separate from) the order total. I also want to use this "ot_custom" total for recordkeeping/reporting purposes in the backend for the client. I know I can do special queries for display purposes, like "SELECT SUM(orders_products.products_quantity * orders_products.products_custom) " etc., but it would be nice to have the actual total recorded in the db for simplicity, so I can just call up that one field, like I can for the "ot_total."

Link to comment
Share on other sites

I've been playing around with this a little more and and might be getting close -- looking at this (pretty old) contribution I thought I'd try to just create a new order total module. What I did was basically take \includes\modules\order_total\ot_subtotal.php and \includes\languages\english\modules\order_total\ot_subtotal.php and saved them each as ot_custom.php, and altered all the "MODULE_ORDER_TOTAL_SUBTOTAL_ETC" parts to be "MODULE_ORDER_TOTAL_CUSTOM_ETC."

 

This might be where I start to get thrown off -- the following is what I have in \includes\modules\order_total\ot_custom.php for the process() function:

	function process() {
  global $order, $currencies;

  $this->output[] = array('title' => $this->title . ':',
						  'text' => $currencies->format($order->info[custom], true, $order->info['currency'], $order->info['currency_value']),
						  'value' => $order->info[custom]);
}

 

Now, over in \includes\classes\order.php, I made some more changes.

 

		$this->products[$index] = array('qty' => $orders_products['products_quantity'],
								'id' => $orders_products['products_id'],
									'name' => $orders_products['products_name'],
									'model' => $orders_products['products_model'],
									'tax' => $orders_products['products_tax'],
									'price' => $orders_products['products_price'],
									// Below line added for custom total
									'custom' => $orders_products['products_custom'],
									'final_price' => $orders_products['final_price']);

(Added the custom field to the array there)

 

		$this->products[$index] = array('qty' => $products[$i]['quantity'],
									'name' => $products[$i]['name'],
									'model' => $products[$i]['model'],
									'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
									'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
									'price' => $products[$i]['price'],
									// Below line added for the custom total
									'custom' => $products[$i]['custom'],
									'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']),
									'weight' => $products[$i]['weight'],
									'id' => $products[$i]['id']);

 

(And added to that array.)

 

	  $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
					  'currency' => $currency,
					  'currency_value' => $currencies->currencies[$currency]['value'],
					  'payment_method' => $payment,
					  'cc_type' => '',
					  'cc_owner' => '',
					  'cc_number' => '',
					  'cc_expires' => '',
					  'shipping_method' => $shipping['title'],
					  'shipping_cost' => $shipping['cost'],
					  'subtotal' => 0,
					  // The below line is being added to create a total for the custom amount.
					  'custom_total' => 0,
					  'tax' => 0,
					  'tax_groups' => array(),
					  'comments' => (tep_session_is_registered('comments') && !empty($comments) ? $comments : ''));

 

(And added to that array.)

 

Down around line 317, where this part is:

		$shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);
	$this->info['subtotal'] += $shown_price;

 

Below that, I added this:

		$custom_price = $currencies->calculate_price($this->products[$index]['custom'], $this->products[$index]['tax'], $this->products[$index]['qty']);
	$this->info['custom_total'] += $custom_price;

 

Now, when I place an order, there is indeed a "ot_custom" field being added to the "orders_totals" table, and it's displaying on the checkout page, but the dollar amount keeps coming up zero. I'm sure I need to change something somewhere where it will calculate the amounts, probably in the order.php file -- that little part I added at the bottom, the $custom_price part, do you think that's where the problem lies? Or is there more I would need to change for this to work?

 

I feel like I'm sooooo close to getting this, and hoping there's just one simple little missing line somewhere I can add.

Link to comment
Share on other sites

Success! Turns out I had one little thing wrong, in the process() function -- instead of $order->info['custom_total'] I had $order->info['custom']. Once I fixed that, it works fine now, both on the checkout screen and in the backend of things.

 

Who knows, maybe me talking myself through this will help someone else down the road with something similar... :)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...