Tip: Automatically Select An 'in-Stock' Combination On Product Page Load

Hi guys.

I would like to share this hint/tip with you all since it's been quite important to us and I'm sure it will be useful to somebody else.

We've recently upgraded to version 4.3.5 and we've noticed a piece of functionality missing that was present in 2.2.5 but not in the 4.3.x versions.

When a customer browsed to a product on our old store, the product loaded and automatically selected a product combination that was 'in-stock'.

We run 99% of our products to 'track with options', so each of our products carry many combinations with inventory/stock quantities attached to each.

In version 4.3.x, the first variant in each option is selected by default and this can often result in the product appearing 'out of stock' to a customer at first glance if the first combination has sold out. I didn't like the fact that customers now had to dig through the options to find a combination that was in stock.

Here's how I changed our cart to automatically load the first in-stock product combination it can.

In /app/functions/fn.catalog.php, look for this block of code (at around line 3700):

unset($product_options);
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if (empty($exceptions)) {
            return $default;
        }
    }

Change it to the following:

unset($product_options);
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if (empty($exceptions) && ($track_with_options != ProductTracking::TRACK_WITH_OPTIONS)) {
            return $default;
        }
    }

Save the file, upload, clear your store cache and test it. That's it :grin:

I've tested this with all types of products (types of tracking and 'combination exceptions' too) with no issues.

Please note that this is a core edit so any future upgrades are bound to remove this.

We haven't upgraded to 4.3.6 yet, but I've checked the source and this doesn't seem to be present in the new version either.

Cheers!

Andrew.

thank you, this was very useful!! :grin: :grin:

This work in 4.3.9?

To answer my own question: Yes, it does work!

been looking for the solution, but in my CS-Cart 4.2.2 the offered solution does not work.

the error i get

is currently unable to handle this request.

HTTP ERROR 500