PHP Code to display Saving Price/Text in osCommerce

Discussion in 'PHP' started by rosiee007, Apr 29, 2008.

  1. #1
    Hi,

    I'm not much of a PHP expert, but I want to display the 'Save Price' with each product where ever Price and Special Price are being displayed.

    I've written code to show the 'Saving Price' like this: (It is the difference of Actual price minus special price).

    <span class="productSavePrice">You Save: '.	  
    	  $currencies->display_price($product_info['products_price']-$new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>
    PHP:
    Now I want to add a condition which displays a different tag line for every language. Like for French, I don't want to display 'You Save' as the text but use appropriate text for every language. Currently I'm just using 2 languages, to keep it simple, so you can give a solution for 2 languages only, English and French.
     
    rosiee007, Apr 29, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    Look at the language code in OSCommerce script and there you will find how to choose different lang.

    Basically they use a variable in langugae file in each language file

    and display the value of that variable based on language selected ,so no need to put condition

    Just in place of text use variable name defined in language file

    regards

    Alex
     
    kmap, Apr 29, 2008 IP
    rosiee007 likes this.
  3. rosiee007

    rosiee007 Notable Member

    Messages:
    3,352
    Likes Received:
    179
    Best Answers:
    0
    Trophy Points:
    230
    #3
    Thanks for the reply. I've now defined the variable in danish.php and english.php files as given below respectively:

    //currency You Save Text
    define('CURRENCIES_SAVE_TEXT', 'Besparelse');
    
    //currency You Save Text
    define('CURRENCIES_SAVE_TEXT', 'You Save');
    PHP:
    I cannot access it directly or display it on the place where I want to:

     <span class="productSavePrice">.' CURRENCIES_SAVE_TEXT '.	  
    	  $currencies->display_price($product_info['products_price']-$new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>
    PHP:
    I checked other texts, and they seem to use an array to display them. Will I need to use an array also?

    Sorry if it is a stupid question.
     
    rosiee007, Apr 29, 2008 IP
  4. mike.greenleaf

    mike.greenleaf Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <span class="productSavePrice">.' CURRENCIES_SAVE_TEXT '.     
          $currencies->display_price($product_info['products_price']-$new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>
    Code (markup):
    The problem may be that you have wrapped your constant variable in single quotes...

    Is this what is displayed? :

    CURRENCIES_SAVE_TEXT $some_number

    Trying removing the single quotes from CURRENCIES_SAVE_TEXT; i.e.

    <span class="productSavePrice"> . ' ' . CURRENCIES_SAVE_TEXT . ' ' .     
          $currencies->display_price($product_info['products_price']-$new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>
    Code (markup):
     
    mike.greenleaf, Apr 29, 2008 IP
  5. rosiee007

    rosiee007 Notable Member

    Messages:
    3,352
    Likes Received:
    179
    Best Answers:
    0
    Trophy Points:
    230
    #5
    Thanks Mike,

    I fixed the problem. There was PHP code right after I called the constant:

     <span class="productSavePrice"> ' . TEXT_YOU_SAVE .' : '. 	  
    	  $currencies->display_price($product_info['products_price']-$new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
    PHP:
     
    rosiee007, Apr 30, 2008 IP