Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Option Types v2 for sts content pages


multimixer

Recommended Posts

Since I don't want to spam the stsv4 or option types v2 forums with this issue I post in a separate topic.

 

The task is to get the features of the option types v2 contribution into the sts content pages. Reading around I didn't found a solution. Also some solutions published at the sts power pack site didn't brought me any result. Still, everything is a valuable input.

 

Till now I did following, all in file includes/modules/sts_inc/product_info.php

 

1) At beginning of the file I changed this

// Start the "Add to Cart" form
   $template_pinfo['startform'] = tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'));

to this

// Start the "Add to Cart" form. Option Types v2 - Added for File upload: 'post', 'enctype="multipart/form-data"'
   $template_pinfo['startform'] = tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data"');

in order to get the uploaded files into the cart (same change as in regular product_info.php

 

2) In the attributes part of the file I added following, same as in original product_info.php

//BOF - Zappo - Option Types v2 - ONE LINE - Initialize $number_of_uploads
   $number_of_uploads = 0;

 

3) this query

  // Select the list of attribute (option) names
 $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 = '" . (int)$languages_id . "' order by popt.products_options_name");

changed to this

//BOF - Zappo - Option Types v2 - Add extra Option Values to Query && Placed Options in new file: option_types.php
$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)$product_info['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_order, popt.products_options_name");

again, same as in original product_info.php

 

4) Immediately under I added following

//BOF option type images ***************************************************************

if ($Default == false) {  // following should hapen if not the default option listing

$sts->start_capture();  

     $Image_Opticount_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_info['products_id'] . "' and options_id ='" . (int)$ProdOpt_ID . "'");
     $Image_Opticount = tep_db_fetch_array($Image_Opticount_query);

     $Image_displayed = 0;

       // BOF - Zappo - PreLoad the Images
       if ($Image_displayed == 1) echo '<div id="ImagePreload">' ;
      echo '<img src="' . OPTIONS_TYPE_IMAGEDIR . $Real_Image_Name . '" alt="'.$pOptValName.'" title="'.$pOptValName.'">';
       if ($Image_displayed != $Image_Opticount['total']) {
         $ImageText[$product_info['products_id']] .= ',';
       } else { // - Zappo - PreLoad the Images - Close Div...
			echo '</div>'; 
			}
	// EOF - Zappo - PreLoad the Images

     $ImageSelector_Name = $ProdOpt_Name . ': <script language="JavaScript" type="text/JavaScript">var ImageText'.$product_info['products_id'] . ' = new Array(' . $ImageText[$product_info['products_id']] . ')</script>';
     $ImageSelector_Dropdown = '<select name="' . $Image_Dropdown_ID . '" onChange="document.getElementById(\'ImageSelect' . $product_info['products_id'] . '\').innerHTML=ImageText'.$product_info['products_id'].'[this.selectedIndex];">' . $Image_Dropdown[$product_info['products_id']] . '</select> ' . $ProdOpt_Comment;	  

$sts->stop_capture ('imgpreload'); // Get the result to the main array
$template_pinfo['imgpreload']= '<div class="ImagePreload">' . $sts->template['imgpreload'] . '</div>' ; // Put it in the product info



  } // end if default == false

//EOF  option type images ******************************************************************

There are 2 reasons for this

a. the image selection (for option type "image") was not working, because nothing was getting preloaded

b. I thougt it would be a good idea to offer a preview of the different options (maybe for the case to preview prints for t-shirts etc). You can change the css class from display:none; to anything you want to have a nice preview.

The code is comes from includes/modules/option_types.php. There are issues with this, read below

 

5) the rest of the file (attributes section only) has many small changes, so I'm posting it in total, you can compare to the original. Everything is placed directly under the above posted

$sts->start_capture();  

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

// - Zappo - Option Types v2 - Include option_types.php - Contains all Option Types, other than the original Drowpdown...
include(DIR_WS_MODULES . 'option_types.php');
// EOF

       if ($Default == true) {  // - Zappo - Option Types v2 - Default action is (standard) dropdown list. If something is not correctly set, we should always fall back to the standard.


   $products_options_array = array();
   $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 = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");

   // For each option name, get the individual attribute (option) choices
   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 the attribute (option) has a price modifier, include it
     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'])) .') ';
     }

   }

   // If we should select a default attribute (option), do it here
   if (isset($cart->contents[$_GET['products_id']]['attributes'][$products_options_name['products_options_id']])) {
     $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
   } else {
     $selected_attribute = false;
   }


   $template_pinfo['optionnames'] .= $products_options_name['products_options_name'] . ':<br><br>'; 
   $template_pinfo['optionchoices'] .=  tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute) . "<br>"; 

 } // End if Default=true

    } // End while

