Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Remove decimal in shipping - grams

Remove decimal in shipping - grams

Locked

Views: 3,677

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
26 Dec 2006, 11:40 AM
#1
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Remove decimal in shipping - grams

Hoping to open by Jan 1st. Yippee.

Question. I've searched and searched but can't get the darn thing to work.

I need to get rid of the decimal place for weight. I use grams.

Already tried to change to INT, SMALLINT and DECIMAL 5,0 in my database but still shows up.

I read something about rounding but don't know how to go about it.

Here is a screenshot of my problem.

http://******/images/zen_question.gif

Thanks for any help in advance.

27 Dec 2006, 8:36 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Remove decimal in shipping - grams

If you can use a sql tool to edit your DB (phpmysql is most common) Here's what i think will fix your issue..

In your database > on the table products > field products weight > change the length/value 5,2 to 5,0 - this should give you your "0" decimal places.

27 Dec 2006, 12:55 PM
#3
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

I tried that. Didn't work. My product info pages don't have the decimal points but everywhere else does.

30 Dec 2006, 3:34 AM
#4
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

Sstill stuck on this one.

I'm looking everywhere but no luck. The products all show, for example 400 grams, but when I add them to the cart a decimal point gets added and two zeros.

Could someone maybe tell me where the function for handling integers is located for shipping weight? Or maybe if there is a class for this?

Does the database store weights anywhere other than product_weight?

So much time for a little dot.

30 Dec 2006, 4:24 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Remove decimal in shipping - grams

It is not the database that needs to be changed on the weight ...

It is the display of the weight in your shipping module ...

You should see that your weight is displaying correctly in the shopping_cart, product _info, listings, etc.

Where it is not displaying correctly appears to be your shipping module itself

If you were to edit that file and look for: weight

... you will probably find that on the display it is specifically saying to show decimal places ...

ie: number_format(blah blah)

30 Dec 2006, 6:15 AM
#6
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

Thank you so much Ajeh!

The number_format was what I was looking for. I did a search for number_format using the Dev Tool Kit and found references to weight with a 2. When I used the override system on my mzmt.php files and changed the 2 to a zero it worked. Thank you.

30 Dec 2006, 6:19 AM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Remove decimal in shipping - grams

You are most welcome ... :smile:

Thanks for letting us know that it was not the database causing you issues on your shipping display weights but the module itself was coded to show decimals and you did not want them ... :cool:

30 Dec 2006, 8:20 AM
#8
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

Sorry Ajeh. This didn't fix it.

When I tried to go through the Steps for an order I found that the changes I had made to mzmt.php made my site hiccup. I replaced the original file and everythign worked again, just with the same darn .00 after.

I'm going to post the entire mzmt.php file. Maybe someone can see where I can make changes to get rid of the decimal point: Thanks.

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Josh Dechant                                      |
// |                                                                      |
// | Portions Copyright (c) 2004 The zen-cart developers                  |
// |                                                                      |
// | [URL]http://www.zen-cart.com/index.php[/URL]                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | [URL]http://www.zen-cart.com/license/2_0.txt[/URL].                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | [EMAIL="[email protected]"][email protected][/EMAIL] so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: mzmt.php,v 1.101 2004-10-31 Josh Dechant Exp $
//
  class mzmt {
    var $code, $title, $description, $icon, $enabled, $num_zones, $num_tables, $delivery_geozone, $order_total;
 
    function mzmt() {
      global $order;
      $this->code = 'mzmt';
      $this->title = MODULE_SHIPPING_MZMT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_MZMT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_MZMT_SORT_ORDER;
      $this->tax_class = MODULE_SHIPPING_MZMT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_MZMT_TAX_BASIS;
      $this->num_geozones = MODULE_SHIPPING_MZMT_NUMBER_GEOZONES;
      $this->num_tables = MODULE_SHIPPING_MZMT_NUMBER_TABLES;
      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_MZMT_STATUS == 'True') ? true : false);
      }
      if ($this->enabled == true) {
        $this->enabled = false;
        for ($n=1; $n<=$this->num_geozones; $n++) {
          if ( ((int)constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_ID') > 0) && ((int)constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_ID') == $this->getGeoZoneID($order->delivery['country']['id'], $order->delivery['zone_id'])) ) {
            $this->enabled = true;
            $this->delivery_geozone = $n;
            break;
          } elseif ( ((int)constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_ID') == 0) && ($n == (int)$this->num_geozones) ) {
            $this->enabled = true;
            $this->delivery_geozone = $n;
            break;
          }
        }
      }
    }
