|
Product option exceptions
When using more than one option groups
of the price modifier or product variant types for one product, not all
the possible combinations of the options may be actually available. This
problem can be handled by setting up exceptions. An exception is a
combination of options with which a product cannot be added to the
shopping cart.
Example:
You sell t-shirts
available in two colors: white and blue. White t-shirts are available in
four sizes: S, M, L and XL. Blue t-shirts are available in the sizes S,
M, L, but not available in XL.
You set up product
variants for the product T-shirt, defining the product option groups as
follows:
|
Color: |
White, Blue |
|
Size: |
S, M, L, XL |
This leaves you with
all the t-shirts available in all the sizes. However, you do not want to
allow your customers to order blue XL t-shirts, as there is not such a
thing. So, you need to disable the combination 'blue + XL'.
A good way to handle
that is to add the said combination to the list of product option
exceptions. Then, when a customer selects the color blue and the size XL
for a t-shirt, the page will display a message saying that the selected
combination of options is unavailable. If, regardless of the message,
the customer attempts to add the product to the cart without first
changing the options, he or she will get a JavaScript warning pop-up
with the same message and will not be allowed to proceed to checkout
until the options are readjusted.
Adding product
option exceptions
To add a combination of options to the
list of product option exceptions:
|
1. |
In the 'Product
Options' section, scroll down to the dialog box titled 'Product
option exceptions': |

The 'Add
exception' section of the dialog box
contains some drop-down boxes titled by the names of the defined option
groups.
|
2. |
Use the drop-down boxes to create
the unavailable combination of options (In the above example, you
would have to select Blue from the
box titled 'Color' and
XL from the box titled 'Size'). |
|
3. |
Click the button
Add exception. |
The combination gets added to the list of
unavailable option combinations in the upper section of the 'Product
option exceptions' dialog box:

Deleting product
option exceptions
To delete one or more product option
exceptions:
|
1. |
In the list of product option
exceptions, select the check boxes next to the exceptions that need
to be removed. |
|
2. |
Click the
Delete selected button. |
Product options validation
The dialog box titled 'Validation
script (Javascript)', which is located in the 'Product
Options' section, allows you to provide JavaScript validation for
product options. The text area provided in this dialog box is intended
for adding JavaScript code that you wish to be called when a customer
selects a certain combination of options.

Validation JavaScript code can be typed
into the text area of the 'Validation script
(Javascript)' dialog box directly or pasted from clipboard. To
save the code entered into the text area, click the
Update
button.
For example, talking about the same
t-shirts and the combination of options that we chose to be unavailable
(Blue + XL), you may wish to add some code that would produce a
JavaScript warning (like "Sorry, the combination of Blue and XL is not
available currently. Please check back later") on the screen when
someone tries to add a blue XL t-shirt to the cart.
The following code sample highlights the
use of JavaScript for creating a JavaScript warning:
var value = product_option_value("Color");
var value2 = product_option_value("Size");
if (value !== false && value == "Blue" && value2 !== false && value2 == 'XL') {
alert("Sorry, the combination of Blue and XL is not available currently. Please
check back later");
return false;
}
In the above code sample,
Color and Size
are option group names in the default admin language,
Blue and XL
- names of specific option values in the default admin language (Note
that some users may prefer using ClassId numbers instead of option group
names).
The
return false
statement at the end stops the submission of the form, which results in
the product not getting added to the cart. However, if we use
return true
instead, the warning message becomes merely
informative and the customer is allowed to proceed to checkout. |