Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Option Type Feature v1.4 (for osc 2.2 ms1)


Guest

Recommended Posts

Version 1.4 of the Product Attributes - Option Type Feature is now available.

 

http://www.oscommerce.com/community/contributions,160

 

Version 1.4 upgrades the contribution to the osc 2.2 ms1 code base, provides for the first time a user interface for updating the option type of an option, and fixes a nasty bug that occurs when an end user enters special characters (" ' < > ) into a text option field.

 

For background on the contribution, here is the description from the original posting:

 

The purpose of this contribution is to allow the use of various option types when setting up product attributes. With the current CVS version of osCommerce, all options are displayed with select lists for user input. This contribution specifically adds the ability to display options with text input boxes. This allows a store owner to collect customization/personalization information for a product from the end user. The contribution is written in such a way that the addition of other option types such as Radio Buttons should be reasonably simple to add.

 

Thanks to Dominik Guder for his help with this release of the contribution!

 

-Chandra

Link to comment
Share on other sites

  • Replies 192
  • Created
  • Last Reply

Top Posters In This Topic

Version 1.4 of the Product Attributes - Option Type Feature is now available.

 

The contribution is written in such a way that the addition of other option types such as Radio Buttons should be reasonably simple to add.

 

Do you have an example of how to setup Radio Buttons and Checkboxes using your Add-on?

 

Thanks.

Link to comment
Share on other sites

actually linda you bring up a good point, these features would be nice for a project i'm working on just now.

 

Chandra, even if you could just point us in the right direction.

 

cheers

barry

Link to comment
Share on other sites

i think you should combine the attributes option type selection contrib with option type feature. with this all option type related things like textfiled, radio, select, checkbox are together in one contribution...

WAR is not the answer!

Link to comment
Share on other sites

According to chandra's readme these features can be easily added to her mod. I have looked at what you suggested in the past but didn't persue it due to lack of time.

 

I may persue this soon though as they are features that would be useful to me. Combining the 2 mods is not an option but using one or the other as a reference point is.

 

cheers

barry

Link to comment
Share on other sites

I completely agree that this contribution needs radio buttons and checkboxes! I've been meaning to add them since the beginning. And the thing is, it should be so simple that I don't have much of an excuse for not doing it. Here's what I think needs to be done:

 

1. In catalogincludesconfigure.php

 

Add new defintions:

define('PRODUCTS_OPTIONS_TYPE_RADIO', 2);

define('PRODUCTS_OPTIONS_TYPE_CHECKBOX', 3);

 

2. In catalogproduct_info.php

 

There's an if statment that checks the option type. Change this to a case statement and add the handling for radio buttons and checkboxes. As long as the same naming convention as select lists is used, then all the backend processing should work.

 

3. In adminproducts_attributes.php

 

Update the functions draw_option_type_pulldown() and translate_type_to_name() to include the new option types.

 

I'll try to get this added to the contribution sometime next month, but feel free to take a crack at it before then.

 

-Chandra

Link to comment
Share on other sites

thanks for the reply chandra, i will take a crack at it later today or tomorrow. I will post my progresss here and if i run into any hurdles i'll let you know.

 

cheers

barry

Link to comment
Share on other sites

I got lost on 2 ... :shock:

 

I have the case statement working fine. But I am not certain how to change what the Radio button case statement should be doing.

 

Umm ... have a sample, perhaps? :D

Link to comment
Share on other sites

I tossed in a case statement but I am not sure yet how to alter the code.

<?php

   $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");

   $products_attributes = tep_db_fetch_array($products_attributes_query);

   if ($products_attributes['total'] > 0) {

     echo '<b>' . TEXT_PRODUCT_OPTIONS . '</b><br>' .

          '<table border="0" cellpadding="0" cellspacing"0">';

     // dogu 2003-02-28 update query to pull option_type

     // clr 2003-03-15 add order by statement to query

     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_type, popt.products_options_length, popt.products_options_comment from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "' order by popt.products_options_id");

//      $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");

     while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {

       //dogu 2003-02-28 BEGIN Add if statement to check product option type.  If add more option types, then change this to a case statement.

       switch (true) {

       case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_TEXT):

         // dogu 2003-02-28 add query to pull attribute price and price_prefix

         $products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");

         $products_attribs_array = tep_db_fetch_array($products_attribs_query);

         echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ': </td><td class="main"><input type="text" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] .'">  ' . $products_options_name['products_options_comment'];

         if ($products_attribs_array['options_values_price'] != '0') {

           echo '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

         }

         echo '</td></tr>';

         break;

       case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_RADIO):

         // dogu 2003-02-28 add query to pull attribute price and price_prefix

         $products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");

         $products_attribs_array = tep_db_fetch_array($products_attribs_query);

         echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ': </td><td class="main"><input type="text" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] .'">  ' . $products_options_name['products_options_comment'];

         if ($products_attribs_array['options_values_price'] != '0') {

           echo '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

         }

         echo '</td></tr>';

         break;

      default:

   //dogu 2003-02-28 END Add if statement to check product option type.



       $selected = 0;

       $products_options_array = array();

       echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ':</td><td>' . "n";

       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");

       while ($products_options = tep_db_fetch_array($products_options_query)) {

         $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);

         if ($products_options['options_values_price'] != '0') {

           $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';

         }

       }

       echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']]);

       echo '</td></tr>';

