hubcat Posted June 17, 2009 Posted June 17, 2009 I would like there to be a "Please Select [option name]" as the first choice on each of these pull-down menus. That will force people to pick and not accidentally get the first option in the list. I am completely PHP illeterate. :blink: :blush: Can anyone tell me what would need to change? Here is the menu drawing function: string: HTML to display dropdown lists for attributes that stock is tracked for */ function _draw_stocked_attributes() { global $languages_id; $out=''; $attributes = $this->_build_attributes_array(true, false); if (sizeof($attributes)>0) { for($o=0; $o<sizeof($attributes); $o++) { $s=sizeof($attributes[$o]['ovals']); for ($a=0; $a<$s; $a++) { $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[$o]['oid'] . "-" . (int)$attributes[$o]['ovals'][$a]['id'] . "(,|$)' AND products_stock_quantity > 0"); $out_of_stock=(tep_db_num_rows($attribute_stock_query)==0); if ($out_of_stock && ($this->show_out_of_stock == 'True')) { switch ($this->mark_out_of_stock) { case 'Left': $attributes[$o]['ovals'][$a]['text']=TEXT_OUT_OF_STOCK.' - '.$attributes[$o]['ovals'][$a]['text']; break; case 'Right': $attributes[$o]['ovals'][$a]['text'].=' - '.TEXT_OUT_OF_STOCK; break; } } elseif ($out_of_stock && ($this->show_out_of_stock != 'True')) { unset($attributes[$o]['ovals'][$a]); } } $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_values($attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n"; } $out.=$this->_draw_out_of_stock_message_js($attributes); return $out; } } Thank you, Adrienne
spooks Posted June 17, 2009 Posted June 17, 2009 standard way for drop down: //category drop-down $category_array = array(); $category_array[0] = array('id' => '0', 'text' => 'All'); $category_query = tep_db_query("select category_id, category_name from links_categories where status = 1 order by sort_order, category_name"); //sort_order, while ($category_values = tep_db_fetch_array($category_query)) { $category_array[] = array('id' => $category_values['category_id'], 'text' => str_replace('&','&',$category_values['category_name'])); } tep_draw_pull_down_menu('category', $category_array, $cats, 'onchange="this.form.submit();"'); Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
hubcat Posted June 17, 2009 Author Posted June 17, 2009 Hmm... unfortunately, that wont work here because this particular drop down menu is also doing multiple-attribute stock checks with in stock/out of stock message in the menu itself. So I need the rest of the code to stay unchanged but add one line at the top of the menu to force the customer to choose something. This is from QTPro - has anyone else run into this? Adrienne
hubcat Posted June 18, 2009 Author Posted June 18, 2009 Greetings! :-) I was able to hack in a change that mostly works and looks like this: ORIGINAL: $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_values($attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n"; CHANGE: $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_merge(array(array('id'=>0, 'text'=>'Please Select a '.$attributes[$o]['oname'])), $attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n"; Unfortunately, now the default first line creates an Out of Stock message, so that it looks like the entire product is out of stock. So... I think I need to wrap some sort of if statement around that last line (of the full code posted above). In pseudo code: if (a product has been selected [alt: it's not the text line]) $out.=$this->_draw_out_of_stock_message_js($attributes); Alternately, the draw_out_of_stock_message_js function could be changed, but I'm not sure where. Here's the code for that: function _draw_out_of_stock_message_js($attributes) { $out=''; $out.="<tr><td> </td><td><span id=\"oosmsg\" class=errorBox></span>\n"; if (($this->out_of_stock_msgline == 'True' | $this->no_add_out_of_stock == 'True')) { $out.="<script LANGUAGE=\"JavaScript\"><!--\n"; $combinations = array(); $selected_combination = 0; $this->_build_attributes_combinations($attributes, false, 'None', $combinations, $selected_combination); $out.=" function chkstk(frm) {\n"; // build javascript array of in stock combinations $out.=" var stk=".$this->_draw_js_stock_array($combinations).";\n"; $out.=" var instk=false;\n"; // build javascript if statement to test level by level for existance $out.=' '; for ($i=0; $i<sizeof($attributes); $i++) { $out.='if (stk'; for ($j=0; $j<=$i; $j++) { $out.="[frm['id[".$attributes[$j]['oid']."]'].value]"; } $out.=') '; } $out.="instk=true;\n"; $out.=" return instk;\n"; $out.=" }\n"; if ($this->out_of_stock_msgline == 'True') { // set/reset out of stock message based on selection $out.=" function stkmsg(frm) {\n"; $out.=" var instk=chkstk(frm);\n"; $out.=" var span=document.getElementById(\"oosmsg\");\n"; $out.=" while (span.childNodes[0])\n"; $out.=" span.removeChild(span.childNodes[0]);\n"; $out.=" if (!instk)\n"; $out.=" span.appendChild(document.createTextNode(\"".TEXT_OUT_OF_STOCK_MESSAGE."\"));\n"; $out.=" else\n"; $out.=" span.appendChild(document.createTextNode(\" \"));\n"; $out.=" }\n"; //initialize out of stock message $out.=" stkmsg(document.cart_quantity);\n"; } Any suggestions? Thanks again!
Rosyweb Posted June 15, 2010 Posted June 15, 2010 Hi hubcat ok I realise this post is quite old, but did you ever get rid of the OUT OF STOCK message for the Please select option on the pick list. Like you, I've managed to add the please select to the pick lists, just slightly different to your version: ORIGINAL: $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_values($attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n"; CHANGE: $out.='<tr><td align="right" class=main><strong>'.$attributes[$o]['oname'].":</strong></td><td class=main>".tep_draw_pull_down_menu('id['.$attributes[$o]['oid'].']',array_merge(array(array('id'=>"", 'text'=>'Please select ')), $attributes[$o]['ovals']),$attributes[$o]['default'], "onchange=\"stkmsg(this.form);\"")."</td></tr>\n"; and had hoped that by making the Please select text option value go to " " instead of "0" that would do the trick and get rid of the Out of Stock message. It didn't, so somewhere in the code a blank option value is also triggering the out of stock. Like you were, I'm now looking at the javascript that generates the out of stock message and not sure where to change it to ignore a blank option value. But I do think that if I manage to get it to ignore the blank message, it will probably allow it to be added to the basket - which I don't want. Anyway, did you or anyone else manage this successfully? Here's the code that generates the out of stock message in includes/classes/pad_multiple_dropdowns.php (part of the QTpro contribution). function _draw_out_of_stock_message_js($attributes) { $out=''; $out.="<tr><td> </td><td><span id=\"oosmsg\" class=errorBox></span>\n"; if (($this->out_of_stock_msgline == 'True' | $this->no_add_out_of_stock == 'True')) { $out.="<script LANGUAGE=\"JavaScript\"><!--\n"; $combinations = array(); $selected_combination = 0; $this->_build_attributes_combinations($attributes, false, 'None', $combinations, $selected_combination); $out.=" function chkstk(frm) {\n"; // build javascript array of in stock combinations $out.=" var stk=".$this->_draw_js_stock_array($combinations).";\n"; $out.=" var instk=false;\n"; // build javascript if statement to test level by level for existance $out.=' '; for ($i=0; $i<sizeof($attributes); $i++) { $out.='if (stk'; for ($j=0; $j<=$i; $j++) { $out.="[frm['id[".$attributes[$j]['oid']."]'].value]"; } $out.=') '; } $out.="instk=true;\n"; $out.=" return instk;\n"; $out.=" }\n"; if ($this->out_of_stock_msgline == 'True') { // set/reset out of stock message based on selection $out.=" function stkmsg(frm) {\n"; $out.=" var instk=chkstk(frm);\n"; $out.=" var span=document.getElementById(\"oosmsg\");\n"; $out.=" while (span.childNodes[0])\n"; $out.=" span.removeChild(span.childNodes[0]);\n"; $out.=" if (!instk)\n"; $out.=" span.appendChild(document.createTextNode(\"".TEXT_OUT_OF_STOCK_MESSAGE."\"));\n"; $out.=" else\n"; $out.=" span.appendChild(document.createTextNode(\" \"));\n"; $out.=" }\n"; //initialize out of stock message $out.=" stkmsg(document.cart_quantity);\n"; }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.