$template_pinfo['optiondrop'] .= '<tr><td>' . $template_pinfo['optionnames']. '</td><td>' . $template_pinfo['optionchoices'] . '</td></tr>' ; 
$sts->stop_capture ('optionsv2'); // Get the result to the main array
$template_pinfo['options']= $sts->template['optionsv2'] . $template_pinfo['optiondrop']; // Put it in the product info

$template_pinfo['uploads'] .= tep_draw_hidden_field('number_of_uploads', $number_of_uploads);

} else { // End if attributes >0

 // No options, blank out the template variables for them
 $template_pinfo['optionheader'] = '';
 $template_pinfo['optionnames'] = '';
 $template_pinfo['optionchoices'] = '';
 $template_pinfo['options'] = '';
 $template_pinfo['imgpreload']= '';
 $template_pinfo['uploads'] .= '';
}

 

The RESULTS of this cooking:

- all attributes are in the sts product content template. Using the tag $options$ you have them all. Everything is working fine, add to cart etc also fine, uplodaded files fine.

 

What are the PROBLEMS:

- The order of the attributes is not free to chose. The reason is that the tag $options$ is getting created with putting together $optionsv2 (=the result of capture) and $optionsdrop (=the old sts tags for dropdown). o, they are not really merged into 1 tag

- The images can be chosen via the drodown, ok. If I make (via css) the tag $imgpreload visible, I see there only 1 image. Looking at my page source code I see them all there and each just once. On the page I see only one image, always the last of the options order.

- In the dropdown for the images, each option appears twice.

 

I hope somebody will take a look at this as I think there is a general need for it from many sts users

 

PS I'm posting the complete attributes section of includes/modules/sts_inc/product_info.php, for the case somebody wants to test

Link to comment
Share on other sites

The complete attributes section of the file includes/modules/sts_inc/product_info.php

//BOF - Zappo - Option Types v2 - ONE LINE - Initialize $number_of_uploads
   $number_of_uploads = 0;
//EOF

// Get the number of product attributes (the select list options)
$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 = '" . (int)$languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
// If there are attributes (options), then...
if ($products_attributes['total'] > 0) {
 // Print the options header
 $template_pinfo['optionheader'] = TEXT_PRODUCT_OPTIONS;


//BOF - Zappo - Option Types v2 - Add extra Option Values to Query && Placed Options in new file: option_types.php
$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)$product_info['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_order, popt.products_options_name");
// EOF

//BOF option type images ***************************************************************

if ($Default == false) {  // following should hapen if not the default option listing

$sts->start_capture();  

     $Image_Opticount_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . (int)$product_info['products_id'] . "' and options_id ='" . (int)$ProdOpt_ID . "'");
     $Image_Opticount = tep_db_fetch_array($Image_Opticount_query);

     $Image_displayed = 0;

       // BOF - Zappo - PreLoad the Images
       if ($Image_displayed == 1) echo '<div id="ImagePreload">' ;
      echo '<img src="' . OPTIONS_TYPE_IMAGEDIR . $Real_Image_Name . '" alt="'.$pOptValName.'" title="'.$pOptValName.'">';
       if ($Image_displayed != $Image_Opticount['total']) {
         $ImageText[$product_info['products_id']] .= ',';
       } else { // - Zappo - PreLoad the Images - Close Div...
			echo '</div>'; 
			}
	// EOF - Zappo - PreLoad the Images

     $ImageSelector_Name = $ProdOpt_Name . ': <script language="JavaScript" type="text/JavaScript">var ImageText'.$product_info['products_id'] . ' = new Array(' . $ImageText[$product_info['products_id']] . ')</script>';
     $ImageSelector_Dropdown = '<select name="' . $Image_Dropdown_ID . '" onChange="document.getElementById(\'ImageSelect' . $product_info['products_id'] . '\').innerHTML=ImageText'.$product_info['products_id'].'[this.selectedIndex];">' . $Image_Dropdown[$product_info['products_id']] . '</select> ' . $ProdOpt_Comment;	  

$sts->stop_capture ('imgpreload'); // Get the result to the main array
$template_pinfo['imgpreload']= '<div class="ImagePreload">' . $sts->template['imgpreload'] . '</div>' ; // Put it in the product info



  } // end if default == false

//EOF  option type images ******************************************************************

$sts->start_capture();  

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

