Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Include Product Options in Xsell


1Putts

Recommended Posts

Posted

I have the Xsell stuff working but it's not going to be useful unless the customer can select the associated product options as well. I'm not as concerned with getting the quantity on the xsell product established as they can adjust that in the cart.

 

I'm trying to follow the code in catalog/product_info.php where it deals with product options and slip it into the catalog/includes/modules/xsell_products.php file. I believe this is the section from product_info.php that displays and allows options:

 

<?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 = '" . (int)$languages_id . "'");
   $products_attributes = tep_db_fetch_array($products_attributes_query);
   if ($products_attributes['total'] > 0) {
?>
         <table border="0" cellspacing="0" cellpadding="2">
           <tr>
             <td class="tableHeading" colspan="2"><?php echo TEXT_PRODUCT_OPTIONS; ?></td>
           </tr>
<?php
     $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");
     while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
       $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 = '" . $products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "' order by pa.sort_order, pov.products_options_values_name");
       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'])) .') ';
         }
       }

       if (isset($cart->contents[$HTTP_GET_VARS['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;
       }
?>
           <tr>
             <td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
             <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
          </tr>

 

Naturally, it's not as easy as just cutting and pasting. I'm trying to understand the code but I'm just too new at PHP and am struggling with it. If I'm leaving out important information in order to determine what can be done, please let me know.

 

Any help would be very much appreciated. TIA.

Posted

I'll point you in the right (I think) direction, but this is not an easy route.

 

What you need to end up with is a separate form for each "buy now" button that includes the appropriate product options as displayed in the code you show from product_info.php. First thing to do is to find the contrib that tells you how to turn a Buy Now button into a form (this is often suggested as a way to keep spiders from adding items to a cart) and get that working.

 

Then, for each product, in its form, display the attributes based on the product_info.php code. This will create additional form fields that will then be processed when the form is submitted.

Archived

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

×
×
  • Create New...