[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> pad_sequenced_dropdowns.php (source)

   1  <?php
   2  /*

   3        QT Pro Version 4.1

   4    

   5        pad_sequenced_dropdowns.php

   6    

   7        Contribution extension to:

   8          osCMax Power E-Commerce

   9          http://oscdox.com

  10       

  11        Copyright 2006 osCMax2004, 2005 Ralph Day

  12        Released under the GNU General Public License

  13    

  14        Based on prior works released under the GNU General Public License:

  15          QT Pro prior versions

  16            Ralph Day, October 2004

  17            Tom Wojcik aka TomThumb 2004/07/03 based on work by Michael Coffman aka coffman

  18            FREEZEHELL - 08/11/2003 [email protected] Copyright 2006 osCMax2003 IBWO

  19            Joseph Shain, January 2003

  20          osCommerce MS2

  21            Copyright 2006 osCMax

  22        Modifications made:

  23            11/2004 - Created

  24            12/2004 - Fix _draw_dropdown_sequence_js to prevent js error when all attribute combinations

  25                      are out of stock

  26            03/2005 - Remove '&' for pass by reference from parameters to call of

  27                      _build_attributes_combinations.  Only needed on method definition and causes

  28                      error messages on some php versions/configurations

  29    

  30  *******************************************************************************************

  31    

  32        QT Pro Product Attributes Display Plugin

  33    

  34        pad_sequenced_dropdowns.php - Display stocked product attributes first as one dropdown for each attribute

  35                                      with Javascript to force user to select attributes in sequence so only

  36                                      in-stock combinations are seen.

  37    

  38        Class Name: pad_sequenced_dropdowns

  39    

  40        This class generates the HTML to display product attributes.  First, product attributes that

  41        stock is tracked for are displayed, each attribute in its own dropdown list with Javascript to

  42        force user to select attributes in sequence so only in-stock combinations are seen.  Then

  43        attributes that stock is not tracked for are displayed, each attribute in its own dropdown list.

  44    

  45        Methods overidden or added:

  46    

  47          _draw_stocked_attributes            draw attributes that stock is tracked for

  48          _draw_dropdown_sequence_js          draw Javascript to force the attributes to be selected in

  49                                              sequence

  50          _SetConfigurationProperties         set local properties

  51                                              

  52  */
  53    require_once (DIR_WS_CLASSES . 'pad_multiple_dropdowns.php');
  54  
  55    class pad_sequenced_dropdowns extends pad_multiple_dropdowns {
  56  
  57  
  58  /*

  59      Method: _draw_stocked_attributes

  60    

  61      draw dropdown lists for attributes that stock is tracked for

  62  

  63    

  64      Parameters:

  65    

  66        none

  67    

  68      Returns:

  69    

  70        string:         HTML to display dropdown lists for attributes that stock is tracked for

  71    

  72  */
  73      function _draw_stocked_attributes() {
  74        global $languages_id;
  75        
  76        $out='';
  77        
  78        $attributes = $this->_build_attributes_array(true, false);
  79        if (sizeof($attributes)<=1) {
  80          return parent::_draw_stocked_attributes();
  81        }
  82  
  83        // Check stock

  84        $s=sizeof($attributes[0]['ovals']);
  85        for ($a=0; $a<$s; $a++) {
  86          $attribute_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_id = '" . (int)$this->products_id . "' AND products_stock_attributes REGEXP '(^|,)" . (int)$attributes[0]['oid'] . "-" . (int)$attributes[0]['ovals'][$a]['id'] . "(,|$)' AND products_stock_quantity > 0");
  87          $out_of_stock=(tep_db_num_rows($attribute_stock_query)==0);
  88          if ($out_of_stock) {
  89            unset($attributes[0]['ovals'][$a]);
  90          }
  91        }
  92  
  93        // Draw first option dropdown with all values

  94        $out.='<tr><td align="right" class=main><b>'.$attributes[0]['oname'].":</b></td><td class=main>".tep_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";
  95  
  96        // Draw second to next to last option dropdowns - no values, with onchange

  97        for($o=1; $o<sizeof($attributes)-1; $o++) {
  98          $out.='<tr><td align="right" class=main><b>'.$attributes[$o]['oname'].":</b></td><td class=main>".tep_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";
  99        }        
 100  
 101        // Draw last option dropdown - no values, no onchange      

 102        $out.='<tr><td align="right" class=main><b>'.$attributes[$o]['oname'].":</b></td><td class=main>".tep_draw_pull_down_menu('id['.$attributes[$o]['oid'].']',array(array('id'=>0, 'text'=>'Next select '.$attributes[$o]['oname'])), '')."</td></tr>\n";
 103        
 104        $out.=$this->_draw_dropdown_sequence_js($attributes);
 105        
 106        return $out;
 107      }
 108  
 109  
 110  /*

 111      Method: _draw_dropdown_sequence_js

 112    

 113      draw Javascript to display out of stock message for out of stock attribute combinations

 114  

 115    

 116      Parameters:

 117    

 118        $attributes     array   Array of attributes for the product.  Format is as returned by

 119                                _build_attributes_array.

 120    

 121      Returns:

 122    

 123        string:         Javascript to force user to select stocked dropdowns in sequence

 124    

 125  */
 126      function _draw_dropdown_sequence_js($attributes) {
 127        $out='';
 128        $combinations = array();
 129        $selected_combination = 0;
 130        $this->_build_attributes_combinations($attributes, false, 'None', $combinations, $selected_combination);
 131        
 132        $out.="<tr><td colspan=2>&nbsp\n";
 133        
 134        $out.="<SCRIPT LANGUAGE=\"JavaScript\"><!--\n";
 135        // build javascript array of in stock combinations of the form

 136        // {optval1:{optval2:{optval3:1,optval3:1}, optval2:{optval3:1}}, optval1:{optval2:{optval3:1}}};

 137        $out.="  var stk=".$this->_draw_js_stock_array($combinations).";\n";
 138  
 139        // js arrays of possible option values/text for dropdowns

 140        // do all but the first attribute (its dropdown never changes)

 141        for ($curattr=1; $curattr<sizeof($attributes); $curattr++) {
 142          $attr = $attributes[$curattr];
 143          $out.="  var txt".$attr['oid']."={";
 144          foreach ($attr['ovals'] as $oval) {
 145            $out.=$oval['id'].":'".$oval['text']."',";
 146          }
 147          $out=substr($out,0,strlen($out)-1)."};";
 148          $out.="\n";
 149        }
 150  
 151        // js functions to set next dropdown options when a dropdown selection is made

 152        // do all but last attribute (nothing needs to happen when it changes)

 153        for ($curattr=0; $curattr<sizeof($attributes)-1; $curattr++) {
 154          $attr=$attributes[$curattr];
 155          $out.="  function i".$attr['oid']."(frm) {\n";
 156          $i=key($attributes);
 157          for ($i=$curattr+1; $i<sizeof($attributes); $i++) {
 158            $out.="    frm['id[".$attributes[$i]['oid']."]'].length=1;\n";
 159          }
 160          $out.="    for (opt in stk";
 161          for ($i=0; $i<=$curattr; $i++) {
 162            $out.="[frm['id[".$attributes[$i]['oid']."]'].value]";
 163          }
 164          $out.=") {\n";
 165          $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";
 166          $out.="    }\n";
 167          $out.="  }\n";
 168        }
 169  
 170        // js to initialize dropdowns to defaults if product id contains attributes (i.e. clicked through to product page from cart)

 171        $out.="  i" . $attributes[0]['oid'] . "(document.cart_quantity);\n";
 172        for($o=1; $o<sizeof($attributes)-1; $o++) {
 173          if ($attributes[$o]['default']!='') {
 174            $out.="  document.cart_quantity['id[".$attributes[$o]['oid']."]'].value=".$attributes[$o]['default'].";\n";
 175            $out.="  i" . $attributes[$o]['oid'] . "(document.cart_quantity);\n";
 176          }
 177          else break;
 178        }
 179        if (($o == sizeof($attributes)-1) && ($attributes[$o]['default']!='')) {
 180          $out.="  document.cart_quantity['id[".$attributes[$o]['oid']."]'].value=".$attributes[$o]['default'].";\n";
 181        }
 182        
 183        // js to not allow add to cart if selections not made

 184        $out.="  function chksel() {\n";
 185        $out.="    var ok=true;\n";
 186        foreach ($attributes as $attr)
 187          $out.="    if (this['id[".$attr['oid']."]'].value==0) ok=false;\n";
 188        $out.="    if (!ok) alert('".TEXT_SELECT_OPTIONS."');\n";
 189        $out.="    return ok;\n";
 190        $out.="  }\n";
 191        $out.="  document.cart_quantity.onsubmit=chksel;\n";
 192        $out.="//--></SCRIPT>\n";
 193        $out.="\n</td></tr>\n";
 194        
 195        return $out;
 196      }
 197  
 198  
 199  /*

 200      Method: _SetConfigurationProperties

 201    

 202      Set local configuration properties

 203    

 204      Parameters:

 205    

 206        $prefix      sting     Prefix for the osCommerce DB constants

 207    

 208      Returns:

 209    

 210        nothing

 211    

 212  */
 213      function _SetConfigurationProperties($prefix) {
 214  
 215        // These properties are not used directly by this class 

 216        // They are set to match how this class displays for the case of a single

 217        // attribute where the parent class _draw_stocked_attributes method is called

 218        $this->show_out_of_stock    = 'False';
 219        $this->mark_out_of_stock    = 'Right';
 220        $this->out_of_stock_msgline = 'False';
 221        $this->no_add_out_of_stock  = 'True';
 222  
 223      }
 224  
 225    }
 226  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7