Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Is there an override for filenames.php?

Is there an override for filenames.php?

Views: 784

Results 1 to 4 of 4
27 Feb 2018, 6:26 PM
#1
roberth avatar

roberth

New Zenner

Join Date:
Aug 2015
Posts:
63
Plugin Contributions:
0

Is there an override for filenames.php?

I know about adding additional defines to filenames in /includes/extra_datafiles/ but what if I need to override a define already existing in /includes/filenames.php? Can I do so without editing the file directly (to keep core file intact)?

I tried reiterating the same define('CONSTANT',''); line in the newly added /extra_datafiles/*_filenames.php file, but the constant still contains the definition from /includes/filenames.php instead of the one from /extra_datafiles/.

27 Feb 2018, 6:45 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Is there an override for filenames.php?

RobertH:

I know about adding additional defines to filenames in /includes/extra_datafiles/ but what if I need to override a define already existing in /includes/filenames.php? Can I do so without editing the file directly (to keep core file intact)?

I tried reiterating the same define('CONSTANT',''); line in the newly added /extra_datafiles/*_filenames.php file, but the constant still contains the definition from /includes/filenames.php instead of the one from /extra_datafiles/.
If you need to override a definition in /includes/filenames.php, the best way is to get that definition placed ***before ***that file is loaded.

Place your customization in /includes/extra_configures/filenames_override.php (or a name of your choosing).

27 Feb 2018, 6:53 PM
#3
roberth avatar

roberth

New Zenner

Join Date:
Aug 2015
Posts:
63
Plugin Contributions:
0

Re: Is there an override for filenames.php?

lat9:

If you need to override a definition in /includes/filenames.php, the best way is to get that definition placed ***before ***that file is loaded.

Place your customization in /includes/extra_configures/filenames_override.php (or a name of your choosing).

Ah okay, that makes sense. That works fine!

What about overrides to files in /includes/functions/ or /includes/classes/? I found this thread from 2009 where a user advises to create an override in /init_includes/, but is there a built-in method for doing this now? Or what would be the suggested procedure for overrides on those files that don't have custom_template override systems?

27 Feb 2018, 7:37 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Is there an override for filenames.php?

RobertH:

Ah okay, that makes sense. That works fine!

What about overrides to files in /includes/functions/ or /includes/classes/? I found this thread from 2009 where a user advises to create an override in /init_includes/, but is there a built-in method for doing this now? Or what would be the suggested procedure for overrides on those files that don't have custom_template override systems?
Using the /includes/auto_loaders/overrides and /includes/init_includes/overrides sub-directories work, but their use (IMO) can cause issues when you're upgrading. I used those methods in the past and then, when upgrading, forgot that they were there ... and wound up spending much more time trying to figure out what the heck was going on.

My advice, make your customized changes directly to the core files in /includes/functions and /includes/init_includes and heavily comment the changes. I've adopted the methods used by the legendary Conor Kerr (now deceased) as illustrated below.

Let's pretend that you want to modify the function zen_get_buy_now_button (present in /includes/functions_general.php) to add a specific class to the output when the associated product is "call_for_price".

The original code fragment in that function reads:
```
case ($button_check->fields['product_is_call'] == '1'):
$return_button = '<a href="' . zen_href_link(FILENAME_CONTACT_US, '', 'SSL') . '">' . TEXT_CALL_FOR_PRICE . '</a>';
break;

I'd make the update as follows:
case ($button_check->fields['product_is_call'] == '1'):

//-bof-20180227-lat9-Add class to enable link's styling
// $return_button = '<a href="' . zen_href_link(FILENAME_CONTACT_US, '', 'SSL') . '">' . TEXT_CALL_FOR_PRICE . '</a>';
$return_button = '<a href="' . zen_href_link(FILENAME_CONTACT_US, '', 'SSL') . '" class="buynow-call-for-price">' . TEXT_CALL_FOR_PRICE . '</a>';
//-eof-20180227-lat9

  break;
The change is surrounded by //-bof and //-eof comments, with a blank line before the //-bof and after the //-eof (it "helps" your file-comparison program properly locate the changes).  Keeping the original code also helps on an upgrade, so you can see what was changed!