// dogu 2003-02-28 insert closing bracket due to if statement

       }

     }

     echo '</table>';

   }

?>

Link to comment
Share on other sites

Here's the jist of what the checkbox and radio button cases should look like. I'm going to be out of pocket for the next week or so. I'll finish the still to do list and update the official version of the contribution after I get back.

 

Still to do:

+ Select a radio button by default

+ Correctly select/check radio button or checkbox when click product link from shopping cart.

+ Adjust layout of radio buttons

 

-Chandra

 

          case PRODUCTS_OPTIONS_TYPE_CHECKBOX:

           //CLR 2003-03-18 Add logic for checkboxes

           $products_attribs_query = tep_db_query("select distinct patrib.options_values_id, patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");                        

           $products_attribs_array = tep_db_fetch_array($products_attribs_query);

           echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ': </td><td class="main">';

           echo tep_draw_checkbox_field('id[' . $products_options_name['products_options_id'] . ']', $products_attribs_array['options_values_id']);            

           echo $products_options_name['products_options_comment'];

           if ($products_attribs_array['options_values_price'] != '0') {

             echo '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

           }

           echo '</td></tr>';

           break;



         case PRODUCTS_OPTIONS_TYPE_RADIO:

           //CLR 2003-03-18 Add logic for radio buttons            

           echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ': </td><td class="main">';

           $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");

           while ($products_options_array = tep_db_fetch_array($products_options_query)) {

             echo tep_draw_radio_field('id[' . $products_options_name['products_options_id'] . ']', $products_options_array['products_options_values_id']);            

             echo $products_options_array['products_options_values_name'];

             echo $products_options_name['products_options_comment'];             

             if ($products_options_array['options_values_price'] != '0') {

               echo '(' . $products_options_array['price_prefix'] . $currencies->display_price($products_options_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

             }

           }  

           echo '</td></tr>';

           break;

Link to comment
Share on other sites

i got the case statements in there ok now .....

 

and the text and select are working .

 

 

 

now i just need to figure out what to change in the admin

 

 

 

 

how do i add the radio and check options to the admin now .....

 

 

can someone please help ?

 

 

thank you

Link to comment
Share on other sites

what might help you out here is that there is a mod called attributes option type selection which you can find here http://www.oscommerce.com/community/contributions,766. This mod adds check boxes, radio buttons and multiple select lists. This should be a refernce point for you. The readme says that thereis a text function already built in, but it isn't set up at all.

 

hope this helps

 

cheers

barry

Link to comment
Share on other sites

that helped

 

i have them all working as far as showing up

and the admin side working

 

 

however

 

 

if i use checkboxes where a user can select more that one

 

when you click add to cart only the last checked attrib

gets added to cart.

 

 

i must be missing something there but i just cant fugure it out

 

so close .......

 

 

anyone ?

Link to comment
Share on other sites

heres my code im using in product_info.php

 

hope it helps someone .

 

 

<?php

   $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");

   $products_attributes = tep_db_fetch_array($products_attributes_query);

   if ($products_attributes['total'] > 0) {

     echo '<b>' . TEXT_PRODUCT_OPTIONS . '</b><br>' .

          '<table border="0" cellpadding="0" cellspacing"0">';

     // dogu 2003-02-28 update query to pull option_type

     // clr 2003-03-15 add order by statement to query

     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_type, popt.products_options_length, popt.products_options_comment from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "' order by popt.products_options_id");

//      $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");

while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {

       //dogu 2003-02-28 BEGIN Add if statement to check product option type.  If add more option types, then change this to a case statement.

       switch (true) {

       case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_TEXT):

         // dogu 2003-02-28 add query to pull attribute price and price_prefix

         $products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");

         $products_attribs_array = tep_db_fetch_array($products_attribs_query);

         echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ': </td><td class="main"><input type="text" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] .'">  ' . $products_options_name['products_options_comment'];

         if ($products_attribs_array['options_values_price'] != '0') {

           echo '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

         }

         echo '</td></tr>';

         break;

       case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_CHECKBOX):



             //CLR 2003-03-18 Add logic for checkboxes

             $products_attribs_query = tep_db_query("select distinct patrib.options_values_id, patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");

             $products_attribs_array = tep_db_fetch_array($products_attribs_query);

             echo '<tr><td class="main" valign="top">' . $products_options_name['products_options_name'] . ': </td><td class="main">';

             $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");

             while ($products_options_array = tep_db_fetch_array($products_options_query)) {

             echo tep_draw_checkbox_field('id[' . $products_options_name['products_options_id'] . ']', $products_attribs_array['options_values_id']);

             echo $products_options_array['products_options_values_name'];

             echo $products_options_name['products_options_comment'] . '<br>';

             if ($products_attribs_array['options_values_price'] != '0') {

               echo '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

             }

             }

             echo '</td></tr>';

             break;



           case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_RADIO):

             //CLR 2003-03-18 Add logic for radio buttons

             echo '<tr><td class="main" valign="top">' . $products_options_name['products_options_name'] . ': </td><td class="main">';

             $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");

             while ($products_options_array = tep_db_fetch_array($products_options_query)) {

               echo tep_draw_radio_field('id[' . $products_options_name['products_options_id'] . ']', $products_options_array['products_options_values_id']);

               echo $products_options_array['products_options_values_name'];

               echo $products_options_name['products_options_comment'] . '<br>';

               if ($products_options_array['options_values_price'] != '0') {

                 echo '(' . $products_options_array['price_prefix'] . $currencies->display_price($products_options_array['options_values_price'], $product_info_values['products_tax_class_id']) .') ';

               }

             }

             echo '</td></tr>';



             break;



      case ($products_options_name['products_options_type'] == PRODUCTS_OPTIONS_TYPE_SELECT):

   //dogu 2003-02-28 END Add if statement to check product option type.



       $selected = 0;

       $products_options_array = array();

       echo '<tr><td class="main">' . $products_options_name['products_options_name'] . ':</td><td>' . "n";

       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");

       while ($products_options = tep_db_fetch_array($products_options_query)) {

         $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);

         if ($products_options['options_values_price'] != '0') {

           $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';

         }

       }

       echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']]);

       echo '</td></tr>';

