Skip to content

Precision Weight#


Description#

Support for high precision weights, allowing up to 8 decimal places, has been added in version 10.11.00. With this update the weights of products, attributes, options, and variants support up to 8 decimal digits. The total weights for baskets, orders, and quotes continue to use two decimal digits. This ensures compatibility with shipping rules, price group limitations, and other settings that operate on combined weights.

Updated Admin Settings#

New Weight Units settings have been added to Settings > Store Settings > Store Details tab under the Settings section:

Display Weights in Mixed Units#

When enabled, this setting displays weights in both the main unit (e.g., pounds or kilograms) and the smaller unit (e.g., ounces or grams) for fractional weights within the administrative and runtime interfaces.

For stores using smaller units as the primary weight unit, such as oz or g, the system still applies mixed units but adjusts the calculation to display conversions from the smaller to the larger unit. For example, 24 oz displays as 1 lb, 8 oz, and 1500 g as 1 kg, 500 g.

Additionally, when this setting is enabled, the product details section shows separate inputs for each unit, rather than a single input with a unit selection dropdown.

Display Weights Less Than 1 in Smaller Unit#

When enabled, weights that are less than 1 will automatically be displayed in the next lower weight unit (e.g., ounces or grams). If both this setting and “Display Weights in Mixed Units” are enabled, weights below 1 will only be displayed in the smaller unit. For example, a weight of 0.5 lb will display as 8 oz, and 0.5 kg as 500 g.

Note

This setting only applies when the primary weight unit is kg or lb.

Minimum Precision of Displayed Weight#

This setting controls the minimum number of decimal places shown for weight values. The default precision is set to 2 decimal places to ensure consistency with existing stores, but it can be adjusted anywhere from 0 to 8 decimal places.

When using mixed units, this precision setting only applies to the smaller units (ounces or grams), as larger units (pounds or kilograms) will always be shown as whole numbers.

Database Updates#

Within the database Product, Attribute, Option, and Variant weight fields store values with 8 decimal digits. This also includes Basket and Order Items weights.

ALTER TABLE sNN_AttributeTemplateAttrs
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_AttributeTemplateOptions
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_Products
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_ProductVariantPricing
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_Attributes
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_Options
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_BasketItems
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_BasketOptions
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_OrderItems
    MODIFY weight DB_Type_NUMBER( 16, 8 )

ALTER TABLE sNN_OrderOptions
    MODIFY weight DB_Type_NUMBER( 16, 8 )

JSON#

Miva JSON API inputs can either be direct numbers or structured objects specifying weight units and values, ensuring seamless integration with different data formats.

"weight": 0.3125

or

"weight": {
    "unit": "OZ",
    "value": 5
}

The following JSON API Functions have no applied rounding.

  • BaseSubscription_With_Query:product_weight
  • AttributeTemplateAttribute
  • AttributeTemplateOption
  • AttributeTemplateAttributeList_Load_Query
  • ProductInventoryList_Load_ProductVariants
  • ProductInventoryList_Load_ProductVariants_Filter
  • ProductVariantPricing_Load
  • OrderItem_OnDemandColumns
  • Product_OnDemandColumns
  • Attribute_Load_Code
  • AttributeList
  • Option_Load_Code
  • OptionList_Load_CodeMatch
  • OptionList_Load_Attribute
  • AttributeTemplateOptionList_Load_Attribute
  • AttributeAndOptionList_Load_Product
  • ProductAttribute
  • ProductOption
  • ProductAttributeAndOptionList_Load_Query
  • Runtime_Product_AttributeAndOption
  • Possible_Output
  • Runtime_Product
  • ProductInventoryList_Load_ProductKit

New Functions#

Helper functions have been implemented for the total_weight and formatted_weight tokens that have been added to the basket and order item structures.

Format_Weight( weight )#

This function will format the weight depending on the weight units settings set for the store.

Example Usage#

<mvt:do file="g.Module_Library_Utilities" name="l.void" value="Format_Weight( weight )" />

Decimal_Pad( value, digits )#

This function ensures the return value always has at least the number of specified digits to the right of the decimal, with “0” being used to append to the end of the value.

Example Usage#

<mvt:do file="g.Module_Library_Utilities" name="l.void" value="Decimal_Pad( 1, 2 )" />
<mvt:do file="g.Module_Library_Utilities" name="l.void" value="Decimal_Pad( 7.2, 2 )" />
<mvt:do file="g.Module_Library_Utilities" name="l.void" value="Decimal_Pad( 6.785, 2 )" />
<mvt:do file="g.Module_Library_Utilities" name="l.void" value="Decimal_Pad( 1.23, 0 )" />

Example Output#

Decimal_Pad( 1, 2 ) -> 1.00
Decimal_Pad( 7.2, 2 ) -> 7.20
Decimal_Pad( 6.785, 2 ) -> 6.785
Decimal_Pad( 1.23, 0 ) -> 1.23

JSON Output Updates#

The following JSON functions have been modified to include the formatted_weight output:

  • JSON_OrderItem_OnDemandColumns
  • ProductInventoryList_Load_ProductKit
  • Product_OnDemandColumns
  • Attribute_Load_Code
  • AttributeList
  • Option_Load_Code
  • OptionList_Load_CodeMatch
  • OptionList_Load_Attribute
  • AttributeTemplateOptionList_Load_Attribute
  • AttributeAndOptionList_Load_Product
  • ProductAttribute
  • ProductOption
  • ProductAttributeAndOptionList_Load_Query
  • ProductInventoryList_Load_ProductVariants
  • ProductInventoryList_Load_ProductVariants_Filter
  • ProductVariantPricing_Load
  • Runtime_Product_AttributeAndOption
  • Possible_Output
  • Runtime_Product
  • BaseSubscription_With_Query (as product_formatted_weight)