Re: how do I require application_top.php in folder in admin with a composer package?
Agree with DrByte that PHPStorm is worth trying/using. I have/use it when I need to do some more "intricate" review, coordination, evaluation though more frequently I enter code directly I'll say into the file. Like anything there is a learning curve and to say the least it is very powerful. Back in the day I had used some other IDEs the names of which I forget, but its great to have the additional tools of code completion, assignment/use lookup, it even has a git interface though I have a separate tool that I have come to like because with that tool I can also visually look through the history of the commits, see my branches, do branch/commit comparison, etc...
As to the question about the order creation. Again, it is good to indicate what is it that you are trying to understand or question to answer? Some questions that come to mind is, do you just want to see what data needs to exist prior to initiating creation, do you want to see how the order gets created, how its used after it was created, everything?
Because no pre-knowledge is identified, what I would suggest is to start using and becoming familiar with the Developers Tool Kit found under the admin's tools menu. The broadest search capability is found in the lower row of that tool. For order related information, I would suggest to start searching on "new order" (without the quotes) May even want to narrow it down to: "= new order" such that text with just the first phrase doesn't appear in the search. Then I suggest also changing the number of lines above/below to at least a value of 3 instead of the default of 0. (BTW, that is a default in the file admin/developers_tool_kit.php that can be changed at/around line 10 of the file.)
Once you find instances of that text, you can 1) follow the logic of the class' constructor as to which way it goes and what is available, 2) work backwards to see what was done to get to that point and how other classes and code work together to get there.
And lest didn't know/realize, help spills out when it is seen what has been tried, what is working, what is wanted, what doesn't work, etc... One thing seen (and I've said something similar before), those that show that they are trying to help themselves get help even with things that are difficult to accomplish.
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
Where's the best place to look for order creation using the order class? I've been skimming the class and the one page checkout add-on...
When customers are shopping via their browser, products get added to the cart using data submitted from product-listing page forms or buy-now-button-links, which trigger some functions in the shopping_cart class via:
https://github.com/zencart/zencart/b...ns.php#L42-L56
Then during checkout, the checkout_process "page" calls the checkout_process "module", and essentially creates the new order using all the collected data from the customer's choices (cart contents, shipping/payment selections, applying discounts and taxes).
https://github.com/zencart/zencart/b...header_php.php
https://github.com/zencart/zencart/b...ut_process.php
Re: how do I require application_top.php in folder in admin with a composer package?
i need to still look into the last 2 replies but I skimmed code for a few hours this morning and really the only issue with...
Code:
$insertOrderSql = "INSERT INTO " . TABLE_ORDERS .
"(orders_id, customers_id, customers_name, payment_method, payment_module_code, shipping_method, shipping_module_code, date_purchased, orders_status, currency, currency_value, order_cogs, order_total, order_tax)" .
" VALUES ('".$newoID."','429', 'Amazon Gmail Import','Amazon Payments', 'amazon', 'Store Pickup (Walk In)', 'storepickup', '" . $newdate . "', 1, 'USD', '1.000000', '".$_POST['Cogs']."', '".$_POST['SoldFor']."', '0.0000');";
$insertOrdersTotalsSubsql = "INSERT INTO " . TABLE_ORDERS_TOTAL .
"(orders_id, title, text, value, class, sort_order)" .
" VALUES ('". $newoID . "', 'Sub-Total:', '$".$_POST['SoldFor']. "', '".$_POST['SoldFor']. "', 'ot_subtotal', '100');";
$insertOrdersTotalsShipSql = "INSERT INTO " . TABLE_ORDERS_TOTAL .
"(orders_id, title, text, value, class, sort_order)" .
" VALUES ('". $newoID . "', 'Amazon Shipping:', '$".$_POST['Ship']. "', '".$_POST['Ship']. "', 'ot_shipping', '200');";
$insertOrdersTotalsSql = "INSERT INTO " . TABLE_ORDERS_TOTAL .
"(orders_id, title, text, value, class, sort_order)" .
" VALUES ('". $newoID . "', 'Total:', '$".$_POST['SoldFor']. "', '".$_POST['SoldFor']. "', 'ot_total', '999');";
$insertOrdersStatusSql = "INSERT INTO " . TABLE_ORDERS_STATUS_HISTORY .
"(orders_id, orders_status_id, date_added, comments)" .
" VALUES ('". $newoID . "', '3', '" . $newdate . "', '" . $orderData . "');";
$insertOrdersProdsSql = "INSERT INTO " . TABLE_ORDERS_PRODUCTS .
"(orders_id, products_id, products_model, products_name, products_price, products_cost, final_price, products_tax, products_quantity)" .
" VALUES ('". $newoID . "', '".$_POST['Pid']."', '".$_POST['Model']. "', '".$_POST['Skus']. "', '".$_POST['SoldFor']. "', '".$_POST['Cogs']. "', '".$_POST['SoldFor']. "', '0.0000', '".$_POST['Quan']. "');";
$insertOrdersAmazonSql = "INSERT INTO `orders_amazon` " .
"(orders_id, orders_id_amazon, orders_amazon_status, orders_amazon_earnings, orders_amazon_shipping)" .
" VALUES ('".$newoID."','".$_POST['AmazonOrderId']."', '".$status."','".$_POST['Earn']."', '".$valueShipWePaid."');";
...followed by the respective globe db->execute's ...is just setting the orderID/$oID
I found a tab in phpmyadmin to change up the auto-increment. I've experimented w/ the store manager reset next Order ID and manually editting all order tables back, however the auto-increment field in phpmyadmin doesn't want to change, it throws ...
Code:
"Error
SQL query: Copy Edit Edit
FLUSH PRIVILEGES;
MySQL said: Documentation
#1030 - Got error 176 "Read page with wrong checksum" from storage engine Aria "
...I spent some time trying to repair tables twice from stackexchange or overflow, but to no avail.
Re: how do I require application_top.php in folder in admin with a composer package?
this is the groaner section of code I need to objectify ;)
Code:
//THIS BLOCK IS HOW IT SHOULDN'T BE
$otherSql = " SELECT LAST_INSERT_ID();";
$newoIDResult = $db->Execute($otherSql);
$newoID = $newoIDResult->fields['LAST_INSERT_ID()'];
$testsql = "SELECT * FROM `orders`";
$db->Execute($testsql);
$newoID_part2 = $db->Insert_ID();
echo '$newoID_part2 is ' . $newoID_part2;
$insertOrderSql = "INSERT INTO " . TABLE_ORDERS .
"(orders_id, customers_id, customers_name, payment_method, payment_module_code, shipping_method, shipping_module_code, date_purchased, orders_status, currency, currency_value, order_cogs, order_total, order_tax)" .
" VALUES ('".$newoID."','429', 'Amazon Gmail Import','Amazon Payments', 'amazon', 'Store Pickup (Walk In)', 'storepickup', '" . $newdate . "', 1, 'USD', '1.000000', '".$_POST['nameCogs']."', '".$_POST['nameSoldFor']."', '0.0000');";
//END - THIS BLOCK IS HOW IT SHOULDN'T BE
this code "works" but it jumped my order_id count by like 60,000?!
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
this is the groaner section of code I need to objectify ;)
Code:
//THIS BLOCK IS HOW IT SHOULDN'T BE
$otherSql = " SELECT LAST_INSERT_ID();";
$newoIDResult = $db->Execute($otherSql);
$newoID = $newoIDResult->fields['LAST_INSERT_ID()'];
$testsql = "SELECT * FROM `orders`";
$db->Execute($testsql);
$newoID_part2 = $db->Insert_ID();
echo '$newoID_part2 is ' . $newoID_part2;
$insertOrderSql = "INSERT INTO " . TABLE_ORDERS .
"(orders_id, customers_id, customers_name, payment_method, payment_module_code, shipping_method, shipping_module_code, date_purchased, orders_status, currency, currency_value, order_cogs, order_total, order_tax)" .
" VALUES ('".$newoID."','429', 'Amazon Gmail Import','Amazon Payments', 'amazon', 'Store Pickup (Walk In)', 'storepickup', '" . $newdate . "', 1, 'USD', '1.000000', '".$_POST['nameCogs']."', '".$_POST['nameSoldFor']."', '0.0000');";
//END - THIS BLOCK IS HOW IT SHOULDN'T BE
this code "works" but it jumped my order_id count by like 60,000?!
Ok.. Couple of things... The orderID is an auto_increment field... It doesn't need to be set when adding to the "orders" table ... By inserting a new row of data (suggest excluding the orders_id in that insert), the data is entered into the table at the point next following the LAST_INSERT_ID...
Even with that in mind, note that calling $db->Insert_ID() asks for the system to return the id (whatever it was) that was last inserted... That insert could be from anything that previously happened but in the above code, an insert hasn't occurred until the query generated two lines later is actually executed.
Then, also for database protection, the posted data (e.g. $_POST['nameCogs'] should be treated/handled to ensure that something isn't injected that could cause an issue. There are a number of ways to handle/address, but it is never a good idea to insert into a database the exact content from user's input without some sort of data validation/sanitization. The level of that sanitization is often questionable, but you want to protect the existing database, ensure that when the data is accessed that it doesn't support some undesirable action and while processing the insertion that something malicious doesn't happen.
If you wanted to obtain the orders_id for this new record, then after $insertOrderSql is processed (next action that could possibly touch the database) the $newoID_part2 = $db->Insert_ID() function should be called... If some other database action is performed that inserts data (say a possible notifier action, a page change, another data insertion) then the returned value will represent the id of whatever record was inserted into whatever table was accessed...
Basically for the above insert sql, remove the field orders_id from the first item after the initial quote and also remove it from the first values part.
Ohhh... And another thing, add a space before the opening parentheses of the text that follows TABLE_ORDERS .
Not having that space between the end of the table's name and before the opening parentheses could cause a SQL issue...
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
mc12345678
Ok.. Couple of things... The orderID is an auto_increment field... It doesn't need to be set when adding to the "orders" table ... By inserting a new row of data (suggest excluding the orders_id in that insert), the data is entered into the table at the point next following the LAST_INSERT_ID...
Even with that in mind, note that calling $db->Insert_ID() asks for the system to return the id (whatever it was) that was last inserted... That insert could be from anything that previously happened but in the above code, an insert hasn't occurred until the query generated two lines later is actually executed.
Then, also for database protection, the posted data (e.g. $_POST['nameCogs'] should be treated/handled to ensure that something isn't injected that could cause an issue. There are a number of ways to handle/address, but it is never a good idea to insert into a database the exact content from user's input without some sort of data validation/sanitization. The level of that sanitization is often questionable, but you want to protect the existing database, ensure that when the data is accessed that it doesn't support some undesirable action and while processing the insertion that something malicious doesn't happen.
If you wanted to obtain the orders_id for this new record, then after $insertOrderSql is processed (next action that could possibly touch the database) the $newoID_part2 = $db->Insert_ID() function should be called... If some other database action is performed that inserts data (say a possible notifier action, a page change, another data insertion) then the returned value will represent the id of whatever record was inserted into whatever table was accessed...
Basically for the above insert sql, remove the field orders_id from the first item after the initial quote and also remove it from the first values part.
Ohhh... And another thing, add a space before the opening parentheses of the text that follows TABLE_ORDERS .
Not having that space between the end of the table's name and before the opening parentheses could cause a SQL issue...
And remember, the order class takes care of all this internally :)
Re: how do I require application_top.php in folder in admin with a composer package?
Thanks again for the input! This morning's endeavor shall be to create the simplest one order manually insertion php script using the order class.
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
Thanks again for the input! This morning's endeavor shall be to create the simplest one order manually insertion php script using the order class.
To re-emphasize what DrByte said and in light of all the sql that was written, if all of the data already exists in the "system" to support creating an order, then there are a number of ways to either modify the existing order (previously placed) or to incorporate data into the processing of the order as it is being generated... First, this really goes back to the earlier questioning about what is needed/desired to be done and in a way when it is to be done.
So for example, if you are really wanting to incorporate new fields into the order as the order is being placed, then you would want to tap into the notifiers in the create method to effectively update the information for that order if updating just the orders table, the orders_totals table, and/or the orders_status_history table
. There are also notifiers in the create_add_products method to be able to directly address fields in the orders_products table, orders_products_attributes table, and/or orders_products_downloads table.
What this allows is for you to create a similar array format, use the provided information of the "just added" information and do an update on the associated table to incorporate your additional information and then possibly later perform some additional action....
I don't readily have an example of doing such an update because where I have used this process I added data to a table that was created to support the associated software instead of modifying the default store database format. But that said, the zen_db_perform function is found at the following link: https://github.com/zencart/zencart/b...atabase.php#L2
Where it is possible to see the layout of the call "definition":
Code:
function zen_db_perform($table, $data, $action = 'insert', $parameters = '') {
Re: how do I require application_top.php in folder in admin with a composer package?
Confused on how to actually add the order object to the database. Here's a super basic version of what I currently have:
https://github.com/wolfderby/simple_admin_insert_order
I just started looking into
zen_db_perform('TABLE_ORDER ... ?
when I was called to family breakfast.
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
Confused on how to actually add the order object to the database. Here's a super basic version of what I currently have:
https://github.com/wolfderby/simple_admin_insert_order
I just started looking into
zen_db_perform('TABLE_ORDER ... ?
when I was called to family breakfast.
Added comments of various importance (several don't affect operation, they are just different ways of doing the same thing). They can be seen at: https://github.com/wolfderby/simple_...a2f7fbe2780R26
From what I see overall, with what you're doing the order isn't being created it is being retrieved from the database, modified and then presumably "restored" back to the database... If the goal is to create a **new** order, then as described in the comments a different approach is needed when processing the posted data.