how to add grams to weight_unit under stores-> config->General
Weight_Unit.
Its Having lbs and Kgs i want add Grams also.
Solved! Go to Solution.
Hi @sarithapoleela,
Can you please check below link
Hope it helps you.
Problem solved! Click Kudos & Accept as Solution!
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
Hi @sarithapoleela,
Can you please check below link
Hope it helps you.
Problem solved! Click Kudos & Accept as Solution!
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