How to get the Unit of measure label of product attributes like weight,Length etc in product detail page?
1 Answer
This settings comes from system configuration.
Weight: Stores -> Configurations -> Generale -> Locale Options -> Weight Unit
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
Then
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(ScopeConfigInterface $scopeConfig)
{
$this->scopeConfig = $scopeConfig;
}
Get value:
$weightUnit = $this->scopeConfig->getValue(
'general/locale/weight_unit',
ScopeInterface::SCOPE_STORE
);
For dimension (width, length): here is the logic
vendor/temando/module-shipping-m2/Ui/DataProvider/Product/Form/Modifier/Dimensions.php
($weightUnit === 'kgs') ? 'cm' : 'in'