Copied to clipboard

Flag this post as spam?

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


  • Nguyen Dung Tri 106 posts 606 karma points
    Sep 21, 2016 @ 09:38
    Nguyen Dung Tri
    0

    How to call a function on "ProductEditController"?

    Hello,

    I have added a function in "ProductEditController" from merchello.controller.js (Merchello.FastTrack.Ui\App_Plugins\Merchello\js). Please look for the code below:

    The new function name is changeMicrosoftOffer.

            // Exposed methods
            $scope.save = save;
            $scope.openCopyProductDialog = openCopyProductDialog;
            $scope.loadAllWarehouses = loadAllWarehouses;
            $scope.deleteProductDialog = deleteProductDialog;
            $scope.changeMicrosoftOffer = changeMicrosoftOffer;
    
            function changeMicrosoftOffer() {
                $q.all([
                        offerResource.getOfferCatalog()
                ]).then(function (data) {
                    //$scope.productVariant.microsoftOffers = data[0];
                    var microsoftOffers = data[0];
                    console.log(microsoftOffers);
                });
            }
    
            function openCopyProductDialog() {
                var dialogData = {
                    product: $scope.product,
                    name: '',
                    sku: ''
                };
                dialogService.open({
                    template: '/App_Plugins/Merchello/Backoffice/Merchello/Dialogs/product.copy.html',
                    show: true,
                    callback: processCopyProduct,
                    dialogData: dialogData
                });
            }
    

    In the file "Merchello.FastTrack.Ui\App_Plugins\Merchello\Backoffice\Merchello\directives\productvariant.mainproperties.tpl.html". I add a button to call the function "changeMicrosoftOffer" like this:

    <div>
            <div>
                <label for="changeOffer" style="font-weight: bold;">Change Microsoft Offer</label>
                <a data-ng-click="changeMicrosoftOffer()">Change Microsoft Offer</a>
            </div>
        </div>
    

    When I click the button "Check Microsoft Offer", It does nothing. But when I click OpenCopyProductDialog button, it can open a dialog. How can the OpenCopyProductDialog does effect, but my ChangeMicrosofOffer button doesn't effect on the function? Event they all call the functions inside "ProductEditController". I don't get it, please help me!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 21, 2016 @ 15:25
    Rusty Swayne
    0

    In order for that to work you would need to add the "getOfferCatalog" method in the offerResource factory and then call a method on the OfferApiController which would do whatever it is you are trying to do.

    It would be better to do this thing as a directive so that you can keep your code outside of Merchello's core scripts.

    It would work the same and you would have all of your code (and your own ApiController).

  • Nguyen Dung Tri 106 posts 606 karma points
    Sep 21, 2016 @ 19:46
    Nguyen Dung Tri
    100

    I have my own Api Controller. Let say if I have a function changeMicrosoftOffer in 'merchello.directives', then it works. Because when it direct to view "productVariantMainProperties", it enable $scope.function to any call from the view.

Please Sign in or register to post replies

Write your reply to:

Draft