Loading...

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

We no longer maintain the Knowledge Base since version 4.3.x. All the latest user and developer documentation for 4.3.x and newer versions is now available at docs.cs-cart.com.

  • This article is available only for CS-Cart versions:
  • 1.3.5
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.amount_var)}
                        <select id="amount_of_{$product.product_id}" name="product_data[{$product.product_id}][amount]" size=1>
                            {foreach from=$product.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 the following part of code in the product_multicolumns.tpl file located in the same directory:
    <input type="hidden" name="product_data[{$product.product_id}][amount]" value="1" />

    with this one:
    <input type="hidden" name="product_data[{$product.product_id}][amount]" value="{if $product.amount_var != ''}{$product.amount_var.0}{else}1{/if}" />

    Save the file.
  4. Replace the following part of code in the buy_now.tpl file located in the same directory:
    <input type="hidden" name="product_data[{$obj_id}][amount]" value="1" />

    with this one:
    <input type="hidden" name="product_data[{$obj_id}][amount]" value="{if $product.amount_var != ''}{$product.amount_var.0}{else}1{/if}" />

    Save the file.
  5. 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].amount_var)}
                        <select id="amount_{$key}" name="cart_products[{$key}][amount]" size=1>
                            {foreach from=$cart_products[$key].amount_var 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.
  6. Replace this part of code in the search_products_generic.php file located in the include/common directory of your CS-Cart installation:
    $fields .= ", products.product_code, products.amount, MIN(prices.price) as price, products.avail, products.list_price, descr1.short_description, IF(descr1.short_description='', descr1.full_description, '') as full_description, products.is_edp";

    with this one:
    $fields .= ", products.product_code, products.amount, products.quantity_variants, products.quantity_selectbox, MIN(prices.price) as price, products.avail, products.list_price, descr1.short_description, IF(descr1.short_description='', descr1.full_description, '') as full_description, products.is_edp";

    Save the file.
  7. Replace this part of code in the search_products_improved.php file located in the same directory:
    $fields .= ", products.product_code, products.amount, prices.price, products.avail, products.list_price, descr1.short_description, IF(descr1.short_description='', descr1.full_description, '') as full_description, products.is_edp";

    with this one:
    $fields .= ", products.product_code, products.amount, products.quantity_variants, products.quantity_selectbox, prices.price, products.avail, products.list_price, descr1.short_description, IF(descr1.short_description='', descr1.full_description, '') as full_description, products.is_edp";

    Save the file.
  8. 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.
  9. Replace this part of code in the fn_catalog.php file located in the same directory:
    global $settings, $cart_language, $auth;

    with this one:
    global $settings, $cart_language, $auth;
    
        if ($product['quantity_selectbox'] == 'Y') {
            $product['amount_var'] = explode(";", $product['quantity_variants']);
        }
        unset($product['quantity_variants']);

    Save the file.
  10. 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.

Home / Knowledge base / Look and feel (design) / Displaying the 'Quantity' box as a selectbox with managable quantity variants