Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    help question Simple question for PHP programmers, hard for me!

    I hope to get some help to something that looks simple but I can not make it working:

    I have a table in my main page definition announcing free shipping of orders over EUR300 and the following line, which changes the 300 to the equivalent when a different currency is selected:

    HTML Code:
    FREE SHIPMENT OF ORDERS OVER <?php echo $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ?>
    That works fine. I now want to move this to a side box using Kuroi's blank sidebox mod. Contents of the relative includes/languages/english/extra_definitions/my_template/freeshipping.php file are:

    Code:
    <?php
    /**
     * blank sidebox definitions - text for inclusion in a new blank sidebox
     *
     * @package templateSystem
     * @copyright 2007 Kuroi Web Design
      * @copyright Portions Copyright 2003-2007 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: freeshipping_sidebox.php 2007-05-26 kuroi $
     */
    
    define('BOX_HEADING_FREESHIPPING_SIDEBOX', '');
    define('TEXT_FREESHIPPING_SIDEBOX', '
    	FREE SHIPMENT OF ORDERS OVER <?php echo $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ?>
    ');
    
    ?>
    However, all I get in the side box is

    FREE SHIPMENT OF ORDERS OVER format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ?>

    I know it's something simple but, not being a PHP programmer, doesn't help me to understand what's wrong except that it's PHP within PHP and the syntax should be somehow different.

    Could anybody please point me to the right direction. My thanks are advanced.

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Simple question for PHP programmers, hard for me!

    Quote Originally Posted by Athens Collectibles View Post
    Could anybody please point me to the right direction. My thanks are advanced.
    You can't/shouldn't be placing PHP code within a DEFINE statement.

    This needs to be TEXT ONLY.

    By definition, a 'define' is known as a CONSTANT, and this in turn means it shouldn't be a VARIABLE (which is what the php echo is trying to do)

    Cheers
    Rod
    Last edited by RodG; 6 Mar 2012 at 11:27 AM.

  3. #3
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    Default Re: Simple question for PHP programmers, hard for me!

    I see. It was a stupid question then!

    Cheers Rod and thanks for the reply.

  4. #4
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Simple question for PHP programmers, hard for me!

    If the value of the constant can properly be set before the page displays each time, then PHP inside the define will be okay if written properly. If the currency could be reset without reloading the page, that would be a problem, as the define would not be reset. Your whole issue is that the PHP is inside the text string. It needs to be concatenated with the text parts, like this:
    PHP Code:
    define('TEXT_FREESHIPPING_SIDEBOX''
        FREE SHIPMENT OF ORDERS OVER ' 
    $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) . '
    '
    ); 
    or maybe
    PHP Code:
    define('TEXT_FREESHIPPING_SIDEBOX''<br />    FREE SHIPMENT OF ORDERS OVER ' $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) . '<br />'); 

  5. #5
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    Default Re: Simple question for PHP programmers, hard for me!

    Thank you very much Glenn. My question wasn't that stupid after all.

    I have now worked it and added a "free insurance" definition with format('500'). The full define line is now:

    PHP Code:
    define('TEXT_FREESHIPPING_SIDEBOX''FREE SHIPMENT<br />OF ORDERS OVER<br />' $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) . '<br /><br />FREE INSURANCE<br />OF ORDERS OVER<br />' $currencies->format('500') . '<br />');?> 
    Added some styling and it's now displaying properly in a left column side box on my live site.

    This forum is a great help and I'm glad to learn something new every day, either by asking or by reading posts by other users. Many thanks to all you gurus who spend your time to help us novices.

  6. #6
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Simple question for PHP programmers, hard for me!

    It would also be fully appropriate to split the constant into two or more strictly text constants, and output each of them around the currency output in the module file or the tpl_ file. There is more than one way you can get correctly functioning output. In some cases, the correct value of a variable will not be known when the constant is defined, so the method shown would not work.

  7. #7
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    Default Re: Simple question for PHP programmers, hard for me!

    Thanks again Glenn, you've come to my rescue more than once in the past. I really appreciate your help and always learn from reading your posts.

  8. #8
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Simple question for PHP programmers, hard for me!

    Quote Originally Posted by Athens Collectibles View Post
    I see. It was a stupid question then!
    No, not at all stupid.

    I note that gjh42 has given you instructions in a method to do what you shouldn't really be doing. I can't/won't criticise him for doing so because his suggestion certainly works (which technically means there is nothing actually *wrong* with the code or method used). However I stand my my statement that it *shouldn't* be done this way because it really isn't best practice.
    Constants really should be constant, and treating them as a variables can lead to unexpected behaviour which is often a nightmare to debug.

    My statement that *can't* be done, was clearly an error, but one that I'll be happy to make again :)

    I didn't mean to mislead you (or anyone else). Apologies if I did.

    Cheers
    Rod

  9. #9
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    Default Re: Simple question for PHP programmers, hard for me!

    Of course you didn't mislead me. You presented the "best practice" and Glenn gave a "practical" solution. I followed Glenn's because it suited me and it worked, on the understanding that I'm taking the responsibility for any implications. I'm a bit adventurous and have made a lot of custom changes using information from the forum posts or experimenting. This was one more.

    As said in my previous post, I'm grateful to all wise people who provide help in the forums and, having seen many of your posts, you are one of them.

    Thanks again and have a nice day.

  10. #10
    Join Date
    May 2010
    Location
    Athens, Greece
    Posts
    292
    Plugin Contributions
    0

    Default Re: Simple question for PHP programmers, hard for me!

    In some cases, the correct value of a variable will not be known when the constant is defined, so the method shown would not work.
    I come back to this because I have found out that Glenn's remark quoted above is what happens: when I first load the page, for example after closing and re-opening the browser, the box displays "FREE SHIPMENT OF ORDERS OVER 0". When the page is refreshed, the variable displays correctly. The same happens the first time the page is refreshed after a long period of inactivity, i.e. the variable shows as zero and displays correctly if the page is refreshed once more.

    Could there be a solution to this problem?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Simple CSS/PHP AntiSpam solution for a contact form
    By dlg_ie in forum All Other Contributions/Addons
    Replies: 130
    Last Post: 24 Jan 2017, 05:04 PM
  2. v150 Wanted: Simple Capthcha for Forms, Maybe a Random Question or Image
    By jonisolis in forum General Questions
    Replies: 1
    Last Post: 14 Aug 2013, 09:21 PM
  3. A simple question for PHP programmers
    By HTMLGoddess in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 19 Jul 2008, 10:59 AM
  4. Suggestion for you heavy duty Zen programmers
    By mrogowski in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 5 Apr 2008, 08:09 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