If this is your first visit, check our documentation. To post, register or login.
Forums / Code Collaboration / how do I require application_top.php in folder in admin with a composer package?

how do I require application_top.php in folder in admin with a composer package?

Started by wolfderby on 28 Dec 2020, 4:51 PM · Views: 18,844

Results 21 to 40 of 59
29 Dec 2020, 9:55 PM
#21
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

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?

My site - Pro ZC Help
My portfolio | My plugins

30 Dec 2020, 11:16 AM
#22
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

Re: how do I require application_top.php in folder in admin with a composer package?

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. :/

30 Dec 2020, 12:00 PM
#23
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

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))

30 Dec 2020, 3:40 PM
#24
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

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

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

30 Dec 2020, 5:51 PM
#25
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

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...

My site - Pro ZC Help
My portfolio | My plugins

31 Dec 2020, 8:22 PM
#26
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

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.

31 Dec 2020, 8:26 PM
#27
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

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?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Jan 2021, 11:58 AM
#28
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

Re: how do I require application_top.php in folder in admin with a composer package?

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.

3 Jan 2021, 3:35 PM
#29
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

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/gmailTutorial/tree/end_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/

3 Jan 2021, 3:46 PM
#30
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

Re: how do I require application_top.php in folder in admin with a composer package?

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/gmailTutorial/tree/end_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/65551717/when-using-the-gmail-api-quickstart-code-snippet-how-do-i-relocate-the-vendors

3 Jan 2021, 4:12 PM
#31
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

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/gmailTutorial/blob/05a573e997ba22a2dc365d6d318309f0ab6b7a58/index.php#L9-L12

something like:

<?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....

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

3 Jan 2021, 4:26 PM
#32
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

3 Jan 2021, 10:17 PM
#33
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

Re: how do I require application_top.php in folder in admin with a composer package?

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...

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

3 Jan 2021, 10:19 PM
#34
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

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.

3 Jan 2021, 10:34 PM
#35
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: how do I require application_top.php in folder in admin with a composer package?

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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Jan 2021, 5:07 PM
#36
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

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?

    $newoID = $newoIDResult->fields['LAST_INSERT_ID()'];

... isn't working.

14 Jan 2021, 4:56 AM
#37
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

14 Jan 2021, 5:09 AM
#38
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: how do I require application_top.php in folder in admin with a composer package?

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.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

14 Jan 2021, 12:04 PM
#39
wolfderby avatar

wolfderby

Zen Follower

Join Date:
Dec 2008
Location:
Pittsburgh, PA
Posts:
241
Plugin Contributions:
0

Re: how do I require application_top.php in folder in admin with a composer package?

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?

14 Jan 2021, 4:14 PM
#40
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: how do I require application_top.php in folder in admin with a composer package?

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?list=PLQ176FUIyIUZjFbdm7Ux3Okalij5jMAgw and is preparing a course for it too at https://masteringphpstorm.com

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.