// - Zappo - Option Types v2 - Include option_types.php - Contains all Option Types, other than the original Drowpdown...
include(DIR_WS_MODULES . 'option_types.php');
// EOF

       if ($Default == true) {  // - Zappo - Option Types v2 - Default action is (standard) dropdown list. If something is not correctly set, we should always fall back to the standard.


   $products_options_array = array();
   $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 = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");

   // For each option name, get the individual attribute (option) choices
   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 the attribute (option) has a price modifier, include it
     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'])) .') ';
     }

   }

   // If we should select a default attribute (option), do it here
   if (isset($cart->contents[$_GET['products_id']]['attributes'][$products_options_name['products_options_id']])) {
     $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
   } else {
     $selected_attribute = false;
   }


   $template_pinfo['optionnames'] .= $products_options_name['products_options_name'] . ':<br><br>'; 
   $template_pinfo['optionchoices'] .=  tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute) . "<br>"; 

 } // End if Default=true

    } // End while

$template_pinfo['optiondrop'] .= '<tr><td>' . $template_pinfo['optionnames']. '</td><td>' . $template_pinfo['optionchoices'] . '</td></tr>' ; 
$sts->stop_capture ('optionsv2'); // Get the result to the main array
$template_pinfo['options']= $sts->template['optionsv2'] . $template_pinfo['optiondrop']; // Put it in the product info

$template_pinfo['uploads'] .= tep_draw_hidden_field('number_of_uploads', $number_of_uploads);

} else { // End if attributes >0

 // No options, blank out the template variables for them
 $template_pinfo['optionheader'] = '';
 $template_pinfo['optionnames'] = '';
 $template_pinfo['optionchoices'] = '';
 $template_pinfo['options'] = '';
 $template_pinfo['imgpreload']= '';
 $template_pinfo['uploads'] .= '';
}

Link to comment
Share on other sites

Hi George,

I'm going to be headed in that direction within the next day or so, as I'll also be looking to make a custom product template using the option types features. If I have success with it, I'll keep you informed. ATM I'm having trouble getting my category template to show up so I haven't caught up with you yet.

Johan

Link to comment
Share on other sites

Did you consider looking in the STSv4 Power Pack site to see if someone has already crossed this bridge?

It's a good resource to look to for all things that fall under STSv4 Add-ons.

 

 

 

Bill Kellum

 

Sounds Good Productions

STS Tutorials & more: STSv4.6, STS Add-ons (STS Power Pack), STS V4 Forum STS Forum FREE TEMPLATE

Link to comment
Share on other sites

Did you consider looking in the STSv4 Power Pack site to see if someone has already crossed this bridge?

It's a good resource to look to for all things that fall under STSv4 Add-ons.

Yes, I know it's a very good resource and I used several things from there. For the issue now, there are 2 solutions regarding attributes:

1) QT Pro sts hack (15 4 2007)

2) Attributes sort copier for stsv4 (20 8 2007)

 

I tried to implement the logic of them into the current issue and I think that the result till now is based till a point on this solutions more. But there is no help from there for the concrete problems I'm facing

Link to comment
Share on other sites

  • 2 weeks later...

I have been doing some research on the forums and I think I have found the problem, but unsure of the exact solution.

 

View Postbrainstorming, on Oct 25 2007, 01:46 PM, said:

STS plus Product Attributes Option Type

I'm using STS 4.5.2 with HTCv 2.6.3, which are working really well. I'm now trying to use the contribution Product Attributes Option Type to add a text field where users can add a line of customisation text.

 

PAOT is working well if templates are switched off. If I switch templates on, instead of a text field in the product_info.php page I'm getting a drop-down box containing the option type and attributes value price "Text +£1.00".

 

This happens if I use a product_info.php.html template using the $optionchoices placeholder. If I switch off just the product_info.php.html template, the text field is displayed correctly. The product_info page still picks up basic page layout from the default sts_template.html, but I lose the simple control of layout that the product_info template provides.

 

I have also tried using Option Type to add a textarea for a larger amount of text and that gives similar problems - but doesn't even display well if just the product_info template is switched off.

 

I think I need to create a new placeholder for the text field and use that placeholder in my product_info.php.html template. But I'm not sure how to do it.

 

Or would I be better just hacking the product_info.php page without a template to give me the layout I need?

 

I appreciate that Option Type is not the subject of this forum, but I'd be really grateful for any advice.]

 

 

Same answer as the post before, when using content template for the product_info.php page, the code to display is not coming from catalog/product_info.php anymore, but from catalog/includes/modules/sts_inc/product_info.php, so the code for PAOT must be placed there, and the result must be placed in a placeholder (an easy way is to remove the old code, paste the new one between $sts->start_capture() and $template_pinfo['optionchoices'] = $sts->stop_capture(), then use $optionchoices on your template but not $optionnames.

 

Hopefully this makes sense to you. I have tried to compare and merge the two files but it's hard to figure out exactly what goes where. Maybe this will help you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...