Ever had the annoying occurence when a customer can pick a product without actually picking the size/colour of the item or they just click 'add' and it automatically picks the default for them? Here's how to stop that happening.


Category: oscommerce

To ensure a customer selects an option (rather than just the default), follow these steps.

Step 1
Add to stylesheet.css
.warning-message
{
background: #ffa8a8;
font-size: 12px;
font-weight: 600;
text-align: center;
}
Step 2
In includes/application.top, find
// customer adds a product from the products page
case 'add_product' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {

(around line #356)

Replace the entire case with:-

// customer adds a product from the products page
case 'add_product' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
//we want to cycle through the options to check all options selected!
$attributes_pass_check = true;
if (is_array($HTTP_POST_VARS['id'])) {
reset($HTTP_POST_VARS['id']);
while (list($option, $value) = each($HTTP_POST_VARS['id'])) {
if (!is_numeric($option) || !is_numeric($value)) {
$attributes_pass_check = false;
break;
}
}
}
if ($attributes_pass_check)
{
$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
}else{
global $options_error_message;
$options_error_message = "Please select the options for your product below";
}
}
break;

Step 3
In product_info.php find
while ($products_options = tep_db_fetch_array($products_options_query)) {
ABOVE this, add the line :-
$products_options_array[] = array('id' => '', 'text' => '- please select -');
Step 4
Finally, in product_info.php you want to display there error message, you may wish this inside your text or at the very top. So, add the following in the location you would like the warning to appear

<?php
if ($options_error_message <> "")
{
?>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td class="warning-message"><?php echo $options_error_message; ?></td>
</table>
<?php
}
?>


Comments

Post new comment

The content of this field is kept private and will not be shown publicly.