Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin 35 posts 159 karma points
    Jan 10, 2017 @ 19:15
    Kevin
    0

    Product option saves with 2 defaults

    Hard one to describe, but here goes....

    I have a shared option, colour. I specify 30 colours.

    I have a product that is available in 6 colours (white, black, red, green, blue, & yellow). so I assign it the 6 colours giving me 6 variants. The default colour is white.

    I now want to change the default colour to black, so I edit the product, go to the Product Options tab and change the default colour option to black. But in fact the product now has 2 defaults (isDefaultChoice), black and green. This is confirmed in the database.

    I have been trying to debug and I think the code is in the angular data binding.

    On opening the product everything is fine and the original data is correct.

    On choosing the new default colour the angular event fires and all is correct.

    On clicking "Save" (for the product options), the data is initially fine until it hits the emitService code. It is after this code the $scope.dialogData.options becomes "corrupt" and you can see in the debugger that 2 colours have isDefaultChoice set to true.

        angular.module('merchello').controller('Merchello.ProductOption.Dialogs.ProductOptionEditController', ['$scope', 'eventsService', function($scope, eventsService) {
                $scope.visiblePanel = $scope.dialogData.sharedOptionEditor ? 'sharedoption' : 'newoption';
                var newName = 'merchNewProductOptionSave';
                var sharedEvent = 'merchSharedProductOptionSave';
                $scope.validate = function() {
                    var validation = {
                        valid: false
                    };
                    if ($scope.visiblePanel === 'newoption') {
                        eventsService.emit(newName, validation);
                    } else if ($scope.visiblePanel === 'sharedoption') {
    
    // DATA IS OK HERE
                        eventsService.emit(sharedEvent, validation);
    // DATA HAS 2 isDefaultChoice HERE
    
                    }
                    if (validation.valid) {
                        $scope.submit($scope.dialogData);
                    }
                }
            }
            ]);
    

    Not really sure where to look next. I have set break points on all relevant named variables and can't spot anything so am thinking/guessing it's Angular data binding???? Any pointers on where to look next.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 11, 2017 @ 16:37
    Rusty Swayne
    0

    Thanks for the great description.

    When you say "corrupt" does that mean the actual object is bad, or the result at that point has two default options set?

    Without stepping through myself, my first thought is this may be a scope issue - where the controller or directive handling the event merchSharedProductOptionSave is updating an object in that scope incorrectly.

    Maybe in this directive? https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web.UI.Client/src/views/productoptions/directives/productoptions.associateshared.directive.js#L49

    If you would, please write up an issue in the issue tracker so we can track this - and if you work out the solution please reference the issue in your pull request =)

  • Kevin 35 posts 159 karma points
    Jan 11, 2017 @ 17:50
    Kevin
    0

    The result at that point ends up with two default options, so when the object is posted to the web services, the generated SQL flags two records as the default choice.

    I will write up an issue.

    I will dig deeper but I got stuck (new to angular!). The directive you have mentioned is indeed the one, but not sure where else to set breakpoints to step through. Getting lost in the code.

    Thanks

  • Kevin 35 posts 159 karma points
    Mar 14, 2017 @ 16:09
    Kevin
    0

    I have a fix for this but could do with some guidance on creating a pull request. I have a GitHub account. Should I create a new branch?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Mar 14, 2017 @ 16:51
    Rusty Swayne
    1

    Awesome - and thanks!!!

    Don't think that is necessary, unless you want to do it for organization on your end. Make sure you've updated your local with the latest from the merchello-dev.

    Assuming your fork has the Merchello as a remote named "merchello"

      git remote update
      git merge merchello/merchello-dev
    

    Work out any conflicts - if any ... then just do a push to your origin and do a pull request to the merchello-dev branch.

  • Kevin 35 posts 159 karma points
    Mar 14, 2017 @ 16:50
    Kevin
    0

    More details of this issue and the fix can be found at:

    http://issues.merchello.com/youtrack/issue/M-1287

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Mar 14, 2017 @ 19:09
    Rusty Swayne
    0

    Awesome, thanks Kevin.

Please Sign in or register to post replies

Write your reply to:

Draft