Search code examples
orocommerce

OroCommerce: How to add new product unit?


For some strange reason in so very configurable OroCommerce there is no ability to manage product units and the only few words doc says that its possible to add units via web api. I need to add "days" units and best if do it in code via migration. Is it enough just to make migration like

INSERT INTO `oro_product_unit` (`code`, `default_precision`) VALUES ('day', '0');

and add tranlation messages like

oro.product_unit.day.label.full: day
oro.product.product_unit.day.label.full: day

or need to do smth else?


Solution

  • Product units may be loaded to the database using the data fixtures, like this one that loads default units: https://github.com/oroinc/orocommerce/blob/4.2.1/src/Oro/Bundle/ProductBundle/Migrations/Data/ORM/LoadProductUnitData.php#L47-L52

    In addition, you have to provide translations for the new unit, but there are more messages then you specified in the question: https://github.com/oroinc/orocommerce/blob/ad94fe9bd63db28eae7d4a73743a4cada4f49080/src/Oro/Bundle/ProductBundle/Resources/translations/jsmessages.en.yml#L26-L35