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_query = "select quantity from " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " where products_id = :products_id: AND quantity > 0";
         $attribute_stock_query = $db->bindVars($attribute_stock_query, ':products_id:', $this->products_id, 'integer');
         $attribute_stock = $db->Execute($attribute_stock_query);
         $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;
 }
Пример #2
0
 function _draw_stocked_attributes()
 {
     global $languages_id;
     $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_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");
         $out_of_stock = tep_db_num_rows($attribute_stock_query) == 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>" . 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";
     // 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>" . 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";
     }
     // Draw last option dropdown - no values, no onchange
     $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";
     $out .= $this->_draw_dropdown_sequence_js($attributes);
     return $out;
 }
    function _draw_stocked_attributes()
    {
        global $db, $options_name;
        $out = '';
        $out2 = '';
        $outendecode = '<script type="text/javascript">var htmlEnDeCode = (function() {
    var charToEntityRegex,
        entityToCharRegex,
        charToEntity,
        entityToChar;

    function resetCharacterEntities() {
        charToEntity = {};
        entityToChar = {};
        // add the default set
        addCharacterEntities({
            \'&amp;\'     :   \'&\',
            \'&gt;\'      :   \'>\',
            \'&lt;\'      :   \'<\',
            \'&quot;\'    :   \'"\',
            \'&#39;\'     :   "\'"
        });
    }

    function addCharacterEntities(newEntities) {
        var charKeys = [],
            entityKeys = [],
            key, echar;
        for (key in newEntities) {
            echar = newEntities[key];
            entityToChar[key] = echar;
            charToEntity[echar] = key;
            charKeys.push(echar);
            entityKeys.push(key);
        }
        charToEntityRegex = new RegExp(\'(\' + charKeys.join(\'|\') + \')\', \'g\');
        entityToCharRegex = new RegExp(\'(\' + entityKeys.join(\'|\') + \'|&#[0-9]{1,5};\' + \')\', \'g\');
    }

    function htmlEncode(value){
        var htmlEncodeReplaceFn = function(match, capture) {
            return charToEntity[capture];
        };

        return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
    }

    function htmlDecode(value) {
        var htmlDecodeReplaceFn = function(match, capture) {
            return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10));
        };

        return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn);
    }

    resetCharacterEntities();

    return {
        htmlEncode: htmlEncode,
        htmlDecode: htmlDecode
    };
})();</script>';
        $out .= "\n" . $outendecode;
        $out2 .= "\n" . $outendecode;
        $attributes = array();
        $attributes = $this->_build_attributes_array(true, true);
        if (sizeof($attributes) <= 1) {
            return parent::_draw_stocked_attributes();
        }
        $o = 0;
        // Check stock
        //var_dump($attributes[0]);
        $s = sizeof($attributes[$o]['ovals']);
        for ($a = 0; $a < $s; $a++) {
            // mc12345678 NEED TO PERFORM ABOVE QUERY BASED OFF OF THE INFORMATION IN $attributes[0]['ovals'] to pull only the data associated with the one attribute in the first selection... Needs to be clear enough that the sequence of the data searched for identifies the appropriate attribute.  Also need to make sure that the subsequent data forced to display below actually pulls the out of stock information associated with the sub (sub-sub(sub-sub-sub)) attribute.
            $attribute_stock_query = "select sum(pwas.quantity) as quantity from " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas where pwas.products_id = :products_id: AND pwas.quantity >= 0 AND pwas.stock_attributes like (SELECT products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = :products_id: and options_values_id = :options_values_id:) OR pwas.stock_attributes like CONCAT((SELECT products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = :products_id: and options_values_id = :options_values_id:),',%') or pwas.stock_attributes like CONCAT('%,',(SELECT products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = :products_id: and options_values_id = :options_values_id:),',%') or pwas.stock_attributes like CONCAT('%,',(SELECT products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = :products_id: and options_values_id = :options_values_id:))";
            $attribute_stock_query = $db->bindVars($attribute_stock_query, ':products_id:', $this->products_id, 'integer');
            $attribute_stock_query = $db->bindVars($attribute_stock_query, ':options_values_id:', $attributes[$o]['ovals'][$a]['id'], 'integer');
            $attribute_stock = $db->Execute($attribute_stock_query);
            //echo 'Attrib stock_' . $a . ' is: ' . $attribute_stock->RecordCount();
            $out_of_stock = $attribute_stock->fields['quantity'] == 0;
            // This looks at all variants indicating 0 or no variant being present.  Need to modify to look at the quantity for each variant... So look at the quantity of each and if that quantity is zero then, that line needs to be modified...
            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 . ' - ' . zen_output_string_protected($attributes[$o]['ovals'][$a]['text']);
                        break;
                    case 'Right':
                        $attributes[$o]['ovals'][$a]['text'] = zen_output_string_protected($attributes[$o]['ovals'][$a]['text']) . ' - ' . TEXT_OUT_OF_STOCK;
                        break;
                }
                //end switch
            } elseif ($out_of_stock && $this->show_out_of_stock != 'True') {
                unset($attributes[$o]['ovals'][$a]);
            }
            //end elseif
            //$attribute_stock->MoveNext();
        }
        // end for $a
        // end for $o
        if (sizeof($attributes[0]['ovals']) == 0) {
            // NEED TO DISPLAY A MESSAGE OR ADD SOMETHING TO THE LIST AS THERE
            //  IS NO PRODUCT TO DISPLAY (ALL OUT OF ORDER) SO NEED TO DO WHAT
            //  NEEDS TO BE DONE IN THAT CONDITION.
        }
        // Draw first option dropdown with all values
        // Need to consider if the option name is read only ('products_options_type' == PRODUCTS_OPTIONS_TYPE_READONLY ).  If it is, then simply display it and do not make it "selectable"
        // May want something similar for display only attributes, where the information is displayed but not selectable (grayed out)
        //   See the example for single attributes using the SBA dropdown list for consistent formatting.
        //  Also could consider applying other option name choosing styles here, but need to modify the follow on selectors so that
        //   it is clear what action(s) need to be taken to select the applicable product.  Ideally, this will be something modified
        //   after other functionality is confirmed considering the above "issues".  Perhaps to do this, would want to incorporate things
        //   into attributes.php file or other html drawing to minimize the additional logic and changes.  That said, if incorporated
        //   into base logic, then users are more forced to use this method over alternative methods/have to incorporate all the ons and offs
        //   for this method throughout.
        //  May need to modify the array for the attributes in order to accomodate identification.
        //  Need to add the display of other information such as the attribute image.
        if (PRODUCTS_OPTIONS_SORT_ORDER == '0') {
            $options_order_by = ' order by LPAD(popt.products_options_sort_order,11,"0")';
        } else {
            $options_order_by = ' order by popt.products_options_name';
        }
        $sql = "select distinct popt.products_options_comment  \n              from        " . TABLE_PRODUCTS_OPTIONS . " popt\n              left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa ON (pa.options_id = popt.products_options_id)\n              where           pa.products_id = :products_id:              \n              and             popt.language_id = :languages_id: \n\t\t\t  and             popt.products_options_id = :products_options_id: " . $options_order_by;
        $sql = $db->bindVars($sql, ':products_id:', $this->products_id, 'integer');
        $sql = $db->bindVars($sql, ':languages_id:', $_SESSION['languages_id'], 'integer');
        $sql2 = $db->bindVars($sql, ':products_options_id:', $attributes[0]['oid'], 'integer');
        $products_options_names = $db->Execute($sql2);
        $options_comment[] = $products_options_names->fields['products_options_comment'];
        $options_comment_position[] = $products_options_names->fields['products_options_comment_position'] == '1' ? '1' : '0';
        if ($options_comment[0] != '' and $options_comment_position[0] == '0') {
            $out .= '<tr><td class="attributesComments">' . $options_comment[0] . '</td></tr>';
            $out2 .= '<h3 class="attributesComments">' . $options_comment[0] . '</h3>';
        }
        if ($attributes[0]['otype'] == PRODUCTS_OPTIONS_TYPE_READONLY) {
            // Need to load all readonly option values for this option name that are
            //  associated with this product.
            $out .= '<tr><td align="right" class="main"><b>' . $attributes[0]['oname'] . ":</b></td><td class=\"main\"><input type = \"hidden\" name = \"id[" . $attributes[0]['oid'] . "]\"" . " value=\"" . stripslashes($attributes[0]['ovals'][0]['id']) . "\" />" . $attributes[0]['ovals'][0]['text'] . "</td></tr>\n";
            $out2 .= '<div class="wrapperAttribsOptions">';
        } else {
            $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' => TEXT_SEQUENCED_FIRST . $attributes[0]['oname'])), $attributes[0]['ovals']), $attributes[0]['default'], "onchange=\"i" . $attributes[0]['oid'] . "(this.form);\"") . "</td></tr>\n";
            $out2 .= '<div class="wrapperAttribsOptions">';
            $out2 .= '<h4 class="optionName back">';
            $out2 .= $options_name[0];
            $out2 .= '</h4>';
            $out2 .= '<div class="back">';
            $out2 .= "\n";
            $out2 .= zen_draw_pull_down_menu('id[' . $attributes[0]['oid'] . ']', array_merge(array(array('id' => 0, 'text' => TEXT_SEQUENCED_FIRST . $attributes[0]['oname'])), $attributes[0]['ovals']), $attributes[0]['default'], "id=\"" . "attrib-" . $attributes[0]['oid'] . "\" onchange=\"i" . $attributes[0]['oid'] . "(this.form);\"");
            $out2 .= '</div>';
            $out2 .= '<br class="clearBoth" />';
            $out2 .= '</div>';
        }
        if ($options_comment[0] != '' and $options_comment_position[0] == '1') {
            $out .= '<div class="ProductInfoComments">' . $options_comment[0] . '</div>';
            $out2 .= '<div class="ProductInfoComments">' . $options_comment[0] . '</div>';
        }
        // Draw second to next to last option dropdowns - no values, with onchange
        for ($o = 1; $o < sizeof($attributes) - 1; $o++) {
            // Need to consider if the option name is read only.  If it is, then simply display it and do not make it "selectable"
            //  May need to modify the array for the attributes in order to accomodate identification.
            $sql2 = $db->bindVars($sql, ':products_options_id:', $attributes[$o]['oid'], 'integer');
            $products_options_names = $db->Execute($sql2);
            $options_comment[] = $products_options_names->fields['products_options_comment'];
            $options_comment_position[] = $products_options_names->fields['products_options_comment_position'] == '1' ? '1' : '0';
            if ($options_comment[$o] != '' and $options_comment_position[$o] == '0') {
                $out .= '<tr><td class="attributesComments">' . $options_comment[$o] . '</td></tr>';
                $out2 .= '<h3 class="attributesComments">' . $options_comment[0] . '</h3>';
            }
            // END h3_option_comment
            if ($attributes[$o]['otype'] == PRODUCTS_OPTIONS_TYPE_READONLY) {
                // Need to load all readonly option values for this option name that are
                //  associated with this product.
                $out .= '<tr><td align="right" class="main"><b>' . $attributes[$o]['oname'] . ":</b></td><td class=\"main\"><input type = \"hidden\" name = \"id[" . $attributes[$o]['oid'] . "]\"" . " value=\"" . stripslashes($attributes[$o]['ovals'][0]['id']) . "\" />" . $attributes[$o]['ovals'][0]['text'] . "</td></tr>\n";
                $out2 .= '<div class="wrapperAttribsOptions">';
            } else {
                $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' => TEXT_SEQUENCED_NEXT . $attributes[$o]['oname'])), '', "onchange=\"i" . $attributes[$o]['oid'] . "(this.form);\"") . "</td></tr>\n";
                $out2 .= '<div class="wrapperAttribsOptions">';
                $out2 .= '<h4 class="optionName back">';
                $out2 .= $options_name[$o];
                $out2 .= '</h4>';
                $out2 .= '<div class="back">';
                $out2 .= "\n";
                $out2 .= zen_draw_pull_down_menu('id[' . $attributes[$o]['oid'] . ']', array(array('id' => 0, 'text' => TEXT_SEQUENCED_NEXT . $attributes[$o]['oname'])), '', "id=\"" . "attrib-" . $attributes[$o]['oid'] . "\" onchange=\"i" . $attributes[$o]['oid'] . "(this.form);\"");
                $out2 .= '</div>';
                $out2 .= '<br class="clearBoth" />';
                $out2 .= '</div>';
            }
            if ($options_comment[$o] != '' and $options_comment_position[$o] == '1') {
                $out .= '<div class="ProductInfoComments">' . $options_comment[$o] . '</div>';
                $out2 .= '<div class="ProductInfoComments">' . $options_comment[$o] . '</div>';
            }
        }
        // end for $o
        // Draw last option dropdown - no values, no onchange
        // Need to consider if the option name is read only.  If it is, then simply display it and do not make it "selectable"
        //  May need to modify the array for the attributes in order to accomodate identification.
        $sql2 = $db->bindVars($sql, ':products_options_id:', $attributes[$o]['oid'], 'integer');
        $products_options_names = $db->Execute($sql2);
        $options_comment[] = $products_options_names->fields['products_options_comment'];
        $options_comment_position[] = $products_options_names->fields['products_options_comment_position'] == '1' ? '1' : '0';
        if ($options_comment[$o] != '' and $options_comment_position[$o] == '0') {
            $out .= '<tr><td class="attributesComments">' . $options_comment[$o] . '</td></tr>';
            $out2 .= '<h3 class="attributesComments">' . $options_comment[$o] . '</h3>';
        }
        // END h3_option_comment
        if ($attributes[$o]['otype'] == PRODUCTS_OPTIONS_TYPE_READONLY) {
            // Need to load all readonly option values for this option name that are
            //  associated with this product.
            $out .= '<tr><td align="right" class="main"><b>' . $attributes[$o]['oname'] . ":</b></td><td class=\"main\"><input type = \"hidden\" name = \"id[" . $attributes[$o]['oid'] . "]\"" . " value=\"" . stripslashes($attributes[$o]['ovals'][0]['id']) . "\" />" . $attributes[$o]['ovals'][0]['text'] . "</td></tr>\n";
            $out2 .= '<div class="wrapperAttribsOptions">';
        } else {
            $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' => TEXT_SEQUENCED_NEXT . $attributes[$o]['oname'])), '', "onchange=\"i" . $attributes[$o]['oid'] . "(this.form);\"") . "</td></tr>\n";
            $out2 .= '<div class="wrapperAttribsOptions">';
            $out2 .= '<h4 class="optionName back">';
            $out2 .= $options_name[$o];
            $out2 .= '</h4>';
            $out2 .= '<div class="back">';
            $out2 .= "\n";
            $out2 .= zen_draw_pull_down_menu('id[' . $attributes[$o]['oid'] . ']', array(array('id' => 0, 'text' => TEXT_SEQUENCED_NEXT . $attributes[$o]['oname'])), '', "id=\"" . "attrib-" . $attributes[$o]['oid'] . "\" onchange=\"i" . $attributes[$o]['oid'] . "(this.form);\"");
            $out2 .= '</div>';
            $out2 .= '<br class="clearBoth" />';
            $out2 .= '</div>';
        }
        if ($options_comment[$o] != '' and $options_comment_position[$o] == '1') {
            $out .= '<div class="ProductInfoComments">' . $options_comment[$o] . '</div>';
            $out2 .= '<div class="ProductInfoComments">' . $options_comment[$o] . '</div>';
        }
        //      $out.=$this->_draw_out_of_stock_message_js($attributes);
        $out .= $this->_draw_dropdown_sequence_js($attributes);
        $out2 .= $this->_draw_dropdown_sequence_js($attributes);
        return SBA_ZC_DEFAULT === 'true' ? $out2 : $out;
    }