Skip to content

Price field overwritten in split view due to incorrect isPreview checkΒ #790

@TresBlue

Description

@TresBlue

Which component is this issue related to?

Umbraco Commerce (Core)

Which Umbraco Commerce version are you using? (Please write the exact version, example: 10.1.0)

13.2.4

Bug summary

Bug: Price field overwritten in split view due to incorrect isPreview check

πŸ› Summary

When using split view in Umbraco, the price field in the second window overwrites the value in the first window.
This happens even though the price field does not vary by culture and should be ignored in the second/split-view editor.

The issue occurs because PriceController uses a captured isPreview variable instead of reading the live $scope.preview value. Inside updateModel(), $scope.preview correctly reflects split view state, but isPreview does not.


βœ”οΈ Expected behavior

  • In split view, the second editor should not update or overwrite price values.
  • $scope.preview should correctly prevent updateModel() from writing values.

❌ Actual behavior

  • In split view, isPreview is always false at controller initialization.
  • updateModel() therefore runs when it should not.
  • This causes the second editor to overwrite the first editor’s price values.

πŸ” Root Cause

Inside the controller:

var isPreview = $scope.preview; // Intended to be true in split view

However:

  • At initialization, $scope.preview is still false even in split view.
  • Inside updateModel(), $scope.preview becomes true, but isPreview does not update.

Thus this condition is incorrect:

if (!isPreview && !vm.loading && vm.store && vm.prices)

βœ… Suggested Fix

Use $scope.preview directly inside updateModel():

- if (!isPreview && !vm.loading && vm.store && vm.prices)
+ if (!$scope.preview && !vm.loading && vm.store && vm.prices)

This guarantees correct split-view behavior.


πŸŽ₯ Reproduction Video

A demonstration of the issue:

https://tres.nl/media/temp/video.mp4


πŸ“„ Code Reference (with fix highlighted)

function PriceController($scope, $routeParams, ucStoreResource,
    ucCurrencyResource, ucUtils, ucRouteCache)
{
    var compositeId = ucUtils.parseCompositeId($routeParams.id);
    var storeId = compositeId.length > 1 ? compositeId[0] : null;
    var currentOrParentNodeId = compositeId.length > 1 ? compositeId[1] : compositeId[0];

    var isDocTypeEditorPreview = $routeParams.section == "settings" && $routeParams.tree == "documentTypes";
    var isPreview = $scope.preview;

    var vm = this;

    vm.model = $scope.model;
    vm.loading = true;
    vm.store = null;
    vm.prices = null;

    vm.options = {
        fraction: !(($scope.model.config?.fraction ?? null) === null) ? $scope.model.config?.fraction : 2
    };

    vm.updateModel = function () {
        // FIX APPLIED HERE ↓↓↓
        if (!$scope.preview && !vm.loading && vm.store && vm.prices)
        {
            var value = {};

            vm.prices.forEach(function (price) {
                if (price.value !== "" && !isNaN(price.value)) {
                    value[price.currencyId] = price.value;
                }
            });

            if (_.isEmpty(value))
                value = undefined;

            var oldValue = $scope.model.value;
            $scope.model.value = value;
            $scope.model.onValueChanged($scope.model.value, oldValue);
        }
    };
}

Specifics

No response

Steps to reproduce

See video

Expected result / actual result

No response

Dependencies

No response


This item has been added to our backlog AB#62133

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions