0

I have my own website in Magento2 and also use my shipping method I have created below function in Model\Service\AbstractService.php

/**
     * Convert weight to kilogram
     *
     * @param $weight
     * @param $weightUnit
     * @param int $roundPrecision
     * @return float
     */
    public function convertWeightToKg($weight, $weightUnit, $roundPrecision = 3)
    {
        return round(
            $this->_carrierHelper->convertMeasureWeight(
                $weight,
                $weightUnit,
                \Zend_Measure_Weight::KILOGRAM
            ),
            $roundPrecision
        );
    }

Now I have created new function like Convert weight to grams

so what to do for this function. give me solution for this.

2
  • 1
    what you want? Question is NOT clear.Please explain what you want to achieve?
    – Amit Bera
    Apr 2, 2019 at 13:15
  • I want created new function like Convert weight to grams above is the example ok Apr 2, 2019 at 13:50

1 Answer 1

0

public function convertWeightToKg($weight, $weightUnit, $roundPrecision = 3)

{

switch ($weightUnit) {

case 'LBS':
    $finalWeight=$weight*453.592;
    return $finalWeight;
    break;

case 'KILOGRAM':
    $finalWeight=$weight*1000;
    return $finalWeight;
    break;

default:
    return $weight;

} }

6
  • let me know if any issues
    – mohith
    Apr 2, 2019 at 17:21
  • This is basic structure you can modifiy as per your need
    – mohith
    Apr 2, 2019 at 17:23
  • what is case for gram weight Apr 4, 2019 at 20:22
  • default will work
    – mohith
    Apr 5, 2019 at 4:18
  • kindly check this and update if any issues
    – mohith
    Apr 5, 2019 at 4:19

Your Answer

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

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