Writing query in Oxorder


#1

Hi,

I have created one php page for payment and in that page I need to put one query to insert datas into the oxorder table when an order is placed. I don’t know how to give values to OXID in oxorder table using INSERT INTO function.I think the OXID in oxorder table is not set as auto increment too.

When I wrote the query as INSERT INTO oxorder(OXSHOPID, OXUSERID) VALUES ('value1, ‘value2’), The values got inserted into the table but the oxid was empty.

Is it possible to update the orders section details in oxid admin from database?


#2

Hi @reshmiarm,

I just wonder why you don’t use the OXID framework at all. Did you find the source code documentation yet? Also, there’s a post available “OXID models: Getting, updating and storing database data” here: https://oxidforge.org/en/oxid-models-getting-updating-and-storing-database-data.html (will clean up the code immediately…

Cheers


#3

Thank you Mr. Marco. In all other files , I am using the oxid framework. But here I need the mysql query to insert values directly into the oxorder table. I don’t know how to insert the vales into the oxid field.

Its very urgent and is highly appreciable if could help in writing the query.

Thanks in advance.


#4

Hope this is helpful, mate. oxID can be set as you want as long as it is unique. When entering data via admin, a random number is used, triggered by a method that I can’t find presently. If you have to enter data from outside, please use either this method in the OXID framework or any other tag/number as long as you’re sure it remains unique.

Cheers!


#5
$oxid = "6346363635634564634"; //oxid of your order
$oDb = oxDb::getDb();
$oDb->execute("INSERT INTO `oxorder`(`OXID`,`OXSHOPID`, `OXUSERID`) VALUES ('{$oxid}','value1', 'value2') ");

Should do it.


#6

Thanku. This query really works. But the oxid is an autoincrement unique value. so we cannot enter any value in the oxid field. When each order is placed, an entry shouldbe created in the oxorder table with oxid. Here in this case how can I do?

If I directly enter a value for oxorder table from database why that values is not showing on the oxadmin - Administrative Orders -orders section.

Please help me with a solution for this .


#7

unique YES
autoincrement NO

OK, if I understand it correctly, you want to update a field in an existing order and not write a new order (INSERT). The following should work for this:


$oxid = "6346363635634564634"; //oxid of existing order 
$oOrder = oxNew( "oxorder" );
$oOrder->load( $oxid );
$oOrder->oxorder__oxshopid->setValue( "value1" );
$oOrder->save();

If you want to do it with SQL, use e.g.

update oxorder set oxshopid='value1' where oxid='{$oxid}'

#8

There should be a method that creates those OXIDs, right?


#9

Indeed. In the Class “UtilsObject” there is a method called “generateUId” which creates the OXID.