/*
  $Id: INSTALL_ENG.txt,v v 1.03 2003/11/09

  Product Availability

  Contribution based on:

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 - 2003 osCommerce

  Released under the GNU General Public License
*/

The module has been designed to be intergrated into osCommerce. 

While the module is based on the release version of osCommerce 2.2 Milestone 2, 
It may be possible to intergrate this module with CVS versions of osCommerce 2.2 but no support is given, 
due to the constantly changing code base of the CVS

********  WHAT DOES IT DO???  **********

This module give you the ability to assign various estimated despatch dates and product availability messages 
to your customers (ala amazon.com)

You can assing various messages to each product and these are then displayed immediately under the 
products price on the product_info.php page


********  TO INSTALL  **********

NEW INSTALLATIONS ONLY (FOR UPGRADES SEE THE INCLUDED FILE NAMED UPGRADE_ENG.txt)

1). BACKUP BACKUP BACKUP

2). DID I MENTION BACKUP BACKUP BACKUP???

3). Upload all files to corresponding folders of your osCommerce site.

4). You must also perform a few manual alterations to your osCommerce files

5). Read the FAQ


********  IT IS STRONGLY SUGGESTED TO MAKE A BACK-UP OF THESE FILES FIRST **********


MySQL ALTERATIONS

Insert the new table and data found in the product_availability.sql file into your osCommerce catalog database.


CATALOG ALTERATIONS


In catalog/includes/database_tables.php

add the following to the database table list.:

  define('TABLE_PRODUCTS_AVAILABILITY', 'products_availability');



In catalog/includes/functions/general.php

add the following code to the end of the file before the closing ?>:

  function tep_get_products_availability($products_availability_array = '') {
    if (!is_array($products_availability_array)) $products_availability_array = array();

    $products_availability_query = tep_db_query("select products_availability_id, products_availability_name from " . TABLE_PRODUCTS_AVAILABILITY . " order by products_availability_name");
    while ($products_availability = tep_db_fetch_array($products_availability_query)) {
      $products_availability_array[] = array('id' => $products_availability['products_availability_id'], 'text' => $products_availability['products_availability_name']);
    }

    return $products_availability_array;
  }



In catalog/products_info.php

find the the following code:


<?php
  } else {
    $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
    $product_info = tep_db_fetch_array($product_info_query);

and change to

<?php
 } else {
   $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id,  p.products_availability_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
   $product_info = tep_db_fetch_array($product_info_query);


then find the following code:

    if (tep_not_null($product_info['products_model'])) {
      $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
    } else {
      $products_name = $product_info['products_name'];
    }


and add this immediately after it:

    $products_availability = $product_info['products_availability_id'];

    $products_availability_info_query = tep_db_query("select e.products_availability_name from " . TABLE_PRODUCTS_AVAILABILITY . " e where e.products_availability_id = '" . (int)$products_availability . "' and e.language_id = '" . (int)$languages_id . "'");

    $products_availability_info = tep_db_fetch_array($products_availability_info_query);
    $products_availability_name = $products_availability_info['products_availability_name'];


then find the the following code:

          <tr>
            <td class="pageHeading" valign="top"><?php echo $products_name; ?></td>
            <td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
          </tr>


and add this immediately after it:

<?php
   if (tep_not_null($products_availability_info['products_availability_name'])) {
?>
          <tr>
            <td class="main" align="right" valign="top"></td>
            <td class="main" align="right" valign="top"><b><?php echo TEXT_AVAILABILITY; ?></b>:&nbsp<?php echo $products_availability_name; ?></td>
          </tr>
<?php
   }
?>


In catalog/includes/languages/english/products_info.php

add the the following code:

define('TEXT_AVAILABILITY', 'Availability');


Repeat this last step for any other languages you may have.



ADMIN ALTERATIONS


In admin/categories.php

find the the following code:

          $sql_data_array = array('products_quantity' => tep_db_prepare_input($HTTP_POST_VARS['products_quantity']),
                                  'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']),
                                  'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']),
                                  'products_date_available' => $products_date_available,
                                  'products_weight' => tep_db_prepare_input($HTTP_POST_VARS['products_weight']),
                                  'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']),
                                  'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
                                  'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));

and change the last line of this section to:

                                  'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']),
                                  'products_availability_id' => tep_db_prepare_input($HTTP_POST_VARS['products_availability_id']));


then find the lines:

          } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
            $product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id, from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
            $product = tep_db_fetch_array($product_query);


and change this to:

          } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
            $product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id, products_availability_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
            $product = tep_db_fetch_array($product_query);



then find the lines:

            tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')");
            $dup_products_id = tep_db_insert_id();


and change this to:

            tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_availability_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "', '" . (int)$product['products_availability_id'] . "')");
            $dup_products_id = tep_db_insert_id();


then find the lines:

<?php
  if ($action == 'new_product') {
    $parameters = array('products_name' => '',
                       'products_description' => '',
                       'products_url' => '',
                       'products_id' => '',
                       'products_quantity' => '',
                       'products_model' => '',
                       'products_image' => '',
                       'products_price' => '',
                       'products_weight' => '',
                       'products_date_added' => '',
                       'products_last_modified' => '',
                       'products_date_available' => '',
                       'products_status' => '',
                       'products_tax_class_id' => '',
                       'manufacturers_id' => '');


and change the last line of this section to:

                       'manufacturers_id' => '',
                       'products_availability_id' => '');


