Jump to content



Latest News: (loading..)

- - - - -

tep_db_insert_id() resulting in 0 in checkout_process.php


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1   smartwork

smartwork
  • Members
  • 199 posts

Posted 28 October 2011 - 03:12 PM

I'm working on a beta site where the catalog is in one database and the orders are written to another.  I've got it almost complete, but here is one thing I'm running into.  For a product that is ordered with attributes, orders_products_id is being written as zero in the table orders_products_attributes which causes the ordered attributes not to be associated with the intended product.  I've narrowed it down to this section in checkout_process.php

	tep_db_query_catalog("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
	$sql_data_array = array('orders_id' => $insert_id,
							'products_id' => tep_get_prid($order->products[$i]['id']),
							'products_model' => $order->products[$i]['model'],
							'products_name' => $order->products[$i]['name'],
							'products_packaged_components' => $order->products[$i]['packaged_components'],
							'products_price' => $order->products[$i]['price'],
							'final_price' => $order->products[$i]['final_price'],
							'products_tax' => $order->products[$i]['tax'],
							'products_quantity' => $order->products[$i]['qty']);
	tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
	$order_products_id = tep_db_insert_id();


The first query updates the bestsellers table.  Note "tep_db_query_catalog" which is for the catalog database.  Further down, the "tep_db_perform" is for the orders database.  With the "tep_db_insert_id" being immediately following, it should be taking the auto_increment value for orders_products_id from the previous line... but it's not.  It's writing zero which I'm assuming because it's perhaps using the connection to the catalog database.  I've tried using tep_db_insert($$link) to specify the connection, but have the same result.

Anyone have any tips on how I can ensure it's using the right connection so I'll actually get the last auto_increment id value that was inserted in the tep_db_perform line?

Thanks!

#2   alman

alman
  • Members
  • 39 posts

Posted 14 May 2012 - 09:07 PM

I had the same problem and there has been no solution on the forum that I have found.
so as a work around on checkout_process.php
find
		tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
		$order_products_id = tep_db_insert_id();

and replace with
 tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
	   // $order_products_id = tep_db_insert_id();

$insert_id_query = tep_db_query("SELECT orders_id from ".TABLE_ORDERS." WHERE customers_id = '" . (int)$customer_id . "'");
$insert_id_fetched = tep_db_fetch_array($insert_id_query);
$insert_id = $insert_id_fetched['orders_id'];

hope this helps someone

AL

Edited by alman, 14 May 2012 - 09:07 PM.