This shows you the differences between two versions of the page.
tutorials:zencartmods:tariff.html [2011/05/18 19:03] daigo created |
tutorials:zencartmods:tariff.html [2016/01/28 18:05] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | This is a walkthrough for adding tariff data to each product. | ||
- | |||
- | {{:zencartmods:tariff.jpg|}} | ||
- | |||
- | This is also a general purpose tutorial for | ||
- | * adding a new field to each product which is editable from the admin product page. | ||
- | |||
- | |||
- | ==== DB Mods ==== | ||
- | |||
- | As always, ALWAYS BACK UP YOUR DATABASE BEFORE APPLYING DB MODS. | ||
- | |||
- | <code sql> | ||
- | ALTER TABLE `products` ADD `products_customs` TEXT NOT NULL; | ||
- | ALTER TABLE `products` ADD `products_tariff_country` INT NOT NULL; | ||
- | ALTER TABLE `products` ADD `products_tariff` VARCHAR( 255 ) NOT NULL; | ||
- | </code> | ||
- | |||
- | |||
- | ==== Adding a field to products ==== | ||
- | |||
- | We'll be adding three fields (products_customs, products_tariff_country, products_tariff). This method will work in general for any field that you would add to the table 'products'. | ||
- | |||
- | Modified files: | ||
- | * admin/includes/modules/product/collect_info.php | ||
- | * admin/includes/modules/update_product.php | ||
- | |||
- | |||
- | === admin/includes/modules/product/collect_info.php === | ||
- | |||
- | Find (line 41) | ||
- | <code php> | ||
- | 'master_categories_id' => '' | ||
- | ); | ||
- | </code> | ||
- | and replace with | ||
- | <code php> | ||
- | 'master_categories_id' => '', | ||
- | 'products_customs' => '', | ||
- | 'products_tariff_country' => 0, | ||
- | 'products_tariff' => '' | ||
- | ); | ||
- | </code> | ||
- | |||
- | Find (line 62) | ||
- | <code php> | ||
- | p.products_price_sorter, p.master_categories_id | ||
- | </code> | ||
- | and replace with | ||
- | <code php> | ||
- | p.products_price_sorter, p.master_categories_id, | ||
- | p.products_customs, p.products_tariff_country, p.products_tariff | ||
- | </code> | ||
- | |||
- | The first few lines of the file should now look like | ||
- | |||
- | <code php> | ||
- | <?php | ||
- | /** | ||
- | * @package admin | ||
- | * @copyright Copyright 2003-2010 Zen Cart Development Team | ||
- | * @copyright Portions Copyright 2003 osCommerce | ||
- | * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 | ||
- | * @version $Id: collect_info.php 17947 2010-10-13 20:29:41Z drbyte $ | ||
- | */ | ||
- | if (!defined('IS_ADMIN_FLAG')) { | ||
- | die('Illegal Access'); | ||
- | } | ||
- | $parameters = array('products_name' => '', | ||
- | 'products_description' => '', | ||
- | 'products_url' => '', | ||
- | 'products_id' => '', | ||
- | 'products_quantity' => '', | ||
- | 'products_model' => '', | ||
- | 'products_image' => '', | ||
- | 'products_price' => '', | ||
- | 'products_virtual' => DEFAULT_PRODUCT_PRODUCTS_VIRTUAL, | ||
- | 'products_weight' => '', | ||
- | 'products_date_added' => '', | ||
- | 'products_last_modified' => '', | ||
- | 'products_date_available' => '', | ||
- | 'products_status' => '', | ||
- | 'products_tax_class_id' => DEFAULT_PRODUCT_TAX_CLASS_ID, | ||
- | 'manufacturers_id' => '', | ||
- | 'products_quantity_order_min' => '', | ||
- | 'products_quantity_order_units' => '', | ||
- | 'products_priced_by_attribute' => '', | ||
- | 'product_is_free' => '', | ||
- | 'product_is_call' => '', | ||
- | 'products_quantity_mixed' => '', | ||
- | 'product_is_always_free_shipping' => DEFAULT_PRODUCT_PRODUCTS_IS_ALWAYS_FREE_SHIPPING, | ||
- | 'products_qty_box_status' => PRODUCTS_QTY_BOX_STATUS, | ||
- | 'products_quantity_order_max' => '0', | ||
- | 'products_sort_order' => '0', | ||
- | 'products_discount_type' => '0', | ||
- | 'products_discount_type_from' => '0', | ||
- | 'products_price_sorter' => '0', | ||
- | 'master_categories_id' => '', | ||
- | 'products_customs' => '', | ||
- | 'products_tariff_country' => 0, | ||
- | 'products_tariff' => '' | ||
- | ); | ||
- | |||
- | $pInfo = new objectInfo($parameters); | ||
- | |||
- | if (isset($_GET['pID']) && empty($_POST)) { | ||
- | $product = $db->Execute("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_virtual, 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_quantity_order_min, p.products_quantity_order_units, p.products_priced_by_attribute, | ||
- | p.product_is_free, p.product_is_call, p.products_quantity_mixed, | ||
- | p.product_is_always_free_shipping, p.products_qty_box_status, p.products_quantity_order_max, | ||
- | p.products_sort_order, | ||
- | p.products_discount_type, p.products_discount_type_from, | ||
- | p.products_price_sorter, p.master_categories_id, | ||
- | p.products_customs, p.products_tariff_country, p.products_tariff | ||
- | from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd | ||
- | where p.products_id = '" . (int)$_GET['pID'] . "' | ||
- | and p.products_id = pd.products_id | ||
- | and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"); | ||
- | |||
- | </code> | ||
- | |||
- | |||
- | \\ | ||
- | \\ | ||
- | Adding these variables here will auto-magically save these values to the DB, as long as there are corresponding input boxes in the user interface. So let make those next. | ||
- | |||
- | Find (line 74) | ||
- | <code php> | ||
- | $products_url = $_POST['products_url']; | ||
- | } | ||
- | </code> | ||
- | and repace with | ||
- | <code php> | ||
- | $products_url = $_POST['products_url']; | ||
- | } | ||
- | |||
- | $countries_array = array(array('id' => '', 'text' => TEXT_NONE)); | ||
- | $countries = $db->Execute("select countries_id, countries_name | ||
- | from " . TABLE_COUNTRIES . " order by countries_name"); | ||
- | while (!$countries->EOF) { | ||
- | $countries_array[] = array('id' => $countries->fields['countries_id'], | ||
- | 'text' => $countries->fields['countries_name']); | ||
- | $countries->MoveNext(); | ||
- | } | ||
- | </code> | ||
- | |||
- | |||
- | Find (Line 513) | ||
- | <code php> | ||
- | <tr> | ||
- | <td class="main"><?php echo TEXT_PRODUCTS_SORT_ORDER; ?></td> | ||
- | <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_sort_order', $pInfo->products_sort_order); ?></td> | ||
- | </tr> | ||
- | </code> | ||
- | and replace it with | ||
- | <code php> | ||
- | <tr> | ||
- | <td class="main"><?php echo TEXT_PRODUCTS_SORT_ORDER; ?></td> | ||
- | <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_sort_order', $pInfo->products_sort_order); ?></td> | ||
- | </tr> | ||
- | |||
- | <tr> | ||
- | <td colspan="2"><?php echo zen_draw_separator('pixel_black.gif', '100%', '3'); ?></td> | ||
- | </tr> | ||
- | <tr> | ||
- | <td class="main">Tariff #:</td> | ||
- | <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_tariff', $pInfo->products_tariff); ?></td> | ||
- | </tr> | ||
- | <tr> | ||
- | <td class="main"><?php echo 'Country of Origin'; ?></td> | ||
- | <td class="main"><?php echo zen_draw_pull_down_menu('products_tariff_country', $countries_array, $pInfo->products_tariff_country); ?></td> | ||
- | </tr> | ||
- | <tr> | ||
- | <td></td> | ||
- | <td> | ||
- | <?php | ||
- | echo zen_draw_textarea_field('products_customs', 'soft', '100%', '30', $pInfo->products_customs); | ||
- | ?> | ||
- | </td> | ||
- | </tr> | ||
- | </code> | ||
- | |||
- | === admin/includes/modules/update_product.php === | ||
- | |||
- | find (line 52) | ||
- | <code php> | ||
- | 'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter']) | ||
- | ); | ||
- | </code> | ||
- | and replace with | ||
- | <code php> | ||
- | 'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter']), | ||
- | 'products_customs' => zen_db_prepare_input($_POST['products_customs']), | ||
- | 'products_tariff_country' => zen_db_prepare_input($_POST['products_tariff_country']), | ||
- | 'products_tariff' => zen_db_prepare_input($_POST['products_tariff']) | ||
- | ); | ||
- | </code> | ||
- | |||
- | |||
- | \\ | ||
- | \\ | ||
- | And you're done! Go create a new product or edit an existing one to make sure that everything works. | ||