then find the lines:

   if (isset ($HTTP_GET_VARS['pID']) && (!$HTTP_POST_VARS) ) {
      $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
      $product = tep_db_fetch_array($product_query);


and change this to:

   if (isset ($HTTP_GET_VARS['pID']) && (!$HTTP_POST_VARS) ) {
      $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id, p.products_availability_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
      $product = tep_db_fetch_array($product_query);


then find the lines:

      $pInfo->objectInfo($product);
    } elseif (tep_not_null($HTTP_POST_VARS)) {
      $pInfo->objectInfo($HTTP_POST_VARS);
      $products_name = $HTTP_POST_VARS['products_name'];
      $products_description = $HTTP_POST_VARS['products_description'];
      $products_url = $HTTP_POST_VARS['products_url'];
    }


and add the following immediately afterwards:

    $products_availability_array = array(array('id' => '', 'text' => TEXT_NONE));
    $products_availability_query = tep_db_query("select products_availability_id, products_availability_name from " . TABLE_PRODUCTS_AVAILABILITY . " order by products_availability_name");
    while ($products_availability = tep_db_fetch_array($products_availability_query)) {
      $products_availability_array[] = array('id' => $products_availability['products_availability_id'],
                                     'text' => $products_availability['products_availability_name']);
    }


then find the lines:

          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?><br><small>(YYYY-MM-DD)</small></td>
            <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;'; ?><script language="javascript">dateAvailable.writeControl(); dateAvailable.dateFormat="yyyy-MM-dd";</script></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>


and add the following immediately afterwards:

          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_AVAILABILITY; ?></td>
            <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_pull_down_menu('products_availability_id', $products_availability_array, $pInfo->products_availability_id); ?></td>
          </tr>

then find the lines:

    } else {
      $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
      $product = tep_db_fetch_array($product_query);


and change this to:

    } else {
      $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id, p.products_availability_id  from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
      $product = tep_db_fetch_array($product_query);


In admin/includes/database_tables.php

add the following to the database table list.:

  define('TABLE_PRODUCTS_AVAILABILITY', 'products_availability');


In admin/includes/filenames.php

add the following to the database table list.:

  define('FILENAME_PRODUCTS_AVAILABILITY', 'products_availability.php');


In admin/includes/boxes/localization.php

find the line:

                                   '<a href="' . tep_href_link(FILENAME_ORDERS_STATUS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_LOCALIZATION_ORDERS_STATUS . '</a>');


and change this to:

                                   '<a href="' . tep_href_link(FILENAME_ORDERS_STATUS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_LOCALIZATION_ORDERS_STATUS . '</a><br>' .
                                   '<a href="' . tep_href_link(FILENAME_PRODUCTS_AVAILABILITY, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_LOCALIZATION_PRODUCTS_AVAILABILITY . '</a>');


In admin/includes/functions/general.php

add the follwing code to the file before the closing ?>:

// Return the shipping ETA in the needed language
// TABLES: products_availability
  function tep_get_products_availability_name($products_availability_id, $language_id) {
    $products_availability_query = tep_db_query("select products_availability_name from " . TABLE_PRODUCTS_AVAILABILITY . " where products_availability_id = '" . (int)$products_availability_id . "' and language_id = '" . (int)$language_id . "'");
    $products_availability = tep_db_fetch_array($products_availability_query);

    return $products_availability['products_availability_name'];
  }


In admin/includes/languages/english.php

find the lines:

// localizaion box text in includes/boxes/localization.php
define('BOX_HEADING_LOCALIZATION', 'Localization');
define('BOX_LOCALIZATION_CURRENCIES', 'Currencies');
define('BOX_LOCALIZATION_LANGUAGES', 'Languages');
define('BOX_LOCALIZATION_ORDERS_STATUS', 'Orders Status');


and add the following code to this:

define('BOX_LOCALIZATION_PRODUCTS_AVAILABILITY', 'Product Availability');


then find the following code:
define('TEXT_DISPLAY_NUMBER_OF_MANUFACTURERS', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> manufacturers)');


and on a new line after it add:

define('TEXT_DISPLAY_NUMBER_OF_PRODUCTS_AVAILABILITY', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> product availability options)');


Then in admin/includes/languages/english/categories.php

add the following code:

define('TEXT_PRODUCTS_AVAILABILITY', 'Products Availability:');

##################################################################################################################



********  TO USE THIS MODULE **********

There are a couple of simple settings in the products and shipping sections of your admins configuration that may need editing.

Simply login to the localization section of your admin, select the Products Availability section and edit the various entries to suit your store.

Now go to your categories section and either enter new products or edit current ones. You will now see a drop down option list near the top of the edit/insert page, where you can insert the option of your choice.


********  IT IS STRONGLY SUGGESTED TO MAKE A BACK-UP OF THESE FILES FIRST **********



********  BUGS **********

If you find any bugs please report them at http://forums.snowtech.com.au or at the osCommerce Support Site
 

********  DEVELOPER **********

Steve Kemp   Snowtech Services  	http://www.snowtech.com.au	(Developer)
	Donate via paypal:  		https://www.paypal.com/xclick/business=info%40alpinehosting.net


********  CREDITS **********

Credit to everyone that has inspired me in the development of this evolving module for osCommerce.