Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

    Default Overriding functions?

    Is there a way to overwrite a function like zen_get_buy_now_button? Do I copy the function into an extra file with the same name or a different name?

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Overriding functions

    No there are no overrides for functions ... you would need to customize the original file ... save a copy of the original and your changed file for comparisons to future upgrades ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Overriding functions

    Quote Originally Posted by Ajeh View Post
    No there are no overrides for functions ...
    Just like everything else in Zen Cart, where there's a will there's a way! I've used the method I'll describe for a while now, based on a post that I found once and can't resurrect. It's a bit convoluted, but it does provide an override mechanism.

    The function zen_get_buy_now_button exists in functions_general.php.

    Step 1: Copy /includes/init_includes/init_general_functions.php to /includes/init_includes/overrides/init_general_functions.php. Edit that file

    Code:
    <?php
    /**
     * load the system wide functions
     * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
     *
     * @package initSystem
     * @copyright Copyright 2003-2005 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: init_general_funcs.php 2845 2006-01-13 06:49:15Z drbyte $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    /**
     * General Functions
     */
    require(DIR_WS_FUNCTIONS . 'overrides/functions_general.php');
    /**
     * html_output functions (href_links, input types etc)
     */
    require(DIR_WS_FUNCTIONS . 'html_output.php');
    /**
     * basic email functions
     */
    require(DIR_WS_FUNCTIONS . 'functions_email.php');
    /**
     * EZ-Pages functions
     */
    require(DIR_WS_FUNCTIONS . 'functions_ezpages.php');
    /**
     * User Defined Functions
     */
    include(DIR_WS_MODULES . 'extra_functions.php');
    ?>
    Step 2: Create the directory /includes/functions/overrides. Copy /includes/functions/functions_general.php into that folder and edit it to your heart's content.

    The other functions can be overridden in a similar manner.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Overriding functions

    Just remember that if you do that, your alterations are NOT multi-version friendly. So will absolutely require changes when a new version is released, to ensure compatibility.

    And they're not compatible with other overrides done by the storeowner, if they've already created an override for init_general_functions
    .

    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.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Overriding functions

    Quote Originally Posted by DrByte View Post
    Just remember that if you do that, your alterations are NOT multi-version friendly. So will absolutely require changes when a new version is released, to ensure compatibility.

    And they're not compatible with other overrides done by the storeowner, if they've already created an override for init_general_functions
    DrByte, I'm not necessarily proposing that this approach be used for general add-on writers for the reasons you mentioned. I've found it useful in my one-off changes for my site(s) since the overrides that I've created are preserved on an upgrade.

 

 

Similar Threads

  1. Overriding functions/html_output.php
    By kokuryu in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 16 Mar 2009, 08:02 PM
  2. Sidebox overriding
    By xordox in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Sep 2008, 09:56 AM
  3. Overriding a Class
    By SophWise.com in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 14 Feb 2007, 01:46 PM
  4. Overriding Functions
    By jgamio in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 18 Nov 2006, 06:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR