Syrve POS API SDK

Displaying the relative amount of modifiers

Displaying the relative amount of modifiers

Considering the value of the IRestaurant.DisplayRelativeNumberOfModifiers setting in Syrve POS calculates the number of modifier portions in string form, which is displayed on the UI.

For example, a dish has the Sour cream modifier, which is included in the group of modifiers. For this modifier is run:

Then if IRestaurant.DisplayRelativeNumberOfModifiers is true it will display:

If IRestaurant.DisplayRelativeNumberOfModifiers is false the absolute amount of modifier in the dish will be displayed:

For the convenience of plugin developers and the possibilities to transfer the logic to their UI, here is an example of how to get a line of the number of modifiers.

The CalculateModifierAmountString method takes

As a result it returns a line of the form <sign><number> which has to be displayed on the UI near the name of the modifier for the user can see on the screen <sign><number> <modifier name>.

public static string CalculateModifierAmountString(decimal modifierAmount, int defaultAmount, bool hideIfDefaultAmount, bool isPaid, bool isAmountIndependentOfParentAmount)
{
    // Set the method of displaying the amount of group modifiers of a dish.
    var showDeltaAmount = PluginContext.Operations.GetHostRestaurant().DisplayRelativeNumberOfModifiers;

    // If the option "Quantity is independent of the quantity of the dish" is enabled, we always write "+N".
    if (isAmountIndependentOfParentAmount)
        return $"+{modifierAmount}";

    // If the modifier is paid or we show the absolute number of modifiers, we write "×N".
    const string charX = "\u00D7";
    var multiplyAmountString = $"{charX}{modifierAmount}";

    if (isPaid || !showDeltaAmount)
        return multiplyAmountString;

    // Shows the relative amount of modifiers.
    var deltaAmount = modifierAmount - defaultAmount;

    switch (deltaAmount)
    {
        case 1:
            return "+";
        case -1:
            return "-";
        case 0 when hideIfDefaultAmount:
            return string.Empty;
        case 0:
            return multiplyAmountString;
        default:
            return $"{deltaAmount:+#;-#;0}";
    }
}