// class methods
    function quote($method = '') {
      global $order, $shipping_weight, $shipping_num_boxes, $template;
      $this->quotes = array('id' => $this->code,
                            'module' => constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TEXT_TITLE'),
                            'methods' => array());
      $geozone_mode = $this->determineTableMethod(constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_MODE'));  
 
      if ($method) {
        $j = substr($method, 5);
        $shipping = $this->determineShipping(split("[:,]" , constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TABLE_' . $j)));
        if ($geozone_mode == 'weight') {
          $shipping = $shipping * $shipping_num_boxes;
          // show boxes if weight
          switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
            case (0):
              $show_box_weight = '';
              break;
            case (1):
              $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
              break;
            case (2):
              $show_box_weight = ' (' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
              break;
            default:
              $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
              break;
          }
        }
 
        $this->quotes['methods'][] = array('id' => 'table' . $j,
                                           'title' => constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TABLE_' . $j . '_TEXT_WAY') . $show_box_weight,
                                           'cost' => $shipping + constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_HANDLING'));
      } else {
        for ($j=1; $j<=$this->num_tables; $j++) {
          if (!zen_not_null(constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TABLE_' . $j))) continue;
          $shipping = $this->determineShipping(split("[:,]" , constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TABLE_' . $j)));
          if ($geozone_mode == 'weight') {
            $shipping = $shipping * $shipping_num_boxes;
            // show boxes if weight
            switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
              case (0):
                $show_box_weight = '';
                break;
              case (1):
                $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
                break;
              case (2):
                $show_box_weight = ' (' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
                break;
              default:
                $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
                break;
            }
          }
          $this->quotes['methods'][] = array('id' => 'table' . $j,
                                             'title' => constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_TABLE_' . $j . '_TEXT_WAY') . $show_box_weight,
                                             'cost' => $shipping + constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_HANDLING'));
        }
      }
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }
      if (zen_not_null(constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_ICON'))) $this->quotes['icon'] = zen_image($template->get_template_dir(constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_ICON'), DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . constant('MODULE_SHIPPING_MZMT_GEOZONE_' . $this->delivery_geozone . '_ICON'), $this->title);
      return $this->quotes;
    }  
    function check() {
      global $db;
      if (!isset($this->_check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_MZMT_STATUS'");
        $this->_check = $check_query->RecordCount();
      }
      return $this->_check;
    }
    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable MultiRegion MultiTable Method', 'MODULE_SHIPPING_MZMT_STATUS', 'True', 'Do you want to offer multi-region multi-table rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_MZMT_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_MZMT_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_MZMT_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
      for ($n=1; $n<=$this->num_geozones; $n++) {
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('<hr />Geo Zone $n', 'MODULE_SHIPPING_MZMT_GEOZONE_{$n}_ID', '', 'Enable this for the following geo zone.', '6', '0', 'zen_get_zone_class_title', '_cfg_pull_down_geozones(', now())");
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Geo Zone $n Table Method', 'MODULE_SHIPPING_MZMT_GEOZONE_{$n}_MODE', 'weight', 'The shipping cost is based on the total weight, total price, or total count of the items ordered.', '6', '0', 'zen_cfg_select_option(array(\'weight\', \'price\', \'count\'), ', now())");
 
        for ($j=1; $j<=$this->num_tables; $j++) {
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Geo Zone $n Shipping Table $j', 'MODULE_SHIPPING_MZMT_GEOZONE_{$n}_TABLE_{$j}', '', 'Shipping table $j for this geo zone', '6', '0', now())");
        }
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Geo Zone $n Handling Fee', 'MODULE_SHIPPING_MZMT_GEOZONE_{$n}_HANDLING', '0', 'Handling Fee for this shipping geo zone', '6', '0', now())");
      }
    }
    function remove() {
      global $db;
      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
    function keys() {
      $keys = array('MODULE_SHIPPING_MZMT_STATUS', 'MODULE_SHIPPING_MZMT_TAX_CLASS', 'MODULE_SHIPPING_MZMT_TAX_BASIS', 'MODULE_SHIPPING_MZMT_SORT_ORDER');
      for ($n=1; $n<=$this->num_geozones; $n++) {
        $keys[] = 'MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_ID';
        $keys[] = 'MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_MODE';
        $keys[] = 'MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_HANDLING';
        for ($j=1; $j<=$this->num_tables; $j++) {
          $keys[] = 'MODULE_SHIPPING_MZMT_GEOZONE_' . $n . '_TABLE_' . $j;
        }
      }
      return $keys;
    }
    function determineTableMethod($geozone_mode) {
      global $total_count, $shipping_weight;
      switch ($geozone_mode) {
        case 'price':
          if (method_exists($_SESSION['cart'], 'free_shipping_prices')) {
            $this->order_total = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices();
          } else {
            $this->order_total = $_SESSION['cart']->show_total();
          }
          break;
        case 'count':
          if (method_exists($_SESSION['cart'], 'free_shipping_items')) {
            $this->order_total = $total_count - $_SESSION['cart']->free_shipping_items();
          } else {
            $this->order_total = $total_count;
          }
          break;
        case 'weight':
          $this->order_total = $shipping_weight;
          break;
      }
      return $geozone_mode;    
    }
    function determineShipping($table_cost) {
      for ($i=0, $n=sizeof($table_cost); $i<$n; $i+=2) {
        if ($this->order_total >= $table_cost[$i]) {
          $shipping_factor = $table_cost[$i+1];
        }
      }
      if (substr_count($shipping_factor, '%') > 0) {
        $shipping = ((($this->order_total*10)/10)*((str_replace('%', '', $shipping_factor))/100));
      } else {
        $shipping = str_replace('$', '', $shipping_factor);
      }
 
      return $shipping;
    }
    function getGeoZoneID($country_id, $zone_id) {
      global $db;
      // First, check for a Geo Zone that explicity includes the country & specific zone (useful for splitting countries with zones up)
      $zone = $db->Execute("select gz.geo_zone_id from " . TABLE_GEO_ZONES . " gz left join " . TABLE_ZONES_TO_GEO_ZONES . " ztgz on (gz.geo_zone_id = ztgz.geo_zone_id) where ztgz.zone_country_id = '" . (int)$country_id . "' and ztgz.zone_id = '" . (int)$zone_id . "' and LOWER(gz.geo_zone_name) like 'shp%'");
      if ($zone->RecordCount() > 0) {
        return $zone->fields['geo_zone_id'];
      } else {
        // No luck…  Now check for a Geo Zone for the country and "All Zones" of the country.
        $zone = $db->Execute("select gz.geo_zone_id from " . TABLE_GEO_ZONES . " gz left join " . TABLE_ZONES_TO_GEO_ZONES . " ztgz on (gz.geo_zone_id = ztgz.geo_zone_id) where ztgz.zone_country_id = '" . (int)$country_id . "' and (ztgz.zone_id = '0' or ztgz.zone_id is NULL) and LOWER(gz.geo_zone_name) like 'shp%'");
        if ($zone->RecordCount() > 0) {
          return $zone->fields['geo_zone_id'];
        } else {
          return false;
        }
      }
    }
  }
  function _cfg_pull_down_geozones($zone_class_id, $key = '') {
    global $db;
    $name = (($key) ? 'configuration[' . $key . ']' : 'configuration_value');
    $zone_class_array = array(array('id' => '0', 'text' => 'Rest of the World'));
    $zone_class = $db->Execute("select geo_zone_id, geo_zone_name from " . TABLE_GEO_ZONES . " where LOWER(geo_zone_name) like 'shp%' order by geo_zone_name");
    while (!$zone_class->EOF) {
      $zone_class_array[] = array('id' => $zone_class->fields['geo_zone_id'],
                                  'text' => $zone_class->fields['geo_zone_name']);
      $zone_class->MoveNext();
    }
    return zen_draw_pull_down_menu($name, $zone_class_array, $zone_class_id);
  }
?>
30 Dec 2006, 2:55 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Remove decimal in shipping - grams

You should just be able to find all: number_format

And the references to the weight should be ,0 vs ,2

Sounds like perhaps you had a typo the first time around ...

31 Dec 2006, 12:39 AM
#10
kansai_mike avatar

kansai_mike

New Zenner

Join Date:
Dec 2006
Posts:
48
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

Very interesting. It's fixed. Ajeh, the number_format string was the correct thing to change in order to use MZMT and grams without the decimal point. The problem for me was that the file was getting corrupted if I edited it directly using WS_FTP.

I uploaded the original file back to the server from my computer and everything worked fine. I tested by simply uploading via right click and edit through WS_FTP and then (without editing anything) saving the file and then closing it which automatically uploads it. The problem reoccurs. Corrupted.

Next, I made a copy of the mzmt.php file on my hard drive, edited it in Dreamweaver, saved it, uploaded it and renamed it. Bingo. It worked.

Strange. But it works, movin' on.

31 Dec 2006, 12:45 AM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Remove decimal in shipping - grams

You do have to be careful on the TEXT Editor that you use and be sure that all settings are correct so that the file does not have extra characters, tabs etc. added to it when you edit it ...

Otherwise ... well you know ... KaBoom!! :eek:

Thanks for the update !

15 Sep 2008, 10:33 AM
#12
ilonka avatar

ilonka

New Zenner

Join Date:
Nov 2005
Posts:
51
Plugin Contributions:
0

Re: Remove decimal in shipping - grams

kobra:

If you can use a sql tool to edit your DB (phpmysql is most common) Here's what i think will fix your issue..

In your database > on the table products > field products weight > change the length/value 5,2 to 5,0 - this should give you your "0" decimal places.

Hi,

Could you please explain this some more. Cause i have the same problem and can't figure it out. At first it was shown as 15,000.00 grams and whit the changes from Ajeh. BUt know it shows as 15,000 grams. Which stil is not correct it should be shown as 15000 grams.

this is how it is displayed in the productlisting and shoppingcart. So it should be a istake or somethign in the shipping module or database.

please advise cause this is costingme money.

Thanks