How to Change an Admin File.

Ask the community for help with CE Phoenix Cart.
Post Reply
User avatar
Portman
VIP Member
VIP Member
Posts: 130
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 29 times
Been thanked: 4 times

How to Change an Admin File.

Post by Portman »

Hello Again,

Hopefully a quick one here...
If I want to modify an Admin file but don't want to change the core code, where do I save it?

I made a minor change to admin/includes/modules/currencies/c_ecb.php so that it gets the inverse exchange rate (there is a perfectly good reason for this).

I then saved it in templates/override/admin/includes/modules/currencies/c_ecb.php

I assumed this was wrong but wanted to try for myself first - I was right it did not work.

Is there a way to do this?

Thanks for any help
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1339
Joined: Sat Dec 21, 2019 8:08 am
Has thanked: 39 times
Been thanked: 108 times

Re: How to Change an Admin File.

Post by raiwa »

Admin files and modules can’t be overridden in the template. You may use a renamed copy of the original file.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
burt
Lead Developer
Lead Developer
Posts: 2770
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 52 times
Been thanked: 157 times

Re: How to Change an Admin File.

Post by burt »

As per raiwa's advice above, you'd make yourself a new currency module (copying most of c_ecb) and set that to be used as the currency converter.

Admin > Modules > Update Currencies > {install}
and
Admin > Localization > Currencies

The idea behind "module" is that you don't use [turn off] the core one, and instead use one you've made yourself or had made or found in the addons area etc. That's true for all modules, not just currencies.
Current Beer Fund: £11.53

#wearephoenix #wearecommunity
User avatar
Portman
VIP Member
VIP Member
Posts: 130
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 29 times
Been thanked: 4 times

Re: How to Change an Admin File.

Post by Portman »

im trying to apply what you suggested, what am i doing wrong?

Im getting the error....

PHP Fatal error: Cannot declare class c_ecb, because the name is already in use in .... /admin/includes/modules/currencies/inv_currency.php on line 70

Code: Select all

  class inv_currency extends abstract_module {

    const CONFIG_KEY_BASE = 'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_';

    public static function execute() {
      $xml = Web::load_xml('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
      $xml = json_decode(json_encode($xml), JSON_FORCE_OBJECT);

      $currency_query = $GLOBALS['db']->query("SELECT currencies_id, code, title FROM currencies");
      while ($currency = $currency_query->fetch_assoc()) {
        $to[$currency['code']] = $currency['code'];
      }

      $from = DEFAULT_CURRENCY;

      $ecb_currencies = ['EUR' => 1.0];
      foreach ($xml as $a) {
        foreach ($a['Cube']['Cube'] as $b) {
          $ecb_currencies[$b['@attributes']['currency']] = $b['@attributes']['rate'];
        }
      }

      if ($from !== 'EUR') {
        $exchange = $ecb_currencies[$from];
        foreach ($ecb_currencies as $x => $y) {
          $ecb_currencies[$x] = $y/$exchange;
        }
      }

      $to_exchange = array_intersect_key($ecb_currencies, $to);

      foreach ($to_exchange as $k => $v) {
		$invrate = 1/$v; //Added by Portman - to get inverse exchange rate		  
//        $rate = Text::input($v);
		$rate = Text::input($invrate); // Mod by Portman
       $GLOBALS['db']->query("UPDATE currencies SET value = '" . $GLOBALS['db']->escape($rate) . "', last_updated = NOW() WHERE code = '" . $GLOBALS['db']->escape($k) . "'");
       $GLOBALS['messageStack']->add_session(sprintf(MODULE_ADMIN_CURRENCIES_INV_CURRENCY_CURRENCIES_UPDATED, $k), 'success');
      }

    }

    protected function get_parameters() {
      return [
        'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_STATUS' => [
          'title' => 'Enable INVERSE CURRENCY Module',
          'value' => 'True',
          'desc' => 'Do you want to install this Currency Conversion Module?',
          'set_func' => "Config::select_one(['True', 'False'], ",
        ],
        'MODULE_ADMIN_CURRENCIES_INV_CURRENCY_SORT_ORDER' => [
          'title' => 'Sort Order',
          'value' => '0',
          'desc' => 'Sort order of display. Lowest is displayed first.',
        ],
      ];
    }

  }
User avatar
bonbec
VIP Member
VIP Member
Posts: 65
Joined: Mon Oct 26, 2020 12:23 pm
Has thanked: 10 times
Been thanked: 7 times

Re: How to Change an Admin File.

Post by bonbec »

Old MS2.2 PHP7.4 site being converted to CE Phoenix v1.0.9.6 PHP 8.3
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1339
Joined: Sat Dec 21, 2019 8:08 am
Has thanked: 39 times
Been thanked: 108 times

Re: How to Change an Admin File.

Post by raiwa »

In the original module line 70 is the last line and empty.
What do you have in your module in line 70?
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
Portman
VIP Member
VIP Member
Posts: 130
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 29 times
Been thanked: 4 times

Re: How to Change an Admin File.

Post by Portman »

raiwa wrote: Tue Sep 26, 2023 1:00 pm In the original module line 70 is the last line and empty.
What do you have in your module in line 70?
Line 70 is the closing }

I have only changed a couple of lines to create an inverse exchange rate
User avatar
Portman
VIP Member
VIP Member
Posts: 130
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 29 times
Been thanked: 4 times

Re: How to Change an Admin File.

Post by Portman »

bonbec wrote: Tue Sep 26, 2023 7:06 am Hi,
Take a look here : https://phoenixcart.org/phoenixcartwiki ... ent_Module
Thanks, I feel like I have followed these instructions...
I have modified admin/includes/modules/c_ecb.php which does not have a corresponding template page

I have changed the class name from c_ebc to inv_currency and changed every instance of CURRENCIES_EBC to INV_CURRENCY...

As far as I can tell I've done what I need to but I must be missing something
heatherbell
VIP Member
VIP Member
Posts: 2190
Joined: Mon Oct 07, 2019 4:39 am
Has thanked: 30 times
Been thanked: 203 times

Re: How to Change an Admin File.

Post by heatherbell »

Portman wrote: Tue Sep 26, 2023 11:36 pm As far as I can tell I've done what I need to but I must be missing something
We have no answer but the error message seems strange as there's no mention of c_ecb in the code that you posted.
Can only advise to repeat your work from scratch and upload again, then ensure the old module is uninstalled before installing the new. Maybe also double check your configuration table in your database to ensure the old module is uninstalled but just guessing.
User avatar
Portman
VIP Member
VIP Member
Posts: 130
Joined: Mon Mar 08, 2021 1:04 am
Has thanked: 29 times
Been thanked: 4 times

Re: How to Change an Admin File.

Post by Portman »

thanks @heatherbell that did the job!
Post Reply