// dogu 2003-02-28 insert closing bracket due to if statement



       break;



       }



echo '</td></tr>';

break;

}

     echo '</table>';

   }

?>



       </td>

     </tr>

 

 

 

 

 

can someone please help me with the shopping cart

not storing all the options checked when using check boxes..

 

thank you

Link to comment
Share on other sites

1. In catalogincludesconfigure.php

 

Add new defintions:

 

define('PRODUCTS_OPTIONS_TYPE_RADIO', 2); 

define('PRODUCTS_OPTIONS_TYPE_CHECKBOX', 3);

 

 

2. In catalogproduct_info.php

 

make changes i posted above

 

 

3. In adminproducts_attributes.php

 

under section :

$values[] = array('id' => 0, 'text' => 'Select');

$values[] = array('id' => 1, 'text' => 'Text');

 

add:

 

$values[] = array('id' => 2, 'text' => 'Radio');

$values[] = array('id' => 3, 'text' => 'Checkbox');

 

 

under section :

if ($opt_type == 0) return 'Select';

if ($opt_type == 1) return 'Text';

 

add:

 

if ($opt_type == 2) return 'Radio';

if ($opt_type == 3) return 'Checkbox';

 

 

as i said . when you check more than one checkbox on a product

only one of the attribs get added tothe shopping cart.

 

 

hopefully someone will update the shopping cart.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...