Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Constants for procedural and object oriented code

    I'm working on a mod that displays the correct shipping address for store pickup instead of the customers address in order confirmation, invoices, packing slips, etc. We occasionally go to shows and other events where customers can pickup orders, so the "shipping address" for store pickup can change. We do not want to change the official store address in the configuration table.

    I've got it working pretty well using a special row of the address book that is accessed whenever store pickup shipping method is chosen, but I've had to hard code certain store pickup address data. I'd like to make this data defined constants that I can change for each show or event venue, but the normal define function won't work in methods within a class. I'm working in the order class. But I also need some of the constants in procedural code.

    Having the same constants in define statements for procedural code and in const statements within a class for OO code seems poor programming and I'm not sure it would work. Querying the database multiple times to lookup constants using zen_get_configuration_key_value seems inefficient, or to query a custom table seems to be overkill.

    Is there a way out of this mess? Or am I forced to use the database to store the constants?

  2. #2
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Constants for procedural and object oriented code

    I found the solution. It turns out that normal defines can be used. Apparently, in my testing, the constants defined were not loaded before they were needed. I had placed them in the store pickup shipping module language file. When I placed them in a file in the include/extra_datafiles, they worked fine, both within the order class and in procedural code.

    In addition, I found out that you do not need the zen_get_configuration_key_value function to access constants in the configuartion table. You can access them directly in both the order class and in other procedural code.

    So my solution is to use normal defines, located in the proper location to solve my problem.

    Dave

  3. #3
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Constants for procedural and object oriented code

    Right.

    Configuration table settings are all automatically defined as constants. No need to query the db at all for them.

    Shipping module language files are loaded just before the shipping module loads, so constants in the language file should be ready. But if you're doing something that fires the module uniquely in other ways then using extra_datafiles or extra_configures would be fine.
    .

    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.

 

 

Similar Threads

  1. How much Object Oriented Programming is in Zencart ?
    By DogTags in forum General Questions
    Replies: 2
    Last Post: 25 Nov 2009, 04:51 PM
  2. Is there a list of Constants and Classes and their use?
    By grimorg80 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 18 Aug 2009, 06:53 PM
  3. Constants coming up instead of text assigned to constants
    By blk00xjc in forum General Questions
    Replies: 3
    Last Post: 25 Mar 2009, 10:11 PM
  4. Looking for Payment Gateway for Adult Oriented Products.
    By racerx8413 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 18 Jan 2008, 04:58 AM
  5. PRODUCT_ALL_LIST_PRICE and other constants
    By David Bo in forum General Questions
    Replies: 2
    Last Post: 8 Feb 2007, 05:08 PM

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