www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] adding if statement assistance

  1. #1
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383

    resolved [RESOLVED] adding if statement assistance

    below is part of a dropdown that lists product conditions with their appropriate pricing. i'd like to add an if statement to say, if new do NOT show price next to condition. can anybody help me out with this?


    PHP Code:
    <?php 
    if( $num_options ) {
    echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
    $value_label $value["value"];
    if( 
    $field == "condition_id" ) {
    $price $value["lowest_price"];
    if( 
    $price ) {
    if (
    $custom_map == 'yes') {
    $value_label .= " (Add to Cart for Price)";

    else {
    $value_label .= " ($" number_format($price,2) . ")";
    }
    }
    }
    echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php

    i believe the variables available are:

    PHP Code:
    $lowest_price_condition == 'New' || $parent_product["title"]["brand"]["value"
    or

    PHP Code:
     [id] => [value] => New 
    or

    PHP Code:
    condition_o7 

  2. #2
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    PHP Code:
    <?php 
    if( $num_options ) {
        echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
        
    $value_label $value["value"];
        if( 
    $field == "condition_id" ) {

            
    $price $value["lowest_price"];
            
    $lowest_price_condition $value["lowest_price_condition"]; //Not sure if this is how you have this stored

            
    if( $lowest_price_condition == 'New' ) {} else { //Just made a quick Change
                
    if( $price ){
                    if (
    $custom_map == 'yes') {
                        
    $value_label .= " (Add to Cart for Price)";
                    } 
                    else {
                        
    $value_label .= " ($" number_format($price,2) . ")";
                    }
                }
            }
        }
        echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php
    You Might want to space out your code a bit
    But if i understand you correctly than all you want to do is that.
    Last edited by Nvenom; 07-26-2012 at 06:22 AM.

  3. #3
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    actually i forgot about this operator lol, so this would be better.

    PHP Code:
    <?php 
    if( $num_options ) {
        echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
        
    $value_label $value["value"];
        if( 
    $field == "condition_id" ) {

            
    $price $value["lowest_price"];
            
    $lowest_price_condition $value["lowest_price_condition"]; //Not sure if this is how you have this stored

            
    if( $lowest_price_condition != 'New' ) { //Just made a quick Change using != operator
                
    if( $price ){
                    if (
    $custom_map == 'yes') {
                        
    $value_label .= " (Add to Cart for Price)";
                    } 
                    else {
                        
    $value_label .= " ($" number_format($price,2) . ")";
                    }
                }
            }
        }
        echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php

  4. #4
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383
    so, i want NEW products to display 'add to cart for price' if they're set that way, if not it display only the condition text, no price.

    then for used products, i want to do the same except i want to display the price next to condition text.

    does this look right?
    PHP Code:
     <?php
    if( $num_options ) {
        echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
        
    $value_label $value["value"];
        if( 
    $field == "condition_id" ) {

            
    $price $value["lowest_price"];
            
    $lowest_price_condition $value["lowest_price_condition"]; //Not sure if this is how you have this stored

            
    if( $lowest_price_condition != 'New' ) { //Just made a quick Change using != operator
                
    if( $price ){
                    if (
    $custom_map == 'yes') {
                        
    $value_label .= " (Add to Cart for Price)";
                    }
                    else {
                        
    $value_label;
                    }
                }
            } else {
             if( 
    $price ) {
                 if (
    $custom_map == 'yes') {
                      
    $value_label .= " (Add to Cart for Price)";
                 } 
                 else {
                 
    $value_label .= " ($" number_format($price,2) . ")";
                }
             }
             
            }
        }
        echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php

  5. #5
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383
    i just tried it out and it didn't work out correctly for me. hmm

  6. #6
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    do you have $lowest_price_condition set?

  7. #7
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    Quote Originally Posted by absolutmgd13 View Post
    so, i want NEW products to display 'add to cart for price' if they're set that way, if not it display only the condition text, no price.

    then for used products, i want to do the same except i want to display the price next to condition text.

    does this look right?
    PHP Code:
     <?php
    if( $num_options ) {
        echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
        
    $value_label $value["value"];
        if( 
    $field == "condition_id" ) {

            
    $price $value["lowest_price"];
            
    $lowest_price_condition $value["lowest_price_condition"]; //Not sure if this is how you have this stored

            
    if( $lowest_price_condition != 'New' ) { //Just made a quick Change using != operator
                
    if( $price ){
                    if (
    $custom_map == 'yes') {
                        
    $value_label .= " (Add to Cart for Price)";
                    }
                    else {
                        
    $value_label;
                    }
                }
            } else {
             if( 
    $price ) {
                 if (
    $custom_map == 'yes') {
                      
    $value_label .= " (Add to Cart for Price)";
                 } 
                 else {
                 
    $value_label .= " ($" number_format($price,2) . ")";
                }
             }
             
            }
        }
        echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php
    Must have skipped forward and not read this post.. lol,

    You have it backwards, Try this.

    PHP Code:
     <?php
    if( $num_options ) {
        echo 
    '<option value="none">Choose...</option>' "\n";
    }
    foreach( 
    $settings["select_values"] as $key=>$value ) {
        
    $value_label $value["value"];
        if( 
    $field == "condition_id" ) {

            
    $price $value["lowest_price"];
            
    $lowest_price_condition $value["lowest_price_condition"];

            if( 
    $lowest_price_condition == 'New' ) { //Changed the operator to ==
                
    if( $price ){
                    if (
    $custom_map == 'yes') {
                        
    $value_label .= " (Add to Cart for Price)";
                    }
                    else {
                        
    $value_label;
                    }
                }
            } else {
             if( 
    $price ) {
                 if (
    $custom_map == 'yes') {
                      
    $value_label .= " (Add to Cart for Price)";
                 } 
                 else {
                 
    $value_label .= " ($" number_format($price,2) . ")";
                }
             }
             
            }
        }
        echo 
    '<option value="o' $key '">' $value_label '</option>' "\n";
    }
    ?>
    </select>
    <?php
    == Means, If Equal to.
    so

    PHP Code:
    <?php
    $var 
    1;
    if( 
    $var == ){
        
    //Execute Code...
    }
    ?>
    -------------------------------

    != Means, If not Equal to.
    so

    PHP Code:
    <?php
    $var 
    1;
    if( 
    $var != ){
        
    //Execute Code...
    }
    ?>
    Last edited by Nvenom; 07-26-2012 at 01:32 PM.

  8. #8
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383
    got it.. i used

    PHP Code:
     if( $value_label == 'New' 
    instead of

    PHP Code:
    if( $lowest_price_condition == 'New' 

  9. #9
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383
    thanks for your help!

  10. #10
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    No Problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles