What is the weight service
The weight service is used to normalize weights into the store's base unit (g by default) as well as convert between different units.
Units
By default the weight service has the following units:
gozlbkg
Adding a Unit
Use addUnit() to add a unit, for example we can add milligrams:
\Aero\Common\Facades\Weight::addUnit('mg', 'mg')
->setNormalizer(function ($value) {
return $value / 1000;
});
setNormalizer defines how to get from that unit to the base unit, which is g.
Removing a Unit
\Aero\Common\Facades\Weight::removeUnit('kg');
Converting between Units
You can use convert() to convert between any two units, or normalize() to convert into the store's base unit.
\Aero\Common\Facades\Weight::convert(1000, 'oz', 'g');
\Aero\Common\Facades\Weight::normalize('oz', 1000);
Setting a base Unit
\Aero\Common\Facades\Weight::setBaseUnit('oz');
When you change base unit, database values will still remain in grams. But weights will be displayed in the new unit on screens such as the fulfillment create page.