====== 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. {{: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. 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 '', '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) products_sort_order); ?> and replace it with products_sort_order); ?> Tariff #: products_tariff); ?> products_tariff_country); ?> products_customs); ?> ==== 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.