Zen Cart Logo
Forums / Contribution-Writing Guidelines / Retrieving the admin directory via storefront notifier

Retrieving the admin directory via storefront notifier

Views: 4,172

Results 1 to 12 of 12
3 Jul 2024, 3:17 PM
#1
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Retrieving the admin directory via storefront notifier

So I'm PRETTY sure this is not recommended or is in someway disallowed.

I would like to make an observer that will effectively notify a webhook whenever a new order is created. I know that I would need to use the NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_HEADER hook from the notifier system. I would like to create a hyperlink that will point to the new order in the admin backend. But that would require access to DIR_WS_ADMIN which I think is not possible.

Rather than hardcoding the directory into the notifier class, any advice on how to proceed?

3 Jul 2024, 3:26 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

If the script you intend to run is on the admin side, a relative URL will work fine. Make the link be

index.php?cmd=orders&page=1&oID=xxxxx&action=edit

and you'll get to the order details page from admin.

3 Jul 2024, 4:04 PM
#3
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Re: Retrieving the admin directory via storefront notifier

swguy:

If the script you intend to run is on the admin side, a relative URL will work fine. Make the link be

index.php?cmd=orders&page=1&oID=xxxxx&action=edit

and you'll get to the order details page from admin.

This was planned client side unless there is a notifier that can be triggered when a new order is made?

3 Jul 2024, 4:26 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

Sorry, I mean the "ultimate" target script. But to know where to write this, you'd still have to know the admin URL, so I guess it still wouldn't work.

You might just want to create a config with the name of the admin folder so you can easily access it from anywhere, and you could alert from the admin if you login and see the value has changed.

3 Jul 2024, 5:45 PM
#5
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Re: Retrieving the admin directory via storefront notifier

Okay I guess I should ask, can an observer in the admin directory see events that would trigger from /classes/order.php?

3 Jul 2024, 5:52 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

For an observer to fire, you'd have to have software running. Storefront observers don't fire in arbitrary tasks; they fire in the process where the notifier was issued.

You could have a cron job run from admin and take action based on new orders if you wanted.

3 Jul 2024, 5:56 PM
#7
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

You haven't disclosed what it is you're trying to do, but my guess is you'd be better off just creating a new admin widget to display orders that have not yet gone through whatever processing you want to do, and displaying them (like the New Order widget).

https://docs.zen-cart.com/dev/code/widget/

Then when you login you'd see the orders that need to be processed.

If you want the processing to be done in real time when the order is placed, you should do it on the storefront side.

3 Jul 2024, 7:49 PM
#8
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Re: Retrieving the admin directory via storefront notifier

swguy:

You haven't disclosed what it is you're trying to do, but my guess is you'd be better off just creating a new admin widget to display orders that have not yet gone through whatever processing you want to do, and displaying them (like the New Order widget).

https://docs.zen-cart.com/dev/code/widget/

Then when you login you'd see the orders that need to be processed.

If you want the processing to be done in real time when the order is placed, you should do it on the storefront side.

There is an API for PushBullet that will notify all machines that are subscribed to a "channel" whenever a message (or push) is sent. The API allows for a message to be customized and dispatched to all machines that are subscribed to that notification.

What I wanted to have happen is that as a new order is sent in, a push (message) is sent which contains the Order #, Order Total, Payment Method (name of, not intricate details), Shipping Method and a separate link to the backend where the order can be viewed for processing.

The idea ultimately being that as an order is processed in the front end, the observer will pull the order information (via usual SQL), build a message, and then push that message to the API which will send the nudge to all connected machines.

The only problem is that in order to send the link, I have to specify the full HTML URI of the order which includes the URI of the backend.

I can probably come back at it in the manner you suggested and run a cron that will check for new orders on a regular recurring basis. But I would likely have to add a column to the orders then have the crontab check for all orders not marked 1 in that column, send that push, then update that column to 1.

But to do so live, in the manner I was trying to, still requires me to somehow get the name of the admin folder which is the biggest stump that I'm at. Overall I can still probably do this without the link being attached and drop it if's something or not normally done without reinventing the wheel. Like I can hardcode it for my shop, but was trying to make a generic solution so that all users can use it.

3 Jul 2024, 8:48 PM
#9
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

Put it in the DB - it becomes a general solution.

https://docs.zen-cart.com/dev/plugins/adding_config/

3 Jul 2024, 8:51 PM
#10
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Re: Retrieving the admin directory via storefront notifier

swguy:

Put it in the DB - it becomes a general solution.

https://docs.zen-cart.com/dev/plugins/adding_config/

Is it safe for me to pull the name of the admin folder from a DB configuration setting? I mean I'm HAPPY to do that as it'll save me a headache and a half.

3 Jul 2024, 9:14 PM
#11
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,688
Plugin Contributions:
56

Re: Retrieving the admin directory via storefront notifier

Obscuring the admin name is more about pest control than about security.
Be sure to take the normal security precautions.
Use a strong password, change it every three months, run anti-virus on your PC.

https://docs.zen-cart.com/user/first_steps/security/#secure-access-to-your-admin

3 Jul 2024, 9:36 PM
#12
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
943
Plugin Contributions:
3

Re: Retrieving the admin directory via storefront notifier

swguy:

Obscuring the admin name is more about pest control than about security.
Be sure to take the normal security precautions.
Use a strong password, change it every three months, run anti-virus on your PC.

https://docs.zen-cart.com/user/first_steps/security/#secure-access-to-your-admin

Duly noted!