Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default attribute PHP modding question

    I would like to add and IF/ELSE php statement in the tpl_module_attributes.php page of my template that will check if an attribute is a radio field or select field and change the "<div class='back'>" to a 'new class' on line 32 depending on what input type it is. I could probably do this in javascript after the page loads, but it would be more elegant to do it server side. Any help is welcome.

  2. #2
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: attribute PHP modding question

    Well to do that you are going to need to have a look at modules/attributes.php.

    Two ways of approaching it:
    1. When the menu is created set a flag variable like $input_type that you later use in a conditional statement.
    2. Move the containing div into attributes.php from tpl_modules_attributes. Then you can create it all in one go without the need for the flag variable.

    attributes.php is kind of long and involved but the bit you are interested in is down near the bottom where $options_menu is being created.
    Last edited by niccol; 23 Mar 2012 at 10:18 PM.

  3. #3
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: attribute PHP modding question

    my original thought was#1, only because that seemed easiest. I've been poking about in modules/attributes.php with no luck. I can see for the most part where the menu is being built but any idea how to set a flag variable, and where I should put it.

  4. #4
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: attribute PHP modding question

    So after attempting to get something to work after poking about most of the day, I've thought it might be better to change directions.

    A hidden attribute field would be a cleaner way of doing what I was attempting to do as a hack. So I created a new HIDDEN option type, I added it to my db and then I added the PRODUCTS_OPTIONS_TYPE_HIDDEN to the option_name.php file. Everything seems good on the Admin side.

    But the catalog side...I've tried to hack together a new Hidden attribute field in modules/attributes.php using zen_draw_hidden_field. My attributes seem to be passing as radio buttons, but that may be the default for single item options. So what I thought I would be capable of doing, I just can't quite get my head around. How to output my PRODUCTS_OPTIONS_TYPE_HIDDEN as a zen_draw_hidden_field in attributes.php. Any thoughts other than thinking a novice could tackle this?

  5. #5
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: attribute PHP modding question

    OK. In attributes.php you are looking for a 'switch'. It is worth working out what switch actually does (http://www.tizag.com/phpT/switch.php). Basically it is an easier way of writing lots of 'if' statements. The switch you are interested in is

    Code:
                    // Option Name Type Display
                    switch (true) {
    It is down near the bottom of the file.

    Now, each 'case' in that switch applies to one kind of attribute. They are commented so you should be able to work them out. For every 'case' ( and doing every one is important even if you do not use them ) you need to add a line like this:

    Code:
                      // radio buttons
                      case ($products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_RADIO):
                        $options_type[] = 'radio';
    Then in tpl_modules_attributes you can add this line:

    Code:
    <div class="wrapperAttribsOptions">
    <?php echo $options_type[$i];?>
    Which will just output the option type next to the menu so that you can test that it is all working the way you would expect.

    After that you should have all the stuff in place to write some 'if' statements to get it to work the way you want. You might even just try this:

    Code:
    <div class="wrapperAttribsOptions">
    <h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>
    <div class="<?php echo $options_type[$i];?>"><?php echo "\n" . $options_menu[$i]; ?></div>
    <br class="clearBoth" />
    </div>

  6. #6
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: attribute PHP modding question

    I understand the 'switch', I actually read up on it yesterday and did quite a bit of trying it out. Now I placed the variable flag like mentioned, I even put one in every case, here's a sample:

    Code:
    // radio buttons
                      case ($products_options_names->fields['products_options_type'] == PRODUCTS_OPTIONS_TYPE_RADIO):
                      if ($show_attributes_qty_prices_icon == 'true') {
                        $options_name[] = ATTRIBUTES_QTY_PRICE_SYMBOL . $products_options_names->fields['products_options_name'];
                      } else {
                        $options_name[] = $products_options_names->fields['products_options_name'];
                      }
                      $options_menu[] = $tmp_radio . "\n";
                      $options_comment[] = $products_options_names->fields['products_options_comment'];
                      $options_comment_position[] = ($products_options_names->fields['products_options_comment_position'] == '1' ? '1' : '0');
                      $options_type[] = "radio";
    				  break;
    and then I used the code in tpl_module_attributes to see what the output was:
    Code:
    <div class="wrapperAttribsOptions">
    <?php echo $options_type[$i];?>
    that worked well and it was good to see what was going on, like seeing that my attempt at a hidden type actually output a dropdown converted to a radio button(default case I think), probably because my code was not right. I was actually trying to output the type of option yesterday but was trying to pull the variable from elsewhere and it wasn't working. Anyway I reverted my modules/attributes.php to original, added the flags, reverted to radio button options in the admin, and things started to output as they should without modifications.

    After checking everything I placed this conditional in the tpl_module_attributes:
    Code:
    <?php if ($options_menu == 'radio'){
    	$class = 'hideme'; 
    } else {
    	$class = 'styled-select';
    }
    ?>
    
    <div class="<?php echo $class; ?>" ><?php echo "\n" . $options_menu[$i]; ?></div>
    <br class="clearBoth" />
    but alas, it doesn't work, it outputs every type of option in the same $class rather than just switching the radio options. The whole point is to hide the radio buttons but nothing else. I'm still thinking that figuring out how to have a <input type="hidden" field output as an option would probably be best.

  7. #7
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: attribute PHP modding question

    Well there are lots of ways to skin a cat....

    I suspect that this in your code:

    Code:
    <?php if ($options_menu == 'radio'){
    should actually say $option_type

  8. #8
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: attribute PHP modding question

    Hmm... good catch, unfortunately still not working, I get the 'styled-select' class all the time, it doesn't change whether or not $option_type == 'radio'.

  9. #9
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: attribute PHP modding question

    Well I am not sure exactly what you have done but in my version you would need to have

    $option_type[$i]

    exactly the same vbariable as

    <?php echo $options_type[$i];?>

    that you said that you had working previously.

  10. #10
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: attribute PHP modding question

    so probably your if statement is going to look like

    Code:
    <?php if ($options_type[$i] == 'radio'){
    	$class = 'hideme'; 
    } else {
    	$class = 'styled-select';
    }
    ?>
    If this kind of statement is not working the way that you think it should it then the first step is to include some kind of error reporting or diagnostic code. In this case it can be a s simple as:

    Code:
    <?php 
            echo $options_type[$i];
    if ($options_type[$i] == 'radio'){
    	$class = 'hideme'; 
    } else {
    	$class = 'styled-select';
    }
    ?>
    that will just print the value of the variable just before the if statement.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Modding Stock by Attribute to have SKUs / Model Number
    By flowerchild5 in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 2 Nov 2009, 03:15 AM
  2. Modding an xampp cart - help?
    By Gladys_Pym in forum Installing on a Windows Server
    Replies: 4
    Last Post: 18 May 2007, 09:47 AM
  3. Modding osCommerce File....
    By Eagle75au in forum General Questions
    Replies: 0
    Last Post: 12 May 2007, 02:10 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