-
how do I require application_top.php in folder in admin with a composer package?
Buildling in https:127.0.0.1/mysite/admin/myAdminScript
how do I require admin/includes/application_top.php ?
I've tried...
require(https:
require(http:
require(127.
require(__DIR__ . DIRECTORY_SEPARATOR . '..'
require(../includes/application_top.php;);
require(DIR_FS_ADMIN ...1.3.7 style
not sure... just hoping I can require admin login to access an admin folder
question 2, gmail api uses composer to download a rather large vendor folder, compose remove myAdminScript/vendor should help me out, but currently my git repo has too many changes to tracks
trying: https://stackoverflow.com/questions/...ubset-of-git-f
any suggestions on that question 2 issue would be awesome, thanks!
-
Re: how do I require application_top.php in folder in admin on localhost?
Quote:
Originally Posted by
wolfderby
Buildling in https:127.0.0.1/mysite/admin/myAdminScript
how do I require admin/includes/application_top.php ?
I've tried...
require(https:
require(http:
require(127.
require(__DIR__ . DIRECTORY_SEPARATOR . '..'
require(../includes/application_top.php;);
require(DIR_FS_ADMIN ...1.3.7 style
not sure... just hoping I can require admin login to access an admin folder
If the file is in your admin directory, just use the same logic as all other files have in the admin folder (top level):
Code:
require('includes/application_top.php');
Part 2 of the question... Nope. :blink:
-
Re: how do I require application_top.php in folder in admin on localhost?
And parentheses not needed for require/include statements.
-
Re: how do I require application_top.php in folder in admin on localhost?
but a simple require('includes/application_top.php'); ends up w/ a Warning: require(includes/application_top.php): failed to open stream: No such file or directory in C:\... (because it's a xampp php server run on localhost aka my computer)
so... I need to move up a directory level in the admin, which has an obscured directory path.
-
Re: how do I require application_top.php in folder in admin on localhost?
there is no...
/mysite/admin/myAdminScript/includes/application_top.php
...it's in...
/mysite/admin/includes/application_top.php
-
Re: how do I require application_top.php in folder in admin on localhost?
this might have worked: require(realpath(__DIR__ . DIRECTORY_SEPARATOR . '../includes/application.php')); but now i'm getting An error occurred: { "error": "unauthorized_client", "error_description": "Unauthorized" } which I think is a credentials.json issue.
-
Re: how do I require application_top.php in folder in admin on localhost?
I run everything on xampp so it's not an issue with xampp, but your script.
Now, this seems to be an ajax something, happening from somewhere in your admin directory. This should still work just the same if both your main script file and the processing php file are in the admin root. Perhaps I missed one important part - Buildling in https:127.0.0.1/mysite/admin/myAdminScript - is myAdminScript a directory and then you have all of your php files inside that directory? Honestly, I've never done it like that because I couldn't get it to work either (probably something I don't know how to do), so I opted for the approach where the main php file and the ajax file are in admin root, and the rest of the files can be scattered around. Something like:
- /admin/my_script.php
- /admin/my_script_ajax.php
- /admin/myScriptFolder/everything_else
Either go that way, or wait for someone else to chip in and share their thoughts. Sorry.
-
Re: how do I require application_top.php in folder in admin on localhost?
What purpose is the additional admin sub-directory (/myAdminScript)? My localhost environments normally mimic the associated live site's directory structure, where the /admin sub-directory is at the same 'level' as the storefront /includes sub-directory.
-
Re: how do I require application_top.php in folder in admin on localhost?
Quote:
Originally Posted by
balihr
I run everything on xampp so it's not an issue with xampp, but your script.
Now, this seems to be an ajax something, happening from somewhere in your admin directory. This should still work just the same if both your main script file and the processing php file are in the admin root. Perhaps I missed one important part - Buildling in https:127.0.0.1/mysite/admin/myAdminScript - is myAdminScript a directory and then you have all of your php files inside that directory? Honestly, I've never done it like that because I couldn't get it to work either (probably something I don't know how to do), so I opted for the approach where the main php file and the ajax file are in admin root, and the rest of the files can be scattered around. Something like:
- /admin/my_script.php
- /admin/my_script_ajax.php
- /admin/myScriptFolder/everything_else
Either go that way, or wait for someone else to chip in and share their thoughts. Sorry.
seems like it might go that way then...
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
lat9
What purpose is the additional admin sub-directory (/myAdminScript)? My localhost environments normally mimic the associated live site's directory structure, where the /admin sub-directory is at the same 'level' as the storefront /includes sub-directory.
I'm not sure? first time using google api and composer > "composer require google/apiclient:^2.0"
-
Re: how do I require application_top.php in folder in admin with a composer package?
...seemed to be a google api vendor folder issue (:
-
Re: how do I require application_top.php in folder in admin with a composer package?
What's the purpose of adding this api? What are you building?
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
...seemed to be a google api vendor folder issue (:
^ignore this
I want to set up a cron job to remove my sold amazon inventory using the "Sold, ship now:" emails from amazon sellercentral.
-
Re: how do I require application_top.php in folder in admin on localhost?
Quote:
Originally Posted by
lat9
What purpose is the additional admin sub-directory (/myAdminScript)? My localhost environments normally mimic the associated live site's directory structure, where the /admin sub-directory is at the same 'level' as the storefront /includes sub-directory.
So are you saying I should just put it in admin/includes?
-
Re: how do I require application_top.php in folder in admin on localhost?
I seem to have it working, I needed to have just tried to copy the design patterns already within the admin instead of forcing through 1 require.
basically shooting for /admin/my_script.php
then...
/admin/includes/classes/custom.php
/admin/includes/functions/maybe.php
/admin/includes/modules/kindaConfusedOnThisDir.php
...when I get closer maybe I'll put it on gitLab and share it for some suggestions.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
I want to set up a cron job to remove my sold amazon inventory using the "Sold, ship now:" emails from amazon sellercentral.
Uhm... Why do you need to run it in admin then? If it's a cron job, and it's purpose is to adjust stock levels or update order statuses or something similar, why don't you run it from store root? Is there a specific reason why you're placing it in the admin directory?
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
balihr
Uhm... Why do you need to run it in admin then? If it's a cron job, and it's purpose is to adjust stock levels or update order statuses or something similar, why don't you run it from store root? Is there a specific reason why you're placing it in the admin directory?
I like the idea of putting the gmail api folder within an admin log-in, for assumed security reasons. Not sure if it'd be a risk or not really.
-
Re: how do I require application_top.php in folder in admin with a composer package?
...so when i try to move out the includes\gmail\credentials.json it creates a forbidden access 403 error for the .json file if I directly navigate to it, and I'm sure the path is correct.
-
Re: how do I require application_top.php in folder in admin with a composer package?
I'm basically trying to mash up this youtube series into the zen-cart admin: https://www.youtube.com/watch?v=j_ilbyXwIzI
if you follow that youtube series the code comes out like this: https://github.com/wolfderby/gmailTu...d_of_episode_6
-
Re: how do I require application_top.php in folder in admin with a composer package?
...within that folder composer (
Code:
composer require google/apiclient:^2.0
) builds out a /vendor folder dir w/ lots of the google api files
https://developers.google.com/gmail/api/quickstart/php
-
Re: how do I require application_top.php in folder in admin with a composer package?
Wait... Wait wait wait... Are you saying you're trying to build a script that sits on your server and connects to your Gmail account "just" so you could get it to read your Amazon emails, and then you'll use that data to modify your site's stock levels?
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
balihr
Wait... Wait wait wait... Are you saying you're trying to build a script that sits on your server and connects to your Gmail account "just" so you could get it to read your Amazon emails, and then you'll use that data to modify your site's stock levels?
That and generally to practice using API's. Amazon Sellercentral Pro's $40/mo. for the amazon seller api. :/
-
Re: how do I require application_top.php in folder in admin with a composer package?
currently the only way I can get it to work is w/ a folder in the admin w/ an index.php I'm guessing it's security stuff that's above me. I'm open to other suggestions on approaches. I was also considering trying to use tampermonkey to add a button in amazon sellercentral that send the data (maybe w/ json and some sort of http api end-point? (I don't know about this much yet))
-
Re: how do I require application_top.php in folder in admin with a composer package?
Maybe skip using the email API by:
- linking up an IfTTT (if-this-then-that) service (either forward those emails to it, or maybe it can inspect incoming emails for you)
- then the IfTTT service can be the thing that sends a notice to your server to do the cleanup (and then you just need a tiny cleanup listener script).
.. - that "notice" could be an HTTP call to a listener file (my_amazon_handler.php) that does the cleanup after some validation
.. - or maybe it could send the data as a CSV file (somehow), and you could have a cron job to loop thru all the received CSV files in whatever directory
Popular IfTTT services include ifttt .com, zapier, integromat
-
Re: how do I require application_top.php in folder in admin with a composer package?
IMHO, quite an overkill for what you actually need. Learning APIs is great, but Google's APIs are nowhere near simple or easy to integrate, and are definitely not something to start the learning process.
DrByte's solution is awesome (of course), but you could also have it run on your end without involving 3rd party apps. An idea that crossed my mind - setup a new email account on your server, let's say "[email protected]" and then configure your Gmail to automatically FW the amazon's "sold/ship" emails to that address. Next step would be to create your own script that uses imap_body and other imap_ functions to connect to the new email account and read the contents and then process it against the database. Run it from the admin, run it as a cron job, do whatever you want - it's relatively simple to process the data after you get the contents to your server...
-
Re: how do I require application_top.php in folder in admin with a composer package?
Re: Dr Byte's suggestions:
Cool I'm going to look into IFTTT I have a few of those going for other things not web dev related. Should watch a few introductions to zapier and integromate.
Re: balihr
This seems more robust than google's api auth token expiring and requiring a 2nd log in.
Before I had read those 2 replies my current pseudo code is this:
//Greasemonkey inject a button into sellercentral to pull the amount paid for shipping (not in email)
//button click launches "handler" maybe w/ orderid and shipping cost into the script page that launches the gmail api...
//loop through gmails w/ orderid search criterion
//parse
//inject order
...a question would then also be what's the easiest way to grab all the sql commands that happen when an order's placed? cleverly placed print_r in the db query factory?
Bahlir's seems to be right in I'm probably overly complicating this. Also wouldn't mind messing w/ square's API on another project before classes start back up depending on how productive I am w/ this.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Better yet ... does Amazon offer webhook notifications when something sells?
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
DrByte
Better yet ... does Amazon offer webhook notifications when something sells?
If I'm not mistaken they do, but it's to the tune of $40/mo for the API included w/ the professional selling account. I haven't been able to hit a level of success to justify it.
-
Re: how do I require application_top.php in folder in admin with a composer package?
So I have this mashed up and "working" (reading from my gmail and from an orders_amazon table I created in the zen-cart db)
However, it doesn't automatically create the token.json file as it should. I have to use the google gmail api quickstart to generate it and then move it to the right location.
so the left column here's when it only worked reading from my gmail w/ the api (branch 6 https://github.com/wolfderby/gmailTu...d_of_episode_6) from https://www.youtube.com/watch?v=fUm5ddL7bG8
the right column is me trying to put it into the zen-cart design pattern.
... in ... /amazon_gmail_orders/ >>> ... in ... /admin
/amazon_gmail_orders/index.php >>> amazon_gmail_orders.php
Composer.json >>> admin/composer.json
connection.php >>> includes/classes/yoyo_connection.php
credentials.json >>> includes/classes/credentials.json
gmail.php >>> includes/classes/yoyo_gmail.php
token.json >>> includes/classes/token.json
/vendor/ >>> includes/classes/vendors/gmail/vendor/
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
So I have this mashed up and "working" (reading from my gmail and from an orders_amazon table I created in the zen-cart db)
However, it doesn't automatically create the token.json file as it should. I have to use the google gmail api quickstart to generate it and then move it to the right location.
so the left column here's when it only worked reading from my gmail w/ the api (branch 6
https://github.com/wolfderby/gmailTu...d_of_episode_6) from
https://www.youtube.com/watch?v=fUm5ddL7bG8
the right column is me trying to put it into the zen-cart design pattern.
... in ... /amazon_gmail_orders/ >>> ... in ... /admin
/amazon_gmail_orders/index.php >>> amazon_gmail_orders.php
Composer.json >>> admin/composer.json
connection.php >>> includes/classes/yoyo_connection.php
credentials.json >>> includes/classes/credentials.json
gmail.php >>> includes/classes/yoyo_gmail.php
token.json >>> includes/classes/token.json
/vendor/ >>> includes/classes/vendors/gmail/vendor/
also asking this question on stackoverflow in case it's more appropriate there: https://stackoverflow.com/questions/...te-the-vendors
-
Re: how do I require application_top.php in folder in admin with a composer package?
have you tried moving this code outside of the class:
https://github.com/wolfderby/gmailTu...dex.php#L9-L12
something like:
PHP Code:
<?php
require DIR_FS_CATALOG . 'includes/classes/vendor/autoload.php';
include "connection.php";
class Yoyo {
public function __construct() {
}
public function go() {
not sure where the connection.php file is; but i think you get the idea....
-
Re: how do I require application_top.php in folder in admin with a composer package?
Just taking a wild guess ...
Your github connection.php file mentions $token_path = 'token.json'; ... without any directory qualifier. If you were to be specific about its actual path that might be enough.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
DrByte
Just taking a wild guess ...
Your github connection.php file mentions $token_path = 'token.json'; ... without any directory qualifier. If you were to be specific about its actual path that might be enough.
so if the token's in either path if it's referenced correctly it will work, however it if make the token.json (which was generated from google's quickstart code) into token.json.bak it not longer works because much of the google_client object's empty...
Code:
Google\Client Object
(
[auth:Google\Client:private] =>
[http:Google\Client:private] =>
[cache:Google\Client:private] =>
[token:Google\Client:private] =>
[config:Google\Client:private] => Array
(
[application_name] => Gmail API PHP Quickstart
[base_path] => https://www.googleapis.com
[client_id] => 787788787563-blbahlbah.apps.googleusercontent.com
[client_secret] => blbahlbah
[credentials] =>
[scopes] =>
[quota_project] =>
[redirect_uri] => urn:blbahlbah:wg:oauth:2.0:oob
[state] =>
[developer_key] =>
[use_application_default_credentials] =>
[signing_key] =>
[signing_algorithm] =>
[subject] =>
[hd] =>
[prompt] => select_account consent
[openid.realm] =>
[include_granted_scopes] =>
[login_hint] =>
[request_visible_actions] =>
[access_type] => offline
[approval_prompt] => auto
[retry] => Array
(
)
[retry_map] =>
[cache] =>
[cache_config] => Array
(
)
[token_callback] => Closure Object
(
[this] => Google\Client Object
*RECURSION*
[parameter] => Array
(
[$cacheKey] =>
[$newAccessToken] =>
)
)
[jwt] =>
[api_format_v2] =>
)
[logger:Google\Client:private] =>
[deferExecution:Google\Client:private] =>
[requestedScopes:protected] => Array
(
[0] => https://www.googleapis.com/auth/gmail.readonly
)
)
..then it throws...
PHP Fatal error: Uncaught Error: Call to a member function createAuthUrl() on null in C:\xampp\htdocs\mysite\site\admin\includes\classes\yoyo_connection.php:30
Stack trace:
#0 C:\xampp\htdocs\mysite_from_gitlab\pebs\mysite\includes\classes\yoyo.php(37): Connection->get_unauthenticated_data()
#1 C:\xampp\htdocs\mysite_from_gitlab\pebs\mysite\amazon_gmail_orders.php(31): Yoyo->go()
#2 {main}
thrown in C:\xampp\htdocs\mysite_from_gitlab\mysite\admin\includes\classes\yoyo_connection .php on line 30
-
Re: how do I require application_top.php in folder in admin with a composer package?
ugh so yeah I think I have to delve deep into google's api to get the client object generated correctly? something dealing w/ directory paths I'm guessing.
Might meditate on this a while and try another approach.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
however it if make the token.json ... into token.json.bak it not longer works
That's exactly what I would expect. If your PHP code is looking for "token.json" and you rename the file, then ... it won't find the file ... and ... it won't work.
I don't understand why you'd be renaming the file ...... ?
I'm certain Google wouldn't be suggesting to use a .bak extension for anything important or sensitive.
-
Re: how do I require application_top.php in folder in admin with a composer package?
...flash forward some days...
I have it sorta working... w/ the gmail api.
However I'm still new to thinking in an objected oriented design approach.
Looping through each received email, I'm generating a form w/ an insert/submit button...
that "creates" and order in my database but... the order id's are going haywire, probably because I didn't properly leverage the order's class in zen-cart.
I'm confused on how to create a consistent $oID order ID throughout the table inserts?
Code:
$newoID = $newoIDResult->fields['LAST_INSERT_ID()'];
... isn't working.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Not necessarily expected to work as provided in that code segment unless something has been done to make that exist.
Ok, anyone else familiar with the old/revamped tv show: "name that tune"? I feel like for some reason someone said that they could guess the tune by one note and the above code snippet was that note...
Let me put it another way... In talking about a book: I don't understand all that happened... the last word of the book was "end." how could that be? It is so wrong...
Or the infamous: my car isn't working right. It makes a sound...
Yes, I know I've gone overboard. I'm trying to offer some ways for the reader(s) to think from the other person(s) perspective so that likely more information could be given without having to request what may seem like basics. Sure, there's "hard" stuff that isn't known to give, (reminds me of a story recently told elsewhere in the forum about knowing how to use the tools the right way) but please help to help.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
.probably because I didn't properly leverage the order's class in zen-cart.
I'm confused on how to create a consistent $oID order ID throughout the table inserts?
Simple: use the order class.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
mc12345678
my car isn't working right. It makes a sound...
...so that sound... from my laptop... it's my bad code. :/ I KNEW IT! (:
Thanks for the input though, I had a feeling I was going down the wrong path, so I'm glad the community's here to chime in a get me on track. I don't do this professionally yet, so my outside input's limited.
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...
Also regarding tooling I'm still on VScode which I added some php intellisense to, I'm going to school for comp sci and I've heard PHPstorms' free to students. Any thoughts on trying it out?
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
Also regarding tooling I'm still on VScode which I added some php intellisense to, I'm going to school for comp sci and I've heard PHPstorms' free to students. Any thoughts on trying it out?
At one time Notepad++ was the best recommendation. But it's kinda dated now.
Then Sublime-Text came along (and is still an excellent choice).
But Microsoft has put a huge push into getting people onto VSCode.
I've spent a little time in VScode. It's the tool-of-choice for a lot of developers nowadays. You should be fine with it.
I highly recommend https://learn-vscode.com if you want to augment your efficiency in it.
That said, I use PhpStorm all the time, and find it to be better than all the others. It's also the tool that the ZC core team uses.
Yes it's pretty easy to apply for their student discount. Do it. (Note: PhpStorm includes the WebStorm features, so you only need to apply for PhpStorm.)
A friend of mine recently recorded some videos for the PhpStorm team: https://www.youtube.com/playlist?lis...x3Okalij5jMAgw and is preparing a course for it too at https://masteringphpstorm.com
-
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.
-
Re: how do I require application_top.php in folder in admin with a composer package?
not to be anti-social, but the learning curve seems steep..
Code:
$nextOrderId = "SELECT MAX(orders_id)
FROM `orders`
LIMIT 1;";
$orderIdResult = $db->Execute($nextOrderId);
echo '<pre>';
$oId = ++$orderIdResult->fields['MAX(orders_id)'];
echo 'next oId is ' . $oId . '<br />';
???
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
wolfderby
not to be anti-social, but the learning curve seems steep..
Code:
$nextOrderId = "SELECT MAX(orders_id)
FROM `orders`
LIMIT 1;";
$orderIdResult = $db->Execute($nextOrderId);
echo '<pre>';
$oId = ++$orderIdResult->fields['MAX(orders_id)'];
echo 'next oId is ' . $oId . '<br />';
???
It can be. But also can be helped by providing reasons for doing what is thought is needed.
Again, note that when using the order class to create an oder, the orders_id is autogenerated by way of inserting the base order info into the orders table.
Further note that the above code reviews the table for the highest number and then adds one to that. Problem is, if someone places an order, then that order is deleted and then this code is executed, two customers would have had the same order_id. No fun for customer or store.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Btw, and this was something I learned I believe the hard way, but may have been through watching others get help... If in fact it is needed to determine the next value within a table using the autoincremented field, then the "math" should be done in the query instead of after the query has been run... so instead of just MAX(field_name), should use MAX(field_name) + 1. If the table gets truncated, then a query may return null instead of 0 and doing math after the fact could result in issues. Some of this is system/configuration dependent, but best to use something expected to always work rather than something that *might* work... :)
Still though doesn't seem like this information is needed for this at least until a further reason is identified...
-
Re: how do I require application_top.php in folder in admin with a composer package?
Issues today: getting the order_id "right"
Possible solutions:
Solution "keep it ghetto" > no order object > sql lock the order tables > increment max order_id in sql > run inserts > unlock tables
Solution "pro zen-er" > create order object > create order_totals object > create cart object > create currencies object > fudge SESSION data? since this is run in the admin? > I feel like I'm slowly build an entire zen-cart shopping cart. then after all the objects are made can I just then run $order->create(); I'm pretty sure those zen_db_perform('s are my pay-dirt.
I might do "keep it ghetto" then aim for "pro zen-er" if I have time
-
Re: how do I require application_top.php in folder in admin with a composer package?
Whatever you choose. Let me say this with a little "tough love"... To insert a new order, you *DO NOT* need to know the order_id that is to be inserted when creating a new order...
You insert the data (without it including an order_id) and *then* ask what the order_id has become...
Session data... doesn't matter where you are in the system, having that session data variable set allows use/reuse of existing code that handles everything you need.
Building/rebuilding a cart? Of COURSE! You're incorporating the act of making a purchase on your Zen Cart store...
As far as locking all the tables or whatever, the only order table that really matters and the only time it matters for the most part is the orders table at the point of making an insert to that one table... Once the unnumbered data is inserted which then gets a number assigned, all other related orders tables get similar additions to reference that order_id.
Personally, I think it would be more work, time and effort to "take the short-cut" than it would to do a simple search through the order class perhaps on '$_SESSION', identify all of the unique parameters and really should only need to concern oneself with the create-like methods... then considering that data, compare to the data that you are receiving from your other direction and line the two up... the order class can handle not receiving something, but also need to be sure that as a user of the store that you are going to get out of this process what you want/need... for example, the shipping, payment, and normal home address information... right now, there doesn't appear to be a consideration of ensuring that the data is "uniquely" captured in the database. Meaning if person X places their first order, on their next order if they use the same addresses will the addresses be looked up and referenced or will they just be added to the person's account.
Are these purchasers gaining access to your Zen Cart store by making a purchase through the route you are implementing? Do they already have an account? If they do have an account, what verification is being done to ensure that the purchase they are making elsewhere (to be tracked here) should be associated with the data they have in the store? E.g. What authentication has been performed to relate the purchase made at this other shopping location with the person(s) in the shopping cart?
Again, you can choose what information you're not going to store in the database about an order, but you'll want to also understand what impact that has on order/data retrieval for you and for the customer(s).
And again whatever you do... stop trying to determine the value of something that automatically determines its value on its own... Let me see if I can think of an example...
Ok, perhaps obscure, but think of it this way, the order_id is the position in a race or marathon. Whoever appears at the end of the race is given a number associated to "how they did" in the race. Once they pass the finish line that number is assigned, but they had a lot to do to get to that finish line. Some may have taken easy paths, some harder, but in the end, they were given the number at which they finished (along with their time) rather than them "appearing" out of the blue and claiming a number... the process of performing the insert to the database is what assigns that number associated with finishing the race... that's also why you'll see in some places in the forum where it is said the first one to checkout wins... if you have limited quantity of a product, you don't want to oversell (taken care of in a way in the process)...
Anyways, hope you get the point..
-
Re: how do I require application_top.php in folder in admin with a composer package?
Quote:
Originally Posted by
mc12345678
Whatever you choose. Let me say this with a little "tough love"... To insert a new order, you *DO NOT* need to know the order_id that is to be inserted when creating a new order...
You insert the data (without it including an order_id) and *then* ask what the order_id has become...
Session data... doesn't matter where you are in the system, having that session data variable set allows use/reuse of existing code that handles everything you need.
Building/rebuilding a cart? Of COURSE! You're incorporating the act of making a purchase on your Zen Cart store...
As far as locking all the tables or whatever, the only order table that really matters and the only time it matters for the most part is the orders table at the point of making an insert to that one table... Once the unnumbered data is inserted which then gets a number assigned, all other related orders tables get similar additions to reference that order_id.
Personally, I think it would be more work, time and effort to "take the short-cut" than it would to do a simple search through the order class perhaps on '$_SESSION', identify all of the unique parameters and really should only need to concern oneself with the create-like methods... then considering that data, compare to the data that you are receiving from your other direction and line the two up... the order class can handle not receiving something, but also need to be sure that as a user of the store that you are going to get out of this process what you want/need... for example, the shipping, payment, and normal home address information... right now, there doesn't appear to be a consideration of ensuring that the data is "uniquely" captured in the database. Meaning if person X places their first order, on their next order if they use the same addresses will the addresses be looked up and referenced or will they just be added to the person's account.
Are these purchasers gaining access to your Zen Cart store by making a purchase through the route you are implementing? Do they already have an account? If they do have an account, what verification is being done to ensure that the purchase they are making elsewhere (to be tracked here) should be associated with the data they have in the store? E.g. What authentication has been performed to relate the purchase made at this other shopping location with the person(s) in the shopping cart?
Again, you can choose what information you're not going to store in the database about an order, but you'll want to also understand what impact that has on order/data retrieval for you and for the customer(s).
And again whatever you do... stop trying to determine the value of something that automatically determines its value on its own... Let me see if I can think of an example...
Ok, perhaps obscure, but think of it this way, the order_id is the position in a race or marathon. Whoever appears at the end of the race is given a number associated to "how they did" in the race. Once they pass the finish line that number is assigned, but they had a lot to do to get to that finish line. Some may have taken easy paths, some harder, but in the end, they were given the number at which they finished (along with their time) rather than them "appearing" out of the blue and claiming a number... the process of performing the insert to the database is what assigns that number associated with finishing the race... that's also why you'll see in some places in the forum where it is said the first one to checkout wins... if you have limited quantity of a product, you don't want to oversell (taken care of in a way in the process)...
Anyways, hope you get the point..
I think it should work if I remove my "hammering in the oID" just haven't done it yet. The various order table's autoincrement value (under operations in phpmyadmin) was high and I couldn't seem to get it to reset. However when I got the bad/high oID values out, the reset oID in the admin store manager seemed to fix it.
-
Re: how do I require application_top.php in folder in admin with a composer package?
So I have this "working" however I was thinking of launching it publicly on a git repo, (ideally to help me get a coding job), but I don't think it's quite there yet.
Would anyone be interested in me doing a screen cap video to show this script in action? I was thinking of putting it on youtube w/ a private link because it's using my personal store data I don't quite want out there right now. (I would private message people this link)
I'd be looking for constructive criticism in hopes of this script helping other people as a possible add-on, helping me get a job like this: (https://pineapplepayments.com/jobs/p...ipt-developer/) and to just better my skills in working within other paradigms.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Know of or remember the movie "Field of Dreams"? Build it and they will come...
If concerned about the store content, then build a separate "disposable" store... Do your video (don't wait for others to chime in especially this far in a thread), launch and see what happens... Further, if you make it a plugin and offer it to the Zen Cart community you may get hits off of that as well... Besides both could exist, the github repo and the ZC plugin which would further show your "engagement" with coding and design... Also, remember someone is more likely to appreciate someone that tries rather than someone that waits...
Sorry for not responding sooner, but because I didn't visit this site between the two messages I didn't get notified of the second message to be able to respond sooner.
-
Re: how do I require application_top.php in folder in admin with a composer package?
Gotcha good advice. Thanks.