Required Options / Variants After Upgrade 4.16.1 - 4.16.2

Where the problem occurred: Seems like any Store Builder after Upgrade Version 4.16.1 - 4.16.2 (maybe Multi too) - I tried all upgraded versions between 4.16.2 to 4.18.1 and a brand new 4.18.1 store with the demo data.

Details of the problem: “Required” options no longer function as being required for customers when “select box” options are set to “Simultaneous” - This setup used to work great. Now, customers do not have to make any selection to required options as the default 1st “Please, select one” option choice is completely gone and it just selects the first real option Variant choice instead, which may not be what they want, but it is selected anyway. Customers miss critical information on their orders by sometimes not realizing they can change those option selections. And adding insult to injury (this part is not a bug, but a side effect of it), the modifer price (if it has one) of the new default 1st option Variant selection is added to the base product price too, so customers automatically see a price that may be way higher than what they would have selected for that option if given the choice to not have something automatically selected for them when they first get to the product page.

How to reproduce the problem: Create any Store Builder after Version 4.16.2 (you can use demo data to save time). Make any Select box option “Required” with the Options type: Simultaneous - You can use product U0012O5AF0 on the demo data (it’s those 100g Pants). Check out a preview of that product on the front end. If it just goes to the first Variant choice automatically, it is NOT working. If however, the option choice says “Please, select one” as the first choice, then it IS working and I need to stop reporting bugs… :wink:

You can also play around with the option Modifier price to see how bad things could get for customers - Make the Size option “Required”, and add $1000.00 to the “Small” option Variant price and see what happens to the displayed price of those fancy pants on the front end! They go from $30.00 to $1030.00 automagically when the 100g Pants page comes up - which is just another reason why this bug needs fixing asap. Not too many people around the world can buy a $1000 pair of pants, but maybe a larger sized pair of pants would help them with the price if only they somehow knew without thinking about it that that option could be changed with a “Please, select one” notice and a corresponding “The Size field is mandatory.” alert if they try to add to the cart without making a real selection there. If the Required option was working as it should be, they would have to actually choose that option to pay $1000 extra for small pants. I know you can create extra description tags for the options or change the working of options to “Sequential”, but both of those choices are far from optimal solutions and more or a sweep under the rug situation…

The file that probably needs modified is:
/design/themes/responsive/templates/views/products/components/product_options.tpl
I tried reverting that file back to a prior working version when the “Required” options worked as intended to no avail, but I’m guessing there may be some other modifications in other parts of the cart (or with newer server compatibility) that prevent it from working as it did - not too many new changes have been made to that file with the later updates.

Two other posts that are also needing this fix are:
Required Options / Variants After Upgrade 4.16.1 - 4.16.2 (I created this post before discovering it is most likely a bug)
Variations Need Please Select Option (I’m pretty sure this would solve their problems too)

Images:
Required options NOT working:


Older version of the cart working great!


How to select Options type “Simultaneous”:

Update: I found and swapped out another options file with an older version (4.13.1) and the Required options seems to work now on our new test server running 4.18.1, but I’m hesitant to use the older version with all of the changes that were made to it with subsequent upgraded versions.

Here is the file that will need to be updated/modified to make Required Simultaneous Select Box options work again:
/public_html/app/functions/fn.options.php

Part of the problem in the newer versions of fn.options.php appears to make $po.value in /public_html/design/themes/responsive/templates/views/products/components/product_options.tpl now contain the first real Variant value with Simultaneous options instead of being blank (“”) as in the past (or something similar to this). I’m still digging through the code to see if I can pinpoint the exact issue to feel a little better about using the older file, or at least using the newer file with the fewest amount of modifications. Feel free to jump in and lend a hand with troubleshooting the code… :wink: Thanks!

I understand now, yes you are correct, I tried the same,

@johnbol1 : Thanks for confirming! It’s always nice to know I’m not going crazy, or at least not at the moment… :wink:

So I was able to narrow down the code and found a place to make Required Options (Select box / Simultaneous) work again, but I’m not sure if it will break anything else somewhere else - I’m going to try to use it since we desperately need Required Options to work again.
@CS-Cart_team : Please check this out as soon as possible and see if it can be incorporated in the next update or if it will cause issues elsewhere in the cart. Thanks!

So here is what I found - like I said, I’m not sure if it will break anything anywhere else yet:
File: /public_html/app/functions/fn.options.php
File Version 4.18.1 - Line 1929
ORIGINAL:
$product[‘product_options’][$_id][‘value’] = $selected_options[$option[‘option_id’]];

REPLACE WITH:
if (!isset($default_selected_options[$option[‘option_id’]]) || $option[‘required’] == ‘N’) {
$product[‘product_options’][$_id][‘value’] = $selected_options[$option[‘option_id’]];
} else {
unset($selected_options[$option[‘option_id’]]);
}


You may need to refresh templates and cache after saving the file to see the changes - Add ?cc&ctpl to the end of your home admin page, so it would look something like this: https://YourStoreDomainName.com/admin.php?cc&ctpl
(hopefully you also changed the “admin.php” file name to something else with the .php extension when you installed your store to help with added security of your store - How To: Make Your Store More Secure — CS-Cart 4.18.x documentation)

I hope this helps others!

Here is a larger chunk of the fn.options.php code surroundings to help with other versions after 4.16.1 (I commented out the original line of code with // and added some comments, just FYI there in case I needed things switched back in a hurry)
Refence (Lines 1922 - 1939 on version 4.18.1) :

    $product['simultaneous'] = $simultaneous;
}

// Restore selected values
if (!empty($selected_options)) {
    foreach ($product['product_options'] as $_id => $option) {
        if (isset($selected_options[$option['option_id']])) {
            if (!isset($default_selected_options[$option['option_id']]) || $option['required'] == 'N') {
                $product['product_options'][$_id]['value'] = $selected_options[$option['option_id']];
            } else {
                unset($selected_options[$option['option_id']]);
            }
            // $product['product_options'][$_id]['value'] = $selected_options[$option['option_id']];    // ORIGINAL LINE 4.18.1 swap with IF statement between 1929-1933 if needing to put back
        }
    }
}

// Generate combination hash to get images. (Also, if the tracking with options, get amount and product code)

1 Like