Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Code snippet: display products with options selected


jestapher

Recommended Posts

Posted

I want to display a product with non-default options already selected. This behavior is achieved when a user clicks on a product in the shopping cart but does not work outside of that specific action. The code below allows options to be passed via the $HTTP_GET_VARS['id[]'] array.

 

In product_info.php, comment out the existing tep_draw_pull_down_menu() function call and add:

 

if ($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name_values['products_options_id']]> 0) {

 $default_options_value = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name_values['products_options_id']];

}

elseif ($HTTP_GET_VARS['id'][$products_options_name_values['products_options_id']] > 0) {

 $default_options_value = $HTTP_GET_VARS['id'][$products_options_name_values['products_options_id']];

}

else {

 $default_options_value = '';

}

echo tep_draw_pull_down_menu('id[' . $products_options_name_values['products_options_id'] . ']', $products_options_array, $default_options_value);

 

The if() evaluates true if the user clicks on their cart product (the standard behavior). The elseif() evaluates true if the GET variable id[$foo] -- where $foo is the current product option id -- is greater than 0.

 

To test it out, find the option id and values by viewing the html source for the product, looking for <select name="id[2]"><option value="43"> or somesuch code. Then call product_info.php?products_id=52&id[2]=43 (with your numbers inserted of course).

 

Hope someone finds this useful. Please let me know if anything looks awry.

  • 11 months later...
Posted

Thanks for the posting... I've been trying to do something like this for a while and no luck

I tried to implement this code and when I clicked on the "add to cart" button I got a stream of messages on the left side of screen such as

Warning: in_array(): Wrong datatype for second argument in /public_html/cart/includes/boxes/categories.php on line 31

The page still diplayed the item added to cart but where the "option" is usually shown I just received a dash.

 

Also, since you already twicked with the code that is in charge of the product's options, do you know how I can just get the option a user chose and pass its value to another page. In the next page I want to take that "option" value that was passed and only then add it along with the product to the cart -- do you have any ideas of how I can implement this??

 

Thank you

Who would have thought that so much can be created from 0`s and 1`s...

Archived

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

×
×
  • Create New...