Database Table Question: cscart_new_orders

Does anyone have any idea what the purpose of cscart_new_orders table is? Why does it exist? I can't figure out what its being used for to know if i should be utilizing it in my order import addons.

It appears to be for twigmo. I think it has to do with who has rights to view an order but not sure.

The data in this table is obnoxious.

Each new order_id is listed 1000 times - once for each customer_id. It currently has over 75,000 rows in it for 75 order numbers.

I'm backing it up, truncating it and testing.

If it's for Twigmo - I disabled Twigmo a month ago. If it controls rights - it's broken anyway.

Wow yeah mine has 956k records. Anyone else have any clue if I can truncate it safely?

Ran in to some problems with our database and was reviewing the tables. This one is 165k on ours. The funny part is I only turned on twigmo for a few hours before I realized how much I hated it. Has anyone truncate or emptied the file yet?

We have never used twigmo so that table must be for something else.

From a quick review of fn.cart.php it appears that it has to do with tracking of orders or otherwise relating an order to an admin user_id.



It appears that when an order is created that a record for every (current) admin user_id is inserted (one line per admin per order).

From what I can see, twigmo is the only “consumer” of this info. Sad thing is that since the only consumer is an addon, it should be done with a hook, not directly integrated into the fn.cart.php file. But then they tend to do that to make their addon development easier.



If you don't use twigmo, you can probably comment out the code in fn.cart.php and truncate the table.



//
// Place the order_id to new_orders table for all admin profiles
//
if (!$parent_order_id) {
$condition = '';
if (PRODUCT_TYPE == 'MULTIVENDOR') {
$condition = empty($order['company_id']) ? ' AND company_id = 0 ' : fn_get_company_condition('company_id', true, $order['company_id'], true);
}
$admins = db_get_fields("SELECT user_id FROM ?:users WHERE user_type = 'A' $condition");
foreach ($admins as $k => $v) {
db_query("REPLACE INTO ?:new_orders (order_id, user_id) VALUES (?i, ?i)", $order_id, $v);
}
}

Thanks for all that info ill be taking a look at it further.

Has anyone actually cleared out this file?

I did. I truncated the table last week.

For each new order, the fn.cart.php script still inserts a row for each user (not just for each admin user). Truncating (emptying) the table had zero impact on the store's front end and/or back end.

I can find no reason for the table at all for function in the store proper. I do agree with tbirnseth though, the logic does appear to be for WHICH Twigmo users have access to the order, but I only have one admin user, so it's either got a bug, or Twigmo uses this table to give ALL users access to ALL orders - and that doesn't make any sense.



I'm reporting this in the Bug Tracker.



I have Twigmo disabled.

Should only be admin users (or users with user_type == 'A') according to the code.

My fn.cart.php script for ver3.0.3 is different. The where clause is missing (unless you are using the MultiVendor edition.)


// Place the order_id to new_orders table for all admin profiles
//
if (!$parent_order_id) {
$condition = '';
if (PRODUCT_TYPE == 'MULTIVENDOR') {
$condition = empty($order['company_id']) ? "AND user_type = 'A' AND company_id = 0 " : "AND user_type = 'V' " . fn_get_company_condition('?:users.company_id', true, $order['company_id'], true);
}
$admins = db_get_fields("SELECT user_id FROM ?:users WHERE 1 $condition");
foreach ($admins as $k => $v) {
db_query("REPLACE INTO ?:new_orders (order_id, user_id) VALUES (?i, ?i)", $order_id, $v);
}

yeah, I was referencing 2.2.4 so that would be a bug in my opinion… And that would make that table get really big, really fast for a mature store and if you “combined customers” in Ultimate, it could make it get even bigger…

Mine has about 600,000 strings! (the whole database has about 1,000,00 strings) and about 11 Mb :-). I have just truncated it - now I am waiting what will happen :-)

Fixed in next version.

See the fix in Bug Tracker:

[url=“http://forum.cs-cart.com/tracker/issue-3523-new-order-table-bug/”]http://forum.cs-cart.com/tracker/issue-3523-new-order-table-bug/[/url]

That link refers to version 3. It needs to be fixed in version 2! I'm not for sure about anyone else, but it may be some time before I upgrade to version 3…if I do at all. Not only do I want to mess with all the bugs in version 3, but I need to know which direction CS-Cart is going on the “1 version covers all” issue before I spend the time upgrading.

Jim, have you tried just commenting out the code block? I believe it is only used by twigmo…

References to “:new_orders” in V2.2.4 are only:


./addons/twigmo/func.php: $condition .= db_quote(" AND ?:new_orders.user_id = ?i", $params['admin_user_id']);
./addons/twigmo/func.php: $join .= " LEFT JOIN ?:new_orders ON ?:new_orders.order_id = ?:orders.order_id";
./core/fn.cart.php: db_query("REPLACE INTO ?:new_orders (order_id, user_id) VALUES (?i, ?i)", $order_id, $v);
./core/fn.cart.php: db_query("DELETE FROM ?:new_orders WHERE order_id = ?i", $order_id);
./core/fn.cart.php: $condition .= db_quote(" AND ?:new_orders.user_id = ?i", $params['admin_user_id']);
./core/fn.cart.php: $join .= " LEFT JOIN ?:new_orders ON ?:new_orders.order_id = ?:orders.order_id";
./controllers/admin/orders.php: db_query("DELETE FROM ?:new_orders WHERE order_id = ?i AND user_id = ?i", $_REQUEST['order_id'], $auth['user_id']);




Sure looks to me like twigmo is the only one that uses the data. If so, it shouldn't be hard-wired into the standard cart since twiggy is an addon.

my

[color=#00A8D5][size=6]cscart_new_order[/size][/color]



[color=#222222]is about 600MB after a few days. using twigmo.[/color]



[color=#222222]my total database is 700MB… [/color]