public static function updateModelFromPropertyBag(
        PropertiesDefinitionInterface $properties,
        ModelInterface $model,
        PropertyValueBagInterface $values
    ) {
        foreach ($values as $propertyName => $value) {
            try {
                if (!$properties->hasProperty($propertyName)) {
                    continue;
                }

                $property = $properties->getProperty($propertyName);
                $extra    = $property->getExtra();
                // Don´t save value if isset property readonly.
                if (empty($extra['readonly'])) {
                    $model->setProperty($propertyName, static::sanitizeValue($property, $value));
                }

                if (empty($extra)) {
                    continue;
                }

                // If always save is true, we need to mark the model as changed.
                if (!empty($extra['alwaysSave'])) {
                    // Set property to generate alias or combined values.
                    if (!empty($extra['readonly'])) {
                        $model->setProperty($propertyName, static::sanitizeValue($property, null));
                    }

                    $model->setMeta($model::IS_CHANGED, true);
                }
            } catch (\Exception $exception) {
                $values->markPropertyValueAsInvalid($propertyName, $exception->getMessage());
            }
        }
    }