Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Trying to make a small script run on "if, else"

    Hello, I am trying to run a script at the shopping cart (tpl_shopping_cart_default)

    Basically, I wans to load a php if the order sub total is below $50 and make it load a different one if the subtotal is above $50

    What I currently have is:

    PHP Code:
    <?php
    if ($order->info['subtotal'] < 50.00) {
                                require(
    $template->get_template_dir('tpl_modules_cart_products1.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_cart_products1.php');
                            } else {
                                require(
    $template->get_template_dir('tpl_modules_cart_products2.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_cart_products2.php');                   
    ?>

    This would only work fine if I leave the firtst part of the If without the "else", meaning, it will load only if under $50, but when the else is added, the else script will always run first.

  2. #2
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Re: Trying to make a small script run on "if, else"

    just to explain why i need this, I just want to show some text if the order is below 50 and a different one if over 50, the current php file being called all it does is display such text

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

    Default Re: Trying to make a small script run on "if, else"

    The snippet you posted is missing the closing } after

    else {
    require()

    Does your file have that } ?

  4. #4
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Re: Trying to make a small script run on "if, else"

    Quote Originally Posted by gjh42 View Post
    The snippet you posted is missing the closing } after

    else {
    require()

    Does your file have that } ?
    Yeah.. it is there.. not sure why it did not copy to this forum.

    I still have the problem... only the first variable will work, after I add the "else", then the If is lost and the same text (the else) will always prevail...

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

    Default Re: Trying to make a small script run on "if, else"

    If the original if() evaluates to true, it will be executed and any else() will be ignored. So somehow the if() is evaluating to false. Maybe seeing a larger section of the file would help understand what is happening.

  6. #6
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Re: Trying to make a small script run on "if, else"

    Quote Originally Posted by gjh42 View Post
    If the original if() evaluates to true, it will be executed and any else() will be ignored. So somehow the if() is evaluating to false. Maybe seeing a larger section of the file would help understand what is happening.
    Sure, this is the complete file:

    PHP Code:
    <?php

    /**

     * Page Template

     *

     * Loaded automatically by index.php?main_page=shopping_cart.<br />

     * Displays shopping-cart contents

     *

     * @package templateSystem

     * @copyright Copyright 2003-2007 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: tpl_shopping_cart_default.php 6528 2007-06-25 23:25:27Z drbyte $

     */

    ?>

    <div class="centerColumn" id="shoppingCartDefault">

    <?php

      
    if ($flagHasCartContents) {

    ?>



    <?php

      
    if ($_SESSION['cart']->count_contents() > 0) {

    ?>

    <div class="text_v_c"><?php echo TEXT_VISITORS_CART?></div>

    <?php

      
    }

    ?>



    <h1 id="cartDefaultHeading"><?php echo HEADING_TITLE?></h1>



    <?php if ($messageStack->size('shopping_cart') > 0) echo $messageStack->output('shopping_cart'); ?>



    <?php echo zen_draw_form('cart_quantity'zen_href_link(FILENAME_SHOPPING_CART'action=update_product')); ?>

    <div id="cartInstructionsDisplay" class="content"><?php echo TEXT_INFORMATION?></div>



    <?php if (!empty($totalsDisplay)) { ?>

      <div class="cartTotalsDisplay important"><?php echo $totalsDisplay?></div>

      <br class="clearBoth" />

    <?php ?>



    <?php  if ($flagAnyOutOfStock) { ?>



    <?php    if (STOCK_ALLOW_CHECKOUT == 'true') {  ?>



    <div class="messageStackError"><?php echo OUT_OF_STOCK_CAN_CHECKOUT?></div>



    <?php    } else { ?>

    <div class="messageStackError"><?php echo OUT_OF_STOCK_CANT_CHECKOUT?></div>



    <?php    //endif STOCK_ALLOW_CHECKOUT ?>

    <?php  //endif flagAnyOutOfStock ?>



    <table  border="0" width="100%" cellspacing="0" cellpadding="0" id="cartContentsDisplay">

         <tr class="tableHeading">

            <th scope="col" id="scQuantityHeading"><?php echo TABLE_HEADING_QUANTITY?></th>

            <th scope="col" id="scProductsHeading"><?php echo TABLE_HEADING_PRODUCTS?></th>

            <th scope="col" id="scUnitHeading"><?php echo TABLE_HEADING_PRICE?></th>

            <th scope="col" id="scTotalHeading"><?php echo TABLE_HEADING_TOTAL?></th>

            <th scope="col" id="scRemoveHeading"><?php echo TABLE_HEADING_REMOVE?></th>

         </tr>

             <!-- Loop through all products /-->

    <?php

      
    foreach ($productArray as $product) {

    ?>

         <tr class="<?php echo $product['rowClass']; ?>">

           <td class="cartQuantity">

    <?php

      
    if ($product['flagShowFixedQuantity']) {

        echo 
    $product['showFixedQuantityAmount'] . '<br /><span class="alert bold">' $product['flagStockCheck'] . '</span><br />' $product['showMinUnits'];

      } else {

        echo 
    $product['quantityField'] . '<br /><span class="alert bold">' $product['flagStockCheck'] . '</span><br />' $product['showMinUnits'];

      }

    ?>

    <div class="buttonRow">

    <?php

      
    if ($product['buttonUpdate'] == '') {

        echo 
    '' ;

      } else {

        echo 
    $product['buttonUpdate'];

      }

    ?>

    </div>

    <?php

        
    echo '<br /><br />';

    ?>

           </td>

           <td class="cartProductDisplay">

    <a href="<?php echo $product['linkProductsName']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] . '<span class="alert bold">' $product['flagStockCheck'] . '</span>'?></span></a>

    <br class="clearBoth" />





    <?php

      
    echo $product['attributeHiddenField'];

      if (isset(
    $product['attributes']) && is_array($product['attributes'])) {

      echo 
    '<div class="cartAttribsList">';

      echo 
    '<ul>';

        
    reset($product['attributes']);

        foreach (
    $product['attributes'] as $option => $value) {

    ?>



    <li><?php echo $value['products_options_name'] . TEXT_OPTION_DIVIDER nl2br($value['products_options_values_name']); ?></li>



    <?php

        
    }

      echo 
    '</ul>';

      echo 
    '</div>';

      }

    ?>

           </td>

           <td class="cartUnitDisplay"><?php echo $product['productsPriceEach']; ?></td>

           <td class="cartTotalDisplay"><?php echo $product['productsPrice']; ?></td>

           <td class="cartRemoveItemDisplay"><div class="buttonRow3">

    <?php

      
    if ($product['checkBoxDelete'] ) {

        echo 
    zen_draw_checkbox_field('cart_delete[]'$product['id']);

      }

    ?>

    <?php

      
    echo '</div><br /><br />';

    ?>

    <div class="buttonRow"><?php

      
    if ($product['buttonDelete']) {

    ?>

               <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART'action=remove_product&product_id=' $product['id']); ?>"><?php echo zen_image($template->get_template_dir(ICON_IMAGE_TRASHDIR_WS_TEMPLATE$current_page_base,'images/icons'). '/' ICON_IMAGE_TRASHICON_TRASH_ALT); ?></a>

    <?php

      
    }

    ?></div>

    </td>

         </tr>

    <?php

      
    // end foreach ($productArray as $product)

    ?>

           <!-- Finished loop through all products /-->

          </table>



    <div id="cartSubTotal"><?php echo SUB_TITLE_SUB_TOTAL?> <strong><?php echo $cartShowTotal?></strong></div>

    <br class="clearBoth" />

    <?php 
    if ($order->info['subtotal'] < 50.00) { 
                                require(
    $template->get_template_dir('tpl_modules_cart_products1.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_cart_products1.php'); 
                            } else { 
                                require(
    $template->get_template_dir('tpl_modules_cart_products2.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_cart_products2.php');                    
    }
    ?> 
    <!--bof shopping cart buttons-->

    <div class="buttonRow forward"><?php echo '<a href="' zen_href_link(FILENAME_CHECKOUT_SHIPPING'''SSL') . '">' zen_image_button(BUTTON_IMAGE_CHECKOUTBUTTON_CHECKOUT_ALT) . '</a>'?></div>

    <div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_CONTINUE_SHOPPINGBUTTON_CONTINUE_SHOPPING_ALT) . '</a>'?></div>

    <?php

    // show update cart button

      
    if (SHOW_SHOPPING_CART_UPDATE == or SHOW_SHOPPING_CART_UPDATE == 3) {

    ?>

    <div class="buttonRow back"><?php echo zen_image_submit(ICON_IMAGE_UPDATEICON_UPDATE_ALT); ?></div>

    <?php

      
    } else { // don't show update button below cart

    ?>

    <?php

      
    // show update button

    ?>

    <!--eof shopping cart buttons-->

    </form>



    <br class="clearBoth" />

    <?php

        
    if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1') {

    ?>



    <div class="buttonRow back"><?php echo '<a href="javascript:popupWindow(\'' zen_href_link(FILENAME_POPUP_SHIPPING_ESTIMATOR) . '\')">' .

     
    zen_image_button(BUTTON_IMAGE_SHIPPING_ESTIMATORBUTTON_SHIPPING_ESTIMATOR_ALT) . '</a>'?></div>

    <?php

        
    }

    ?>



    <!-- ** BEGIN PAYPAL EXPRESS CHECKOUT ** -->

    <?php  // the tpl_ec_button template only displays EC option if cart contents >0 and value >0

    if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') {

      include(
    DIR_FS_CATALOG DIR_WS_MODULES 'payment/paypal/tpl_ec_button.php');

    }

    ?>

    <!-- ** END PAYPAL EXPRESS CHECKOUT ** -->



    <?php

          
    if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '2') {

    /**

     * load the shipping estimator code if needed

     */

    ?>

          <?php require(DIR_WS_MODULES zen_get_module_directory('shipping_estimator.php')); ?>



    <?php

          
    }

    ?>



    <?php

      
    } else {

    ?>



    <h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY?></h2>



    <?php

    $show_display_shopping_cart_empty 
    $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);



    while (!
    $show_display_shopping_cart_empty->EOF) {

    ?>



    <?php

      
    if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_FEATURED_PRODUCTS') { ?>

    <?php

    /**

     * display the Featured Products Center Box

     */

    ?>

    <?php require($template->get_template_dir('tpl_modules_featured_products.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_featured_products.php'); ?>

    <?php ?>



    <?php

      
    if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_SPECIALS_PRODUCTS') { ?>

    <?php

    /**

     * display the Special Products Center Box

     */

    ?>

    <?php require($template->get_template_dir('tpl_modules_specials_default.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_specials_default.php'); ?>

    <?php ?>



    <?php

      
    if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_NEW_PRODUCTS') { ?>

    <?php

    /**

     * display the New Products Center Box

     */

    ?>

    <?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>

    <?php ?>



    <?php

      
    if ($show_display_shopping_cart_empty->fields['configuration_key'] == 'SHOW_SHOPPING_CART_EMPTY_UPCOMING') {

        include(
    DIR_WS_MODULES zen_get_module_directory(FILENAME_UPCOMING_PRODUCTS));

      }

    ?>

    <?php

      $show_display_shopping_cart_empty
    ->MoveNext();

    // !EOF

    ?>



    <?php

      
    }

    ?>
    <?php

    ?>

    <?php 

        
    //DRS - Cart Products

        
    if ($shipping_weight 1.8) {

        require(
    $template->get_template_dir('tpl_modules_cart_products.php',DIR_WS_TEMPLATE$current_page_base,'templates'). '/tpl_modules_cart_products.php'); 

        }

        
    //DRS END Cart Products

    ?>

    </div>

  7. #7
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Re: Trying to make a small script run on "if, else"

    to make the code a bit simple for testing purposes, I am trying:

    <?php
    if (($order->info['subtotal'])>=50) {
    echo 'message under 50';
    }
    else {
    echo 'Message OVER 50';
    }
    ?>


    Does not matter the size of the cart, it will always say "Message OVER 50".....


    perhaps the if at the begining is not validating correctly

  8. #8
    Join Date
    Nov 2003
    Location
    Haarlem | Netherlands
    Posts
    1,987
    Plugin Contributions
    15

    Default Re: Trying to make a small script run on "if, else"

    I would also echo
    Code:
    $order->info['subtotal']
    But your test should be
    Code:
    <?php
    if (($order->info['subtotal'])>=50) {
    echo 'Message OVER 50';
    }
    else {
    echo 'message under 50';
    }
    ?>
    (you have it the other way around)

  9. #9
    Join Date
    Apr 2008
    Posts
    51
    Plugin Contributions
    0

    Default Re: Trying to make a small script run on "if, else"

    Quote Originally Posted by paulm View Post
    I would also echo
    Code:
    $order->info['subtotal']
    But your test should be
    Code:
    <?php
    if (($order->info['subtotal'])>=50) {
    echo 'Message OVER 50';
    }
    else {
    echo 'message under 50';
    }
    ?>
    (you have it the other way around)
    I am not sure what you mean by:

    Quote Originally Posted by paulm View Post
    I would also echo
    Code:
    $order->info['subtotal']
    Using your code will still not work,... I am getting the "message under 50" regardless of the cart value...

  10. #10
    Join Date
    Nov 2003
    Location
    Haarlem | Netherlands
    Posts
    1,987
    Plugin Contributions
    15

    Default Re: Trying to make a small script run on "if, else"

    Quote Originally Posted by antoniobb View Post
    I am not sure what you mean by:



    Using your code will still not work,... I am getting the "message under 50" regardless of the cart value...
    You are testing on $order->info['subtotal'], but maybe it's not available in this part of the script. If it's not available the $order->info['subtotal'])>=50 test will be false and the "else" will be executed, which is:
    echo 'message under 50';

    Since you are using the value of $order->info['subtotal'], and testing if it's >= 50, I thought it would be interesting to display the value of $order->info['subtotal'], that is why I suggested to echo $order->info['subtotal'].

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Package Tare - Difference in "small to medium" and "large"
    By JusMeJim in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 4 Apr 2013, 03:03 PM
  2. v138a Trying to make a "Paypal request invoice" option
    By grantopt in forum General Questions
    Replies: 0
    Last Post: 5 May 2012, 07:33 AM
  3. Shopping cart - trying to turn off "Total Items" "Weight" and "Price"
    By deshojo in forum Templates, Stylesheets, Page Layout
    Replies: 11
    Last Post: 4 Apr 2011, 07:15 PM
  4. "if", "else" statements in shopping cart...
    By eranariel in forum Managing Customers and Orders
    Replies: 3
    Last Post: 12 Jan 2011, 05:54 PM
  5. For images, does "base" = "small"? And a question about alternates.
    By molywerks in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 29 Feb 2008, 02:49 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