Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce Starts Here!

Adding a New Field to a Zen Cart Table

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: Zen Cart™ 1.5.x.

Adding Radio Button field to the Products Table

For this example, we'll add the field "is_kit" to the Products table, which is needed by the mod Kitbuilder.
This field is a radio button, which is either Yes or No.

  1. Add the new field to the database. Go to Admin->Tools->Install SQL Patches, and in the box, enter
    ALTER TABLE products ADD is_kit tinyint(1) default '0' NOT NULL;
    
    (Note that in the actual Kitbuilder mod, this is done in the provided .sql file. This step is shown for completeness only.)
  2. Modify the file admin/includes/languages/english/product.php and add the following line:
    define('TEXT_IS_KIT', 'Is Product Kit?');
    
  3. Modify the file admin/includes/modules/update_product.php and below the line
                                'products_model' => zen_db_prepare_input($_POST['products_model']),^M
    
    add
                                'is_kit' => zen_db_prepare_input((int)$_POST['is_kit']),
    
  4. Modify the file admin/includes/modules/product/collect_info.php and change the select statement that uses
    p.product_is_free, p.product_is_call,
    
    to
    p.is_kit, p.product_is_free, p.product_is_call,
    
    Then above the comment
    // Product is Free
    
    add
    // is_kit
        if (!isset($pInfo->is_kit)) $pInfo->is_kit = '0';
        switch ($pInfo->is_kit) {
          case '0': $in_is_kit = false; $out_is_kit = true; break;
          case '1': $in_is_kit = true; $out_is_kit = false; break;
          default: $in_is_kit = false; $out_is_kit = true;
        }
    
    Then above
              <tr>
                <td class="main"><?php echo TEXT_PRODUCT_IS_FREE; ?></td>
    
    
    add
    
              <tr>
                <td class="main"><?php echo TEXT_IS_KIT; ?></td>
                <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_radio_field('is_kit', '1', ($in_is_kit==1)) . ' ' . TEXT_YES . '  ' . zen_draw_radio_field('is_kit', '0', ($in_is_kit==0)) . ' ' . TEXT_NO; ?>
                </td>
              </tr>
    

Adding Radio Button field to the Customers Table

An example of how to add a radio button to the Customers table is provided in the Optional Payment Method mod.

Too many steps? I can do this for you if you'd like! Just contact me with your project specifications and I'll build you a quote.