Forums / Setting Up Categories, Products, Attributes / dynamic drop downs and insert text attributes

dynamic drop downs and insert text attributes

Locked

Started by oakwood on 9 Sep 2008, 4:39 AM · Views: 3,401

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
9 Sep 2008, 4:39 AM
#1
oakwood avatar

oakwood

New Zenner

Join Date:
May 2008
Posts:
85
Plugin Contributions:
0

dynamic drop downs and insert text attributes

Did anyone else have a problem with this? In the admin, it shows it perfect, but on the site there is a dropdown that says text (even though drop downs is not selected) so I'm guessing by the name alone that the dynamic drop downs mod has something to do with it!

Anyone know how to alter the code for that one???
Or maybe I could have a second set of attributes that dont have anything to do with dynamic drop downs just simply for the text attribute???
Or maybe (enter your zen knowledge here)!!!

Hope I'm coming out clear.

thx

follow me on twitter - twitter.com/nuggetshirts

16 Sep 2008, 4:02 AM
#2
oakwood avatar

oakwood

New Zenner

Join Date:
May 2008
Posts:
85
Plugin Contributions:
0

Re: dynamic drop downs and insert text attributes

Almost a week and no replies...must be tough one!

I think I need something this file (includes/classes/pad_sequenced_dropdowns)

   <?php
QT Pro Product Attributes Display Plugin
  
      pad_sequenced_dropdowns.php - Display stocked product attributes first as one dropdown for each attribute
                                    with Javascript to force user to select attributes in sequence so only
                                    in-stock combinations are seen.
  
      Class Name: pad_sequenced_dropdowns
  
      This class generates the HTML to display product attributes.  First, product attributes that
      stock is tracked for are displayed, each attribute in its own dropdown list with Javascript to
      force user to select attributes in sequence so only in-stock combinations are seen.  Then
      attributes that stock is not tracked for are displayed, each attribute in its own dropdown list.
  
      Methods overidden or added:
  
        _draw_stocked_attributes            draw attributes that stock is tracked for
        _draw_dropdown_sequence_js          draw Javascript to force the attributes to be selected in
                                            sequence
        _SetConfigurationProperties         set local properties
                                            
*/
  require_once(DIR_WS_CLASSES . 'pad_multiple_dropdowns.php');

  class pad_sequenced_dropdowns extends pad_multiple_dropdowns {


/*
    Method: _draw_stocked_attributes
  
    draw dropdown lists for attributes that stock is tracked for

  
    Parameters:
  
      none
  
    Returns:
  
      string:         HTML to display dropdown lists for attributes that stock is tracked for
  
*/
    function _draw_stocked_attributes() {
      global $db;
      
      $out='';
      
      $attributes = $this->_build_attributes_array(true, false);
      if (sizeof($attributes)<=1) {
        return parent::_draw_stocked_attributes();
      }

      // Check stock
      $s=sizeof($attributes[0]['ovals']);
      for ($a=0; $a<$s; $a++) {
        $attribute_stock = $db->Execute("select quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int)$this->products_id . "' AND quantity > 0");
        $out_of_stock=(($attribute_stock->RecordCount())==0);
   
        if ($out_of_stock) {
          unset($attributes[0]['ovals'][$a]);
        }
      }

      // Draw first option dropdown with all values
      $out.='<tr><td align="right" class="main"><b>'.$attributes[0]['oname'].":</b></td><td class=\"main\">".zen_draw_pull_down_menu('id['.$attributes[0]['oid'].']',array_merge(array(array('id'=>0, 'text'=>'First select '.$attributes[0]['oname'])), $attributes[0]['ovals']),$attributes[0]['default'], "onchange=\"i".$attributes[0]['oid']."(this.form);\"")."</td></tr>\n";

      // Draw second to next to last option dropdowns - no values, with onchange
      for($o=1; $o<sizeof($attributes)-1; $o++) {
        $out.='<tr><td align="right" class="main"><b>'.$attributes[$o]['oname'].":</b></td><td class=\"main\">".zen_draw_pull_down_menu('id['.$attributes[$o]['oid'].']',array(array('id'=>0, 'text'=>'Next select '.$attributes[$o]['oname'])), '', "onchange=\"i".$attributes[$o]['oid']."(this.form);\"")."</td></tr>\n";
      }        

      // Draw last option dropdown - no values, no onchange      
      $out.='<tr><td align="right" class="main"><b>'.$attributes[$o]['oname'].":</b></td><td class=\"main\">".zen_draw_pull_down_menu('id['.$attributes[$o]['oid'].']',array(array('id'=>0, 'text'=>'Next select '.$attributes[$o]['oname'])), '')."</td></tr>\n";
      
      $out.=$this->_draw_dropdown_sequence_js($attributes);
      
      return $out;
    }


/*
    Method: _draw_dropdown_sequence_js
  
    draw Javascript to display out of stock message for out of stock attribute combinations

  
    Parameters:
  
      $attributes     array   Array of attributes for the product.  Format is as returned by
                              _build_attributes_array.
  
    Returns:
  
      string:         Javascript to force user to select stocked dropdowns in sequence
  
*/
    function _draw_dropdown_sequence_js($attributes) {
      $out='';
      $combinations = array();
      $selected_combination = 0;
      $this->_build_attributes_combinations($attributes, false, 'None', $combinations, $selected_combination);
      
      $out.="<tr><td colspan=\"2\"> \n";
      
      $out.="<script type=\"text/javascript\" language=\"javascript\"><!--\n";
      // build javascript array of in stock combinations of the form
      // {optval1:{optval2:{optval3:1,optval3:1}, optval2:{optval3:1}}, optval1:{optval2:{optval3:1}}};
      $out.="  var stk=".$this->_draw_js_stock_array($combinations).";\n";

      // js arrays of possible option values/text for dropdowns
      // do all but the first attribute (its dropdown never changes)
      for ($curattr=1; $curattr<sizeof($attributes); $curattr++) {
        $attr = $attributes[$curattr];
        $out.="  var txt".$attr['oid']."={";
        foreach ($attr['ovals'] as $oval) {
          $out.=$oval['id'].":'".$oval['text']."',";
        }
        $out=substr($out,0,strlen($out)-1)."};";
        $out.="\n";
      }

      // js functions to set next dropdown options when a dropdown selection is made
      // do all but last attribute (nothing needs to happen when it changes)
      for ($curattr=0; $curattr<sizeof($attributes)-1; $curattr++) {
        $attr=$attributes[$curattr];
        $out.="  function i".$attr['oid']."(frm) {\n";
        $i=key($attributes);
        for ($i=$curattr+1; $i<sizeof($attributes); $i++) {
          $out.="    frm['id[".$attributes[$i]['oid']."]'].length=1;\n";
        }
        $out.="    for (opt in stk";
        for ($i=0; $i<=$curattr; $i++) {
          $out.="[frm['id[".$attributes[$i]['oid']."]'].value]";
        }
        $out.=") {\n";
        $out.="      frm['id[".$attributes[$curattr+1]['oid']."]'].options[frm['id[".$attributes[$curattr+1]['oid']."]'].length]=new Option(txt".$attributes[$curattr+1]['oid']."[opt],opt);\n";
        $out.="    }\n";
        $out.="  }\n";
      }

      // js to initialize dropdowns to defaults if product id contains attributes (i.e. clicked through to product page from cart)
      $out.="  i" . $attributes[0]['oid'] . "(document.cart_quantity);\n";
      for($o=1; $o<sizeof($attributes)-1; $o++) {
        if ($attributes[$o]['default']!='') {
          $out.="  document.cart_quantity['id[".$attributes[$o]['oid']."]'].value=".$attributes[$o]['default'].";\n";
          $out.="  i" . $attributes[$o]['oid'] . "(document.cart_quantity);\n";
        }
        else break;
      }
      if (($o == sizeof($attributes)-1) && ($attributes[$o]['default']!='')) {
        $out.="  document.cart_quantity['id[".$attributes[$o]['oid']."]'].value=".$attributes[$o]['default'].";\n";
      }
      
      // js to not allow add to cart if selections not made
      $out.="  function chksel() {\n";
      $out.="    var ok=true;\n";
      foreach ($attributes as $attr)
        $out.="    if (this['id[".$attr['oid']."]'].value==0) ok=false;\n";
      $out.="    if (!ok) alert('".TEXT_SELECT_OPTIONS."');\n";
      $out.="    return ok;\n";
      $out.="  }\n";
      $out.="  document.cart_quantity.onsubmit=chksel;\n";
      $out.="//--></script>\n";
      $out.="\n</td></tr>\n";
      
      return $out;
    }


/*
    Method: _SetConfigurationProperties
  
    Set local configuration properties
  
    Parameters:
  
      $prefix      sting     Prefix for the osCommerce DB constants
  
    Returns:
  
      nothing
  
*/
    function _SetConfigurationProperties($prefix) {

      // These properties are not used directly by this class 
      // They are set to match how this class displays for the case of a single
      // attribute where the parent class _draw_stocked_attributes method is called
      $this->show_out_of_stock    = 'False';
      $this->mark_out_of_stock    = 'Right';
      $this->out_of_stock_msgline = 'False';
      $this->no_add_out_of_stock  = 'True';

    }

  }
?>

This is a file not included in a regular zen cart install. I can't write code (I have gotten good at modifying it!), but would there be a way to write something like "if text attribute do this else code" or something along those lines?

BTW, I checked and it doesn't look like the tpl_products_attributes file is the answer either.

Any suggestions are much loved.

thx

follow me on twitter - twitter.com/nuggetshirts

22 May 2009, 7:03 AM
#3
laurenjj avatar

laurenjj

New Zenner

Join Date:
Sep 2008
Posts:
80
Plugin Contributions:
0

Re: dynamic drop downs and insert text attributes

Has ANYONE figured out a way to do this???? I'm DESPERATE OVER HERE!

I want so badly to use the dynamicdd mod but it's useless if I even have 1 product that uses a TEXT input button. Anyone?????

22 May 2009, 10:59 AM
#4
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: dynamic drop downs and insert text attributes

The mod's author included a link to his site in the readme file. You might be able to contact him for some guidance.

22 May 2009, 10:21 PM
#5
laurenjj avatar

laurenjj

New Zenner

Join Date:
Sep 2008
Posts:
80
Plugin Contributions:
0

Re: dynamic drop downs and insert text attributes

I have already contacted him and he wasn't able to help with this issue. I'm ready to pay someone if they can help me out here....:cry:

22 May 2009, 10:26 PM
#6
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: dynamic drop downs and insert text attributes

You might want to post in the Commercial Help Wanted forum.

23 May 2009, 9:21 AM
#7
laurenjj avatar

laurenjj

New Zenner

Join Date:
Sep 2008
Posts:
80
Plugin Contributions:
0

Re: dynamic drop downs and insert text attributes

OK....I have an idea but I'm not sure what to do as far as coding the javascript goes..... I need to take this line:

 function _draw_nonstocked_attributes() {
      $out='';
      $nonstocked_attributes = $this->_build_attributes_array(false, true);
      foreach($nonstocked_attributes as $nonstocked)
      {
        $out.='<tr><td align="right" class=main><b><em>'.$nonstocked['oname'].":</b></td><td class=main>".zen_draw_pull_down_menu('id['.$nonstocked['oid'].']',$nonstocked['ovals'],$nonstocked['default'])."</td></tr>\n";
      }
      return $out;
    }

and more specifically...this bit of that code:

<td class=main>".zen_draw_pull_down_menu('id['.$nonstocked['oid'].']',$nonstocked['ovals'],$nonstocked['default'])."</td>

and make that a text input field instead of a pull down....???

29 Oct 2009, 2:28 PM
#8
andreahd avatar

andreahd

New Zenner

Join Date:
Sep 2009
Posts:
9
Plugin Contributions:
0

Re: dynamic drop downs and insert text attributes

hello someone could solve it?. I really need for a customer. I would pay for that requirement. thanks