User Tools

Site Tools


tutorials:zencartmods:tariff.html

Tariff information for each product

If you plan to ship items abroad, the package will end up having to pass through the recipient's customs office. These offices basically look at whats in the package and send a tax bill for any import tariffs or VAT. To speed up shipping (especially with a automated shipping system) its handy to have each items tariff information attached to the product. This tutorial will show how we do this by creating three new product attributes that are stored in the database: Tariff Number, Country of Origin and brief description.

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.

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;  

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)

		       'master_categories_id' => ''
		       );

and replace with

		    'master_categories_id' => '',
		    'products_customs' => '',
		    'products_tariff_country' => 0,
		    'products_tariff' => ''
                    );

Find (line 62)

                                      p.products_price_sorter, p.master_categories_id     

and replace with

                                      p.products_price_sorter, p.master_categories_id,                                                                                                                                                                                        
                                      p.products_customs, p.products_tariff_country, p.products_tariff  

The first few lines of the file should now look like

<?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'] . "'");



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)

      $products_url = $_POST['products_url'];
    }

and repace with

      $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();
    }

Find (Line 513)

          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_SORT_ORDER; ?></td>
            <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . zen_draw_input_field('products_sort_order', $pInfo->products_sort_order); ?></td>
          </tr>

and replace it with

          <tr>
            <td class="main"><?php echo TEXT_PRODUCTS_SORT_ORDER; ?></td>
            <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . 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') . '&nbsp;' . 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>

admin/includes/modules/update_product.php

find (line 52)

                            'products_price_sorter' => zen_db_prepare_input($_POST['products_price_sorter'])
                            );

and replace with

                            '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'])
                            );



And you're done! Go create a new product or edit an existing one to make sure that everything works.

/home/ladyada/public_html/wiki/data/pages/tutorials/zencartmods/tariff.html.txt · Last modified: 2016/01/28 18:05 (external edit)