Displaying the 'Quantity' box as a selectbox with managable quantity variants

To be able to define whether the Quantity box will be displayed as an input field or a select box in the storefront:
  1. Click on the DB Backup/Restore link located in the Administration side box and then on the Upgrade center one located at the top. Submit the following query in the Update database section:
    ALTER TABLE cscart_products ADD COLUMN quantity_variants varchar(32) NOT NULL default '';
    ALTER TABLE cscart_products ADD COLUMN quantity_selectbox char(1) NOT NULL default 'N';
    INSERT INTO cscart_language_values (`lang_code`, `name`, `value`) VALUES ('EN', 'quantity_selectbox', 'Quantity field as a select box');
    INSERT INTO cscart_language_values (`lang_code`, `name`, `value`) VALUES ('EN', 'quantity_selectbox_notice', '<p style=\"font-size:10px;\">Use the semicolumn sign as a delimeter.</p>');
    INSERT INTO cscart_language_values (`lang_code`, `name`, `value`) VALUES ('EN', 'quantity_selectbox_variants', 'Quantity variants');
  2. Replace the following part of code in the product_details.tpl file located in the skins/[CUSTOMER_ACTIVE_SKIN]/customer/products_pages directory of your CS-Cart installation, where [CUSTOMER_ACTIVE_SKIN] is an active skin of your storefront:
    <input type="text" size="5" class="input-text" id="amount_of_{$product.product_id}" name="product_data[{$product.product_id}][amount]" value="1" style="border: 1px solid #6e9db7;" />

    with this one:
    {if $product.quantity_selectbox == 'Y' && !empty($product.quantity_variants)}
                        <select id="amount_of_{$product.product_id}" name="product_data[{$product.product_id}][amount]" size=1>
                            {foreach from=$amount_var item="var"}
                                <option value={$var}>{$var}</option>
                            {/foreach}
                        </select>
                    {else}            
                        <input type="text" size="5" class="input-text" id="amount_of_{$product.product_id}" name="product_data[{$product.product_id}][amount]" value="1" style="border: 1px solid #6e9db7;" />
                    {/if}

    Save the file.
  3. Replace this part of code in the cart_items.tpl file located in the skins/[CUSTOMER_ACTIVE_SKIN]/customer/cart_pages directory of your CS-Cart installation, where [CUSTOMER_ACTIVE_SKIN] is an active skin of your storefront:
    <input type="text" size="3" id="amount_{$key}" name="cart_products[{$key}][amount]" value="{$product.amount}" class="valign input-text" {if $product.is_edp == 'Y' || $product.exclude_from_calculate}disabled="disabled"{/if} onkeypress="cart_changed = true;"/>

    with this one:
    {if $cart_products[$key].quantity_selectbox == 'Y' && !empty($cart_products[$key].quantity_variants)}
                        <select id="amount_{$key}" name="cart_products[{$key}][amount]" size=1>
                            {foreach from=$amount_var[$key] item="var"}
                                <option value={$var} {if $cart_products[$key].amount == $var} selected="selected"{/if}>{$var}</option>
                            {/foreach}
                        </select>
                    {else}            
                    <input type="text" size="3" id="amount_{$key}" name="cart_products[{$key}][amount]" value="{$product.amount}" class="valign input-text" {if $product.is_edp == 'Y' || $product.exclude_from_calculate}disabled="disabled"{/if} onkeypress="cart_changed = true;"/>
                    {/if}

    Save the file.
  4. Replace this part of code (twice) in the checkout.php file located in the include/customer directory of your CS-Cart installation:
    if (!empty($cart_products)) {
            foreach($cart_products as $k => $v) {
                fn_gather_additional_product_data($cart_products[$k], true, false, true, false);
            }
        }

    with this one:
    if (!empty($cart_products)) {
            foreach($cart_products as $k => $v) {
                fn_gather_additional_product_data($cart_products[$k], true, false, true, false);
                if ($cart_products[$k]['quantity_selectbox'] == 'Y') {
                    $amount_var[$k] = explode(";", $cart_products[$k]['quantity_variants']);
                }
            }
            $smarty->assign('amount_var', $amount_var);
        }

    Save the file.
  5. Replace this part of code in the fn_cart.php file located in the core directory of your CS-Cart installation:
    $_pdata = db_get_row("SELECT $db_tables[products].product_id, $db_tables[products].product_code, $db_tables[products].weight, $db_tables[products].tracking, $db_tables[product_descriptions].product, $db_tables[product_descriptions].short_description, $db_tables[products].is_edp, $db_tables[products].edp_shipping, $db_tables[products].shipping_freight, $db_tables[products].free_shipping, $db_tables[products].zero_price_action FROM $db_tables[products] LEFT JOIN $db_tables[product_descriptions] ON $db_tables[product_descriptions].product_id=$db_tables[products].product_id AND $db_tables[product_descriptions].lang_code='$cart_language' WHERE $db_tables[products].product_id='$product_id' AND $db_tables[products].avail IN ('" . implode("','", $_avails) . "')");

    with this one:
    $_pdata = db_get_row("SELECT $db_tables[products].product_id, $db_tables[products].product_code, $db_tables[products].quantity_selectbox, $db_tables[products].quantity_variants, $db_tables[products].weight, $db_tables[products].tracking, $db_tables[product_descriptions].product, $db_tables[product_descriptions].short_description, $db_tables[products].is_edp, $db_tables[products].edp_shipping, $db_tables[products].shipping_freight, $db_tables[products].free_shipping, $db_tables[products].zero_price_action FROM $db_tables[products] LEFT JOIN $db_tables[product_descriptions] ON $db_tables[product_descriptions].product_id=$db_tables[products].product_id AND $db_tables[product_descriptions].lang_code='$cart_language' WHERE $db_tables[products].product_id='$product_id' AND $db_tables[products].avail IN ('" . implode("','", $_avails) . "')");

    Save the file.
  6. Insert this part of code into the products.php file located in the include/customer directory of your CS-Cart installation:
    if ($product['quantity_selectbox'] == 'Y') {
            $amount_var = explode(";", $product['quantity_variants']);
            $smarty->assign('amount_var', $amount_var);
        }

    above this one:
    // [Breadcrumbs]
        if (!empty($category_id)) {
            sess_register('continue_url');
            $continue_url = "$index_script?$target_name=categories&category_id=$category_id";

    Save the file.
  7. Insert the following part of code into the product_update.tpl file located in the skins/[ADMIN_ACTIVE_SKIN]/admin/products_pages directory of your CS-Cart installation, where [ADMIN_ACTIVE_SKIN] is an active skin of your administrator panel:
    <tr>
        <td class="field-name">{$lang.quantity_selectbox}:</td>
        <td>&nbsp;</td>
        <td>
            <input type="hidden" name="product_data[quantity_selectbox]" value="N" />
            <input type="checkbox" name="product_data[quantity_selectbox]" value="Y" {if $product_data.quantity_selectbox == "Y"}checked="checked"{/if} onchange="product_update_form.submit()"/>
            {if $product_data.quantity_selectbox == "Y"}&nbsp;{$lang.quantity_selectbox_variants}&nbsp;<input type="text" name="product_data[quantity_variants]" size="20" value="{$product_data.quantity_variants|default:''}" class="input-text" />&nbsp;&nbsp;{$lang.quantity_selectbox_notice}{/if}</td>
    </tr>

    above this one:
    <tr>
        <td class="field-name">{$lang.shipping_freight} ({$currencies.$primary_currency.symbol}):</td>
        <td>&nbsp;</td>
        <td>
            <input type="text" name="product_data[shipping_freight]" size="10" value="{$product_data.shipping_freight|default:'0.00'}" class="input-text" /></td>
    </tr>

    Save the file.

As a result it will be possible to define whether the Quantity box will be displayed as an input field or a select box in the storefront and also variants for this select box on the details page of a certain product.

Noticed an error in the article or it is not clear enough? Any suggestions to improve it? Please let us know by filling in the feedback form. Click here.