2

How to get the Unit of measure label of product attributes like weight,Length etc in product detail page?

enter image description here

1 Answer 1

4

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'
2
  • How to get it from product detail page?
    – Mujahidh
    May 29, 2019 at 9:37
  • Check updated answer
    – Sohel Rana
    May 29, 2019 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.