Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Best practice to replace Admin module(s)


ArtcoInc

Recommended Posts

(using osC Frozen)

I am working on an add-on that expands the functionality of one (or more) of the stock,  built-in ADMIN modules, and it involves adding additional fields to the existing databases. Since ADMIN is not modular (yet), I can't just un-install the stock module(s). So, I can either:

    1) Overwrite the stock modules (clearly not the best choice),

or 2) Give the new modules different names, and just add the new module name(s) to the menu structure. But, this would leave the original modules intact and still in the menu structure, where:

a) the original module may not functional any more, or worse,

b) they may actually mess up the newly expanded database tables.

or 3) Add the new module names to the menu structure, and try to figure out a way to remove the original module names from the menu structure (and add them back if the new module is ever removed).

I have seen examples of how to add a menu item, but not how to remove a stock one (without editing the 'core' menu definition files (I suppose I could just replace the stock menu definition files, and put the original ones back if uninstalling. But, that could mess up someone that had already hand edited their menu definitions)). Can someone point me toward a Best Practice way to do this?

TIA

Malcolm

Link to comment
Share on other sites

@burt

Let's say that I want to add additional fields to the 'countries' table. And, to be able to administer these new fields, I will want to make changes to /admin/countries.php (a core file). To change this file, I could overwrite the stock /admin/countries.php file. Not the best choice, in my opinion.

Even in Frozen, the stock ADMIN menus are still hard coded (in this case, the link to /admin/countries.php is in /admin/includes/boxes/localization.php).

So, instead of overwriting /admin/countries.php, let's say that I call my new admin file something like /admin/new_countries.php. I can add a link to my new file to the menu (I have seen how to add a new menu item to the array), but the stock link to the stock /admin/countries.php file would still be in the menu. I'm concerned that a shop owner (or some hired help) might use the stock /admin/countries.php link and file, and possibly mess up the database table.

I could overwrite the /admin/includes/boxes/localization.php file, but there's the chance that the store owner has already made their own changes to /admin/includes/boxes/localization.php, so overwriting it would also not be a good choice.

What I originally asked was ... is there a way THROUGH THE ADD-ON INSTALLATION process, to be able to remove (or hide) a link in /admin/includes/boxes/localization.php menu file, and be able to add it back (or un-hide it) if the add-on is ever uninstalled?

After some additional thought, though, I might have a better solution. :rolleyes: During the add-on installation, I could:

1) rename the stock /admin/countries.php file to something like /admin/countries.old, and

2) copy my new /admin/countries.php file into its place.

This way, no changes to the menu structure have to be made. And, if the store owner ever chooses to uninstall the add-on, the new /admin/countries.php file would be deleted, and the renamed /admin/countries.old file would be renamed back to /admin/countries.php.

Thoughts?

M

Link to comment
Share on other sites

OK, I see.  I think I'd (and definitely not saying this is the right way, but a way);

  1. make new page new_countries.php
  2. new file to add in link in localization

    So far, no core changes.  But you have a link to both countries pages in the box. So...this is the tricky bit;
     
  3. make hook which places .js in the bottom of admin side, which
    - removes the original countries.php link
    - if they somehow manage to navigate to the original countries.php add in a message on that page under the page heading:
     
    <div class="secWarning">You have installed XYZ, use {link to new_countries.php} for localization purposes</div>

     

Link to comment
Share on other sites

5 hours ago, ArtcoInc said:

but there's the chance that the store owner has already made their own changes to /admin/includes/boxes/localization.php, so overwriting it would also not be a good choice.

They shouldn't have...if any addon requires shopowner to *manually* add code to a sidebox...the addon is outdated.
I think this system was introduced in 2.3.3 (or so), the ability to add links without amending files.

Link to comment
Share on other sites

Thought about this a bit more.  I recently made for a client a system of assigning "best" products in a category and manufactuer/brand. 

I could have put that into the admin/categories.php page, but that page is kind of complicated...  

Instead I put it in it's own page:

new_page.jpg.77dc1a0ac19950e8b0ff28456f74eb3c.jpg

What you see there (admin side):

  1. New box module & language file for "best products" sidebox [2 files]
  2. New box module & language file for "in brand" link in that sidebox [2 files]
  3. ditto "in category" link [2 files]
  4. New page & language file for assigning products to categories [2 files]
  5. New page & language file for assigning products to manufacturers [2 files]

Shop side:

  1. new module for index_products which looks for assigned products and displays them appropriately  [2 files]

All of the above is a long winded way of saying what you could do is leave the base functionality alone and instead have an extra page just doing the bits you want to add.  Although this is 12 extra files, there is no touching of core code and the amount of time spent creating those 12 files is perhaps a few minutes more than trying to implement it all in admin/categories.php

Link to comment
Share on other sites

@burt
 

8 hours ago, burt said:

So...this is the tricky bit;

   make hook which places .js in the bottom of admin side, which
      - removes the original countries.php link
      - if they somehow manage to navigate to the original countries.php add in a message on that page under the page heading:
 

This is what I was asking about ... if this was even possible. Way above my pay-grade, though.

I had considered creating a new table instead of adding additional fields to the existing Countries table, but thought it would require more work than it was worth. I may have to reconsider that.

But, since Admin is not modularized, there is no built-in way to install any new modules. The store owner would have to manually copy files, run something like phpMyAdmin to work on the database tables, etc. Definitely not a copy/one-click install/configure/go type of thing.

So, maybe this isn't something that really is suitable as an add-on. At least, not one that tries to conform to proper coding practices.

Thank you, though!

M

Link to comment
Share on other sites

11 minutes ago, ArtcoInc said:

This is what I was asking about ... if this was even possible.

For sure possible.  Shopowner would then need that couple of lines of code to call the Hook.

If you could post what it is that you're exactly wanting to do with the countries...I could take a think and provide some thoughts.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...