cancel
Showing results for 
Search instead for 
Did you mean: 

Add new unit to weight_unit.

SOLVED

Add new unit to weight_unit.

how to add grams to weight_unit under stores-> config->General

Weight_Unit.

Its Having lbs and Kgs i want add Grams also.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Add new unit to weight_unit.

Hi @sarithapoleela,

 

Can you please check below link

https://magento.stackexchange.com/questions/119930/magento-2-i-would-like-to-add-a-weight-unit-in-gr...

 

Hope it helps you.

Problem solved! Click Kudos & Accept as Solution!

View solution in original post

Re: Add new unit to weight_unit.

Hello @sarithapoleela ,

Magento only provide two-weight unit type which is KG and LBS under store -> configuration -> general section -> locale options ->weight  unit

 

You can customize it

need to override the file 

\magento\vendor\magento\module-directory\Model\Config\Source\WeightUnit.php

 

Add following code in 

\app\code\Custom\Directory\etc\di.xml

 

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Directory\Model\Config\Source\WeightUnit" type="Custom\Directory\Model\Config\Source\WeightUnit" />
</config>

In your 

app\code\Custom\Directory\Model\Config\Source\WeightUnit.php

 

namespace Custom\Directory\Model\Config\Source;

class WeightUnit extends \Magento\Directory\Model\Config\Source\WeightUnit
{
    /**
     * {@inheritdoc}
     */
    public function toOptionArray()
    {
        return [['value' => 'lbs', 'label' => __('lbs')], ['value' => 'kgs', 'label' => __('kgs')], ['value' => 'gms', 'label' => __('grams')]];
    }
}

Note: Be careful with your shipping methods. DHL, UPS, FedEx they allow only KG & LBS.

 

Problem solved? Accept solution and click kudos

View solution in original post

2 REPLIES 2

Re: Add new unit to weight_unit.

Hi @sarithapoleela,

 

Can you please check below link

https://magento.stackexchange.com/questions/119930/magento-2-i-would-like-to-add-a-weight-unit-in-gr...

 

Hope it helps you.

Problem solved! Click Kudos & Accept as Solution!

Re: Add new unit to weight_unit.

Hello @sarithapoleela ,

Magento only provide two-weight unit type which is KG and LBS under store -> configuration -> general section -> locale options ->weight  unit

 

You can customize it

need to override the file 

\magento\vendor\magento\module-directory\Model\Config\Source\WeightUnit.php

 

Add following code in 

\app\code\Custom\Directory\etc\di.xml

 

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Directory\Model\Config\Source\WeightUnit" type="Custom\Directory\Model\Config\Source\WeightUnit" />
</config>

In your 

app\code\Custom\Directory\Model\Config\Source\WeightUnit.php

 

namespace Custom\Directory\Model\Config\Source;

class WeightUnit extends \Magento\Directory\Model\Config\Source\WeightUnit
{
    /**
     * {@inheritdoc}
     */
    public function toOptionArray()
    {
        return [['value' => 'lbs', 'label' => __('lbs')], ['value' => 'kgs', 'label' => __('kgs')], ['value' => 'gms', 'label' => __('grams')]];
    }
}

Note: Be careful with your shipping methods. DHL, UPS, FedEx they allow only KG & LBS.

 

Problem solved? Accept solution and click kudos