Location: PHPKode > scripts > Discount Code module for osCommerce > discount-code-module-for-oscommerce/readme.txt
Discount Code module for osCommerce

1. Perform the SQL query to your osCommerce database.

CREATE TABLE `customers_to_discount_codes` (
  `customers_id` int(11) NOT NULL default '0',
  `discount_codes_id` int(11) NOT NULL default '0',
  KEY `customers_id` (`customers_id`)
);

CREATE TABLE `discount_codes` (
  `discount_codes_id` int(11) NOT NULL auto_increment,
  `products_id` int(11) NOT NULL default '0',
  `categories_id` int(11) NOT NULL default '0',
  `orders_total` tinyint(1) NOT NULL default '0',
  `discount_codes` char(8) NOT NULL default '',
  `discount_values` char(8) NOT NULL default '',
  `minimum_order_amount` decimal(15,4) NOT NULL default '0.0000',
  `expires_date` date NOT NULL default '0000-00-00',
  `status` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`discount_codes_id`)
);

2. Copy the new files from the catalog/ folder to your osCommerce shop:

catalog/includes/modules/order_total/ot_discount.php
catalog/includes/languages/english/modules/order_total/ot_discount.php
catalog/admin/discount_codes.php
catalog/admin/includes/languages/english/discount_codes.php

3. Modify the catalog/includes/application_top.php file.
Add to the end of the file:

  // Discount Code - start
  if (MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'true') {
    if (!tep_session_is_registered('sess_discount_code')) tep_session_register('sess_discount_code');
    if (!empty($HTTP_GET_VARS['discount_code'])) $sess_discount_code = tep_db_prepare_input($HTTP_GET_VARS['discount_code']);
    if (!empty($HTTP_POST_VARS['discount_code'])) $sess_discount_code = tep_db_prepare_input($HTTP_POST_VARS['discount_code']);
  }
  // Discount Code - end

4. Modify the catalog/includes/database_tables.php file.
Add to the end of the file:

  // Discount Code - start
  define('TABLE_CUSTOMERS_TO_DISCOUNT_CODES', 'customers_to_discount_codes');
  define('TABLE_DISCOUNT_CODES', 'discount_codes');
  // Discount Code - end

5. Modify the catalog/includes/languages/english.php file.
Add to the end of the file:

// Discount Code - start
define('TEXT_DISCOUNT', 'Discount');
define('TEXT_DISCOUNT_CODE', 'Discount Code');
// Discount Code - end

6. Modify the catalog/checkout_payment.php file.
Find:

<?php
    $radio_buttons++;
  }
?>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>

Add after:

      <!-- Discount Code - start -->
<?php
  if (MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'true') {
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><b><?php echo TEXT_DISCOUNT_CODE; ?></b></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><?php echo tep_draw_input_field('discount_code', $sess_discount_code, 'size="10"'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
  }
?>
      <!-- Discount Code - end -->

7. Modify the catalog/checkout_process.php file.
Find:

//------insert customer choosen option eof ----
    $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
    $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
    $total_cost += $total_products_price;

    $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
  }

Add after:

  // Discount Code - start
  if (MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'true') {
    if (!empty($discount)) {
      $discount_codes_query = tep_db_query("select discount_codes_id from discount_codes where discount_codes = '" . tep_db_input($sess_discount_code) . "'");
      $discount_codes = tep_db_fetch_array($discount_codes_query);

      tep_db_perform('customers_to_discount_codes', array('customers_id' => $customer_id, 'discount_codes_id' => $discount_codes['discount_codes_id']));

      tep_session_unregister('sess_discount_code');
    }
  }
  // Discount Code - end

8. Modify the catalog/admin/includes/database_tables.php file.
Add to the end of the file:

  // Discount Code - start
  define('TABLE_CUSTOMERS_TO_DISCOUNT_CODES', 'customers_to_discount_codes');
  define('TABLE_DISCOUNT_CODES', 'discount_codes');
  // Discount Code - end

9. Modify the catalog/admin/includes/filenames.php file.
Add to the end of the file:

  define('FILENAME_DISCOUNT_CODES', 'discount_codes.php'); // Discount Code

10. Modify the catalog/admin/includes/languages/english.php file.
Add to the end of the file:

// Discount Code - start
define('BOX_CATALOG_DISCOUNT_CODE', 'Discount Codes');
define('TEXT_DISPLAY_NUMBER_OF_DISCOUNT_CODES', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> discount codes)');
// Discount Code - end

11. Modify the catalog/admin/includes/boxes/catalog.php file.
Find:

                                   '<a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_SPECIALS . '</a><br>' .

Add after:

                                   '<a href="' . tep_href_link(FILENAME_DISCOUNT_CODES, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_DISCOUNT_CODE . '</a><br>' . // Discount Code

12. Enable the module under Administration -> Modules -> Order Total -> Discount Code.
Return current item: Discount Code module for osCommerce