Answered

Question about overwrite the existing product detail page

0

I followed the steps on the JavaScript page comment. 

which is 

/* 
 ********************IMPORTANT*******************
Please replace follwing Code Snippet with given code as follows:
 1. At the Beginning of Javascript File
  ##Code To Replace: 
  -----------------
  dsCoreViews.config(function config(xxx) {
            <----Config Code--->
    }).controller('ProductDetailsCtrl',['yyy',function(yyy){
        <----Controller Code--->
    }])
------------------
    ##Replace With: 
------------------
    (function () {
     'use strict';
      module.config('config',['xxx',function config(xxx) {
          <----Config Code--->
        }
        ]).controller('ProductDetailsCtrl',['yyy',function(yyy){
            <----Controller Code--->
        }])
------------------

2. Please Change the Controller Name and Use the new controller name in HTML page also.

3. At the End of Javascript File
  ##Code To Replace: 
  -----------------
      ]);
  ------------
##Replace With: 
------------------
        ]);
    })();
------------------

*/
 
 

However I am having an error disco-1586870954089.js:16 Error: [$controller:ctrlreg] The controller with the name 'CustomProductDetailsCtrl' is not registered.

 

Here is my JS code:

 
  (function () {
        'use strict';
       module.config('config',['$stateProvider',function config($stateProvider) {
        $stateProvider.state('ProductDetails', {
          url: '/:WebAlias/ProductDetails/:id',
          params: {
            WebAlias: { squash: true, value: null },
            item: null,
            productList: null,
            type: null,
            cartId: null
          },
          views: {
            main: {
              templateProvider: ['$stateParams', 'customPageService', function ($stateParams, customPageService) {
                return customPageService.getPageTemplate('ProductDetails', $stateParams.id);
              }],
            }
          },
          data: {
            pageTitle: 'ProductDetails'
          }
        });
      }])
      .controller('CustomProductDetailsCtrl', [
        '$scope',
        '$rootScope',
        '$filter',
        '$stateParams',
        '$window',
        '$timeout',
        'itemsService',
        'cartsService',
        'itemsListService',
        'notificationService',
        'userService',
        'commonSetting',
        'shoppingCartService',
        '$RestService',
        '$mdMedia',
        '$state',
        'metaDataService',
        '$location',
        'autoshipConfiguration',
        'GetSettingsService',
        'titleService',
        'customPageService',
        function (
          $scope,
          $rootScope,
          $filter,
          $stateParams,
          $window,
          $timeout,
          itemsService,
          cartsService,
          itemsListService,
          notificationService,
          userService,
          commonSetting,
          shoppingCartService,
          $RestService,
          $mdMedia,
          $state,
          metaDataService,
          $location,
          autoshipConfiguration,
          GetSettingsService,
          titleService,
          customPageService
        ) {
          $location.search('cartId', $location.search().cartId || $state.params.cartId || $location.search().shopCartId);
          $location.search('type', userService.customerTypeID);
          $location.search('countrycode', commonSetting.commonData.selectedCountry);
    
    
          $window.scrollTo(0, 0);
          $scope.providerList = [{ proiverName: 'facebook', icon: 'zmdi zmdi-facebook' },
          { proiverName: 'twitter', icon: 'zmdi zmdi-twitter' },
          { proiverName: 'pinterest', icon: 'zmdi zmdi-pinterest-box' }];
          titleService.setTitle('pagetitle_productdetails');
          $scope.metaDataService = metaDataService;
          $scope.commonSetting = commonSetting;
          $scope.customPageService = customPageService;
          // an item can come from different pages / contexts, each which need to use diffent variables and call different APIs... this object is a quick fix to determine which vars / calls should be used
          var itemTypes = {
            packs: {
              getItemsCall: 'GetEnrollmentKitItems',
              itemQuantity: 'packQuantity',
              cartItems: 'SelectedPacks',
              itemserviceCall: 'getPackItems'
              //addToCart: 'AddKit'
            },
            order: {
              getItemsCall: 'GetProducts',
              itemQuantity: 'orderQuantity',
              cartItems: 'SelectedOrderItems',
              itemserviceCall: 'getOrderItems'
              //addToCart: 'OrderAddProduct'
            },
            autoship: {
              getItemsCall: 'GetAutoshipItems',
              itemQuantity: 'autoshipQuantity',
              cartItems: 'SelectedAutoOrderItems',
              itemserviceCall: 'getAutoshipItems'
              //addToCart: 'AutoshipAddProduct'
            }
          };
          $scope.cartsService = cartsService;
          $scope.autoshipConfiguration = autoshipConfiguration.init();
          $scope.value = [];
          $scope.$on('orderQuantity', function (events, data) {
            if (
              data.type === $scope.itemType &&
              data.item.ItemCode === $scope.item.ItemCode
            ) {
              $rootScope.OrderQuantityCount = data.remove
                ? 1
                : data.item && data.item.Quantity;
              localStorage.setItem('params.item', JSON.stringify(data.item));
            }
          });
          /**
           * @ngdoc method
           * @name onGetItemsSuccess
           * @description Method calls on success of GetItems API
           * @param {object} result
           */
          function onGetItemsSucces(result) {
            var itemType = type === 'order' ? 'orders' : type == 'packs' ? 'packs' : 'autoship';
            if (Number(result.Status) === 0) {
              itemsService[itemType] = result.Data.map(function (item) {
                item.Price = item.Price || item.Prices[0].Price;
                return item;
              });
    
              itemsListService.products = itemsService[itemType];
              itemsListService.type = type;
            } else {
              notificationService.error('error_', result.ErrorDescription);
            }
            var selectedItem = JSON.parse(localStorage.getItem('params.item'));
            $scope.product = result.Data.map(function (item) {
              item.Price = item.Price || item.Prices[0].Price;
              return item;
            });
            if (selectedItem) {
              $scope.product = _.filter($scope.product, function (product) {
                return product.ItemCode != selectedItem.ItemCode;
              });
            }
            if (itemCode) {
              var isItemExists = false;
              _.each(result.Data, function name(item) {
               if (isNaN(itemCode)?((item.ItemName || '').toLowerCase().replace(/\s/g, '') == itemCode.toLowerCase().replace(/\s/g, '')):(item.ItemCode==itemCode)) {
                  isItemExists = true;
                  $scope.item = transformItem(item);
                  $rootScope.OrderQuantityCount = selectedItem ? (selectedItem.Quantity || 1) : 1;
                  item.Quantity = selectedItem ? (selectedItem.Quantity || 1) : 1;
                  localStorage.setItem('params.item', JSON.stringify(item));
                  localStorage.setItem('params.type', type);
                  localStorage.setItem('params.productList',JSON.stringify($scope.product));
                  $scope.setDefaultValue(item, type);
                }
              });
              if (!isItemExists) {
                $state.go('Products', { WebAlias: $state.params.WebAlias });
              }
            }
          }
          /**
          * @ngdoc method
          * @name getItems
          * @description Method calls GetItems API to get product details
          * @param {object} item
          * @param {string} type
          */
          $scope.getItems = function (type, item) {
            var itemType = type === 'autoship' ? 'autoship' : type == 'packs' ? 'packs' : 'orders';
            var selectedItem = JSON.parse(localStorage.getItem('params.item'));
            if (itemsService[itemType].length > 0) {
              $scope.product = itemsService[itemType];
              //remove selected item form related search products
              if (selectedItem) {
                $scope.product = _.filter($scope.product, function (product) {
                  return product.ItemCode !== selectedItem.ItemCode;
                });
              }
              if (item) {
                $scope.item = transformItem(item);
                $stateParams.item = $scope.item;
                $scope.setDefaultValue(item, type);
                $state.go('ProductDetails', {
                  id: item.ItemCode,
                  WebAlias: $state.params.WebAlias,
                  type:
                    type === 'order'
                      ? 'order'
                      : type == 'packs'
                        ? 'packs'
                        : 'autoship',
                  cartType:
                    type === 'order'
                      ? 'order'
                      : type == 'packs'
                        ? 'packs'
                        : 'autoship',
                  cartId: $state.params.cartId
                });
              }
              else {
                if (type == 'autoship') {
                  itemsService.getAutoshipItems().then(onGetItemsSucces);
                } else if (type == 'packs') {
                  itemsService.getPackItems().then(onGetItemsSucces);
                } else {
                  $scope.customerDataDeferred.promise.then(function () {
                    itemsService.getOrderItems().then(onGetItemsSucces);
                  });
                }
              }
            } else {
              if (type == 'autoship') {
                itemsService.getAutoshipItems().then(onGetItemsSucces);
              } else if (type == 'packs') {
                itemsService.getPackItems().then(onGetItemsSucces);
              } else {
                $scope.customerDataDeferred.promise.then(function () {
                  itemsService.getOrderItems().then(onGetItemsSucces);
                });
              }
            }
          };
    
          $scope.openSelect = function (event) {
            $scope.event = event || $scope.event;
            //this is due to select input fields are not consistant in some browser
            if (window.screen.availWidth < 600 && !event) {
              setTimeout(function () {
                $('.md-select-menu-container.md-active.md-clickable').css('top', ($scope.event.clientY - 20 + 'px'));
              }, 100);
            }
          };
    
    
          $scope.getRelatedProducts = function (item) {
            if (item) {
              var request = {
                CategoryId: item.CategoryId,
                Limit: 4,
                CurrencyCode: ((commonSetting.commonData.CurrencySymbol && commonSetting.commonData.CurrencySymbol[0].CurrencyCode) || 'USD'),
                CountryCode: commonSetting.commonData.selectedCountry,
                LanguageCode: commonSetting.commonData.selectedLanguageCode,
                cartId: shoppingCartService.cartId,
                customertype: userService.customerTypeID,
                RegionID: itemsService.getState()
              };
              $scope.loading=true;
              $RestService.GetTopPurchaseItems(request,true).then(function (result) {
                result = result.data;
                $scope.loading=false;
                if (result && result.Data) {
                  $scope.relatedProducts = result.Data.filter(function (relatedItem) {
                    return relatedItem.ItemCode !== item.ItemCode;
                  });
                }
              });
            }
          };
    
          /**
          * @ngdoc method
          * @name getRelatedItem
          * @description Method called to get related products
          * @param {object} item
          * @param {string} type
          * @param {string} itemCode
          */
          $scope.getRelatedItem = function (item, type, itemCode) {
            $scope.getItems(type, item, itemCode);
          };
    
          function getQueryString(param) {
            var found;
            window.location.search.substr(1).split('&').forEach(function (item) {
                if (param == item.split('=')[0]) {
                    found = item.split('=')[1];
                }
            });
    
            return found;
        }
    
          $scope.RetailSession.CartType = $scope.itemType = $scope.RetailSession.CartType || getQueryString('cartType') || $location.search().cartType || 'order';
          $location.search('cartType', null);
          var itemCode;
          if ($stateParams.item) {
            localStorage.setItem('params.item', JSON.stringify($stateParams.item));
            localStorage.setItem('params.type', $scope.RetailSession.CartType);
            localStorage.setItem(
              'params.productList',
              JSON.stringify($stateParams.productList)
            );
            $scope.getItems($stateParams.type);
          } else { 
            var type = $scope.RetailSession.CartType;
            itemCode = $stateParams.id;
            $scope.getRelatedItem('', type, itemCode);
          }
          
          $scope.countinueSteps = function (type) {
            $state.go(
              type === 'order' ? 'Order' : type == 'packs' ? 'Packs' : 'Autoship',
              { WebAlias: $state.params.WebAlias }
            );
          };
          $scope.defaultImage = {
            Path: 'assets/img/images_coming_soon.png',
            Description: $scope.item ? $scope.item.Description : ''
          };
          /**
          * @ngdoc method
          * @name setDefaultValue
          * @description Method called to set default value
          * @param {object} item
          * @param {string} type
          */
          $scope.setDefaultValue = function (item, type) {
            // set up scope
            $scope.item = $stateParams.item
              ? transformItem($stateParams.item)
              : item;
            $scope.itemType = $scope.RetailSession.CartType || type;
            $scope.productList = $stateParams.productList
              ? _.indexBy($stateParams.productList, 'ItemCode')
              : _.indexBy($scope.product, 'ItemCode');
            $scope.defaultImage = {
              Path: 'assets/img/images_coming_soon.png',
              Description: $scope.item ? $scope.item.Description : ''
            };
            $scope.showItemChooser = $scope.item.HasKitGroups;
            $scope.itemQuantity = $scope.item.Quantity || 1;
            $scope.childItem = {};
            $scope.thumbcarouselImages = $filter('groupByCount')(
              $scope.item.Images,
              $scope.isMobile() ? 3 : 7
            );
    
            $scope.getOrderOptionKey = getOrderOptionKey;
            $scope.getValidValues = getValidValues;
    
            // Get the item code with any customizations
            $scope.getItemCode = getItemCode;
            setUpOrderOptions($scope.item);
            $scope.ezpModel = {
              small: $scope.item
                ? $scope.item.Images.length
                  ? $scope.item.Images[0].Path
                  : $scope.defaultImage.Path
                : $scope.defaultImage.Path,
              large: $scope.item
                ? $scope.item.Images.length
                  ? $scope.item.Images[0].Path
                  : $scope.defaultImage.Path
                : $scope.defaultImage.Path
            };
            $scope.getRelatedProducts($scope.item);
          };
          if ($stateParams.item) {
            $scope.setDefaultValue();
          }
          /**
          * @ngdoc method
          * @name addToCart
          * @description Method to Add item to appropriate cart (autoship / order)
          * @param {string} type
          */
          $scope.addToCart = function (type) {
            $scope.CurrentQuantity(type);
            //  cartsService.addToCart($scope.item, true, getItemCode($scope.item), $scope.itemType === 'autoship', true, $scope.itemType === 'packs');
    
            cartsService.addToCart(
              $scope.item,
              true,
              getItemCode($scope.item),
              type === 'autoship',
              true,
              type === 'packs'
            );
            $scope.item.Quantity = $rootScope.OrderQuantityCount;
            localStorage.setItem('params.item', JSON.stringify($scope.item));
          };
          /**
           * @ngdoc method
           * @name selectOption
           * @description Method to Select an option from a customization menu
           * @param {string} type
           */
          $scope.selectOption = function (item, option, value, isKitItem) {
            option.selected = value.Option;
            $scope.orderOptions[getOrderOptionKey(item, option)] = value.Option;
            var tempOptData = [];
            angular.forEach($scope.orderOptions, function(optdata) {
                tempOptData.push(optdata);
            }),
            angular.forEach(item.OptionsMap, function(itemOptdata) {
              if (JSON.stringify(tempOptData.sort()) === JSON.stringify(itemOptdata.OptionNames.sort())) {
                  var tempimgurl = item.SmallImageUrl;
                  itemOptdata.Image && (tempimgurl = item.SmallImageUrl.substr(0, item.SmallImageUrl.lastIndexOf('/')).concat(itemOptdata.Image));
                  var tempimage = {
                      Path: tempimgurl
                  };
                  $scope.setActiveImage(tempimage);
              }
          });
            if (isKitItem) {
              item.KitCustomItemCode = getItemCode(item);
            }
          };
          /**
          * @ngdoc method
          * @name checkOptions
          * @description Method to check Selected option
          * @param {object} option
          */
          $scope.checkOptions = function (option) {
            var count = 0;
            angular.forEach($scope.value, function (item) {
              if (item) {
                count++;
              }
            });
    
            $scope.isOptionsSelected = count == option.length;
          };
          /**
          * @ngdoc method
          * @name setInitialItemOption
          * @description Method sets options on ng-init
          * @param {object} option
          * @param {object} value
          */
          $scope.setInitialItemOption = function (option, value) {
            var defaultOption =
              $scope.orderOptions[getOrderOptionKey($scope.item, option)] ||
              option.Option;
            if (value.Option === defaultOption) {
              option.selected = value.Option;
            }
          };
          /**
          * @ngdoc method
          * @name getPrice
          * @description Show the price times the quantity selected
          * @param {object} item
          * @param {number} quantity
          */
          $scope.getPrice = function (item, quantity) {
            if (quantity < 1) {
              $rootScope.OrderQuantityCount = 1;
            }
            return item ? (item.Price || item.Prices[0].Price) * quantity : 0;
          };
    
    
          /**
           * Initialize
           */
          (function init() {
            $scope.loadingDetails = false;
            if ($scope.item) {
              var cartItem = itemInCart($scope.item);
              if (cartItem) {
                $scope.itemQuantity = cartItem.Quantity;
              }
              // orderOptions is a dictionary of ItemOptions.Option to ItemOptions.Values.Option, representing the selected option for each customization
              // Defaults to the first OptionsMap
              setUpOrderOptions($scope.item);
    
              // get kit item details
              if ($scope.item.HasKitGroups) {
                // set up request for kit item details
                var kitItemRequest =
                  '?' +
                  'cartId=' +
                  shoppingCartService.cartId +
                  '&storeId=0' +
                  '&customerType=' +
                  userService.customerTypeID;
                if (commonSetting.commonData.selectedCountry) {
                  kitItemRequest +=
                    '&countryCode=' + commonSetting.commonData.selectedCountry;
                }
                kitItemRequest += '&itemCodes=';
                // grab kit items that aren't already cached
                var itemsToGrab = {};
                _.each($scope.item.KitGroups, function (group) {
                  _.each(group.Items, function (kitItem) {
                    if (!$scope.productList[kitItem.Id]) {
                      itemsToGrab[kitItem.Id] = kitItem;
                      kitItemRequest += kitItem.Id + ',';
                    } else {
                      _.extend(
                        kitItem,
                        transformItem($scope.productList[kitItem.Id])
                      );
                    }
                  });
                });
    
                // Set up the kit item options in $scope.orderOptions
                $scope.item.KitGroups.forEach(function (kitGroup) {
                  kitGroup.Items.forEach(setUpOrderOptions);
                });
    
                // send request for kit item details that aren't cached
                if (Object.keys(itemsToGrab).length) {
                  kitItemRequest = kitItemRequest.slice(0, -1);
                  $RestService[itemTypes[$scope.itemType].getItemsCall](
                    kitItemRequest
                  ).then(
                    function (result) {
                      var kitItems = result.data.Data;
    
                      _.each(kitItems, function (kitItem) {
                        var item = transformItem(kitItem);
                        $scope.productList[kitItem.ItemCode] = item;
                        itemsToGrab[kitItem.ItemCode] = _.extend(
                          itemsToGrab[kitItem.ItemCode],
                          item
                        );
                      });
                      $scope.loadingDetails = false;
                    },
                    function () {
                      $scope.loadingDetails = false;
                    }
                  );
                } else {
                  $scope.loadingDetails = false;
                }
              } else {
                $scope.loadingDetails = false;
              }
            }
          })();
    
          /**
          * @ngdoc method
          * @name transformItem
          * @description Method to transform item
          * @param {object} item
          * @return {object}  transformed item
          */
          function transformItem(item) {
            $scope.isShowShareOptions = false;
            //item.ItemCode = Number(item.ItemCode);
            item.Price =
              item.Price || item.Price === 0
                ? item.Price
                : item.Prices && item.Prices[0] && item.Prices[0].Price;
    
            item.Images = item.Images || [];
            if (
              item.LargeImageUrl &&
              !_.find(item.Images, { Path: item.LargeImageUrl })
            ) {
              item.Images.unshift({
                Description: item.Description,
                Path: item.LargeImageUrl
              });
            } else if (item.Image && !_.find(item.Images, { Path: item.Image })) {
              item.Images.unshift({
                Description: item.Description,
                Path: item.Image
              });
            }
            metaDataService.setMetadata(
              item.ItemName, 
              item.ShortDescription ? item.ShortDescription.replace(/(<([^>]+)>)/ig, '').replace(/\n/g, '').replace(/"/g, '\'') : '',
              $location.absUrl().replace(/\+/g, '%2B').replace(/!/g, '%21'),
              item.LargeImageUrl ? item.LargeImageUrl.replace(/ /g, '%20') : '',
              item.CurrencySymbol,
              item.Price,
              '', '', '');
            window.prerenderReady = true;
            $scope.isShowShareOptions = true;
            return item;
          }
    
          /**
           * @ngdoc method
           * @name itemInCart
           * Returns item if it appears in the cart.
           * @param      {number}  itemCode  The item code
           * @return     {object}  Item object if it exists in the cart
           */
          function itemInCart(item) {
            var shoppingCart =
              $scope.RetailSession[itemTypes[$scope.itemType].cartItems];
            return _.findWhere(shoppingCart, {
              ItemCode: item.ItemCode
            });
          }
    
    
          // Set item quantity on the viewmodel
          $rootScope.OrderQuantityCount =
            $scope.item && $scope.item.Quantity ? $scope.item.Quantity : 1;
    
          /**
           * @ngdoc method
           * @name IncreaseQuantity
           * @description Method to Increase the quantity of an item
           */
          $scope.IncreaseQuantity = function () {
            if ($rootScope.OrderQuantityCount < 99) {
              $rootScope.OrderQuantityCount++;
            }
          };
          /**
           * @ngdoc method
           * @name DecreaseQuantity
           * @description Method to Decrease the quantity of an item
           */
          $scope.DecreaseQuantity = function () {
            if ($rootScope.OrderQuantityCount > 1) {
              $rootScope.OrderQuantityCount--;
            }
          };
          /**
           * @ngdoc method
           * @name DecreaseQuantity
           * @description Method to Set the quantity of an autoship item on the session
           */
          $scope.CurrentQuantity = function (type) {
            type = type || $scope.itemType;
            cartsService[itemTypes[type].itemQuantity] =
              cartsService[itemTypes[type].itemQuantity] || {}; //TODO::check if needed
            cartsService[itemTypes[type].itemQuantity][getItemCode($scope.item)] =
              $rootScope.OrderQuantityCount;
          };
          /**
           * @ngdoc method
           * @name DecreaseQuantity
           * @description Method to Set the quantity of an autoship item on the session
           */
          function setUpOrderOptions(item) {
            if (!$scope.orderOptions) {
              $scope.orderOptions = {};
            }
    
            var dict = $scope.orderOptions;
    
            // If editing an item with selected customizations, find them and set the dropdowns
            var optionsMap;
            if (item.selectedOptions) {
              item.OptionsMap.some(function (optMap) {
                if (optMap.ItemId === (item.KitCustomItemCode || item.ItemCode)) {
                  optionsMap = optMap.OptionNames;
                  return true;
                }
                return false;
              });
            }
    
            // Otherwise, default to the first options map
            var optionMapNames = item.OptionsMap
              ? item.OptionsMap.map(function (optMap) {
                return optMap.OptionNames;
              })
              : [];
    
            if (!item.selectedOptions || !optionsMap) {
              optionsMap = optionMapNames[0];
            }
    
            // Loop through the OptionsMap
            var optionVal;
            var optionValues;
            for (var index in optionsMap) {
              optionVal = optionsMap[index];
    
              // For each option in the OptionsMap, loop through the ItemOptions
              for (var itemIndex in item.ItemOptions) {
                // Get all the values of the ItemOption
                optionValues = item.ItemOptions[itemIndex].Values.map(
                  getOptionValueName
                );
    
                // If one of them is the value from the OptionsMap, use it
                var option = item.ItemOptions[itemIndex];
                if (
                  !!~optionValues.indexOf(optionVal) &&
                  !dict[getOrderOptionKey(item, option)]
                ) {
                  dict[getOrderOptionKey(item, option)] = optionVal;
                  break;
                }
              }
            }
    
            function getOptionValueName(val) {
              return val.Option;
            }
          }
    
          function getOrderOptionKey(item, option) {
            return item.ItemCode + '__' + option.Option;
          }
    
          // Determine what values are available based on what's already been selected
          function getValidValues(item, option, values) {
            // Get the already-selected option values (except this one and values from other items)
            var currentOption = getOrderOptionKey(item, option);
            var otherOptions = [];
    
            for (var key in $scope.orderOptions) {
              if (
                key === currentOption ||
                item.ItemCode.toString() !== key.split('__')[0]
              ) {
                continue;
              }
    
              otherOptions.push($scope.orderOptions[key]);
            }
    
            // Whittle down the OptionMaps to the ones that have all the already-selected options
            var optionMapNames = item.OptionsMap
              ? item.OptionsMap.map(function (optMap) {
                return optMap.OptionNames;
              })
              : [];
            var validOptionMaps = optionMapNames.filter(function (optNames) {
              // For each OptionMap, ensure that it contains all the other selected options
              var optionValue;
              for (var index in otherOptions) {
                optionValue = otherOptions[index];
                if (~optNames.indexOf(optionValue)) {
                  continue;
                }
                return false;
              }
              return true;
            });
    
            // Union the validOptionMaps
            var validOptionValues = validOptionMaps.reduce(function (arr, optMap) {
              var optionName;
              for (var index in optMap) {
                optionName = optMap[index];
                if (!~arr.indexOf(optionName)) {
                  arr.push(optionName);
                }
              }
              return arr;
            }, []);
    
            // Set `isAvailable: true` on each option that can be found in validOptionNames, and `isAvailable: false` on the others
            var optionValue;
            for (var index in values) {
              optionValue = values[index];
              optionValue.isAvailable = !!~validOptionValues.indexOf(
                optionValue.Option
              );
            }
    
            // return the original values
            return values;
          }
    
          // Get the current item code, whether it's a customizable item or not
          // SIDE EFFECTS: Create a list of selected options on the item ("item.selectedOptions")
          function getItemCode(item) {
            // If there are no customizations, just return the item code
            if (!item.ItemOptions || !item.ItemOptions.length) {
              return $scope.item.ItemCode;
            }
    
            // If there are customizations, find the right OptionsMap and use its code
            var optionValues = [];
            for (var key in $scope.orderOptions) {
              if (
                !$scope.orderOptions.hasOwnProperty(key) ||
                item.ItemCode.toString() !== key.split('__')[0]
              ) {
                continue;
              }
    
              optionValues.push($scope.orderOptions[key]);
            }
    
            optionValues.sort();
    
            item.selectedOptions = getOptionsText(optionValues);
    
            if (item.HasKitOptions) {
              item.KitGroups.forEach(function (kitGroup) {
                kitGroup.Items.forEach(getItemCode);
              });
            }
    
            var mapping;
            for (var index in item.OptionsMap) {
              mapping = item.OptionsMap[index];
              mapping.OptionNames.sort();
              if (angular.equals(optionValues, mapping.OptionNames)) {
                return mapping.ItemId;
              }
            }
    
            throw 'Error: ' +
            item.ItemName +
            ' does not have a mapping for ' +
            optionValues.toString() +
            '.';
          }
    
          // Get text to display in the cart when customizations are chosen, e.g. '[Medium, Red]'
          function getOptionsText(optionValArray) {
            return '[' + optionValArray.join(', ') + ']';
          }
    
          $scope.displayItemChooser = function () {
            $scope.showItemChooser = true;
          };
    
          $scope.ezpModel = {
            small: $scope.item
              ? $scope.item.Images.length
                ? $scope.item.Images[0].Path
                : $scope.defaultImage.Path
              : $scope.defaultImage.Path,
            large: $scope.item
              ? $scope.item.Images.length
                ? $scope.item.Images[0].Path
                : $scope.defaultImage.Path
              : $scope.defaultImage.Path
          };
          $scope.isShowZoom = $mdMedia('max-width: 1049px');
    
          // change active image
          $scope.setActiveImage = function (image) {
            $scope.ezpModel = {
              small: image.Path || $scope.defaultImage.Path,
              large: image.Path || $scope.defaultImage.Path
            };
            $timeout(function () {
              $scope.activeImage = image;
            }, 1);
          };
          $scope.setActiveChildImage = function (image) {
            $scope.activeChildImage = image;
          };
          GetSettingsService.GetSetting('ProductDetails')
            .then(function (result) {
              $scope.isShow = [];
              if (result) {
                if (result.length > 0) {
                  _.each(result, function (data) {
                    $scope.isShow[data.SettingName] =
                      data.Value == '1' ? true : false;
                  });
                }
              }
            });
            
          $RestService.GetInstagramFeed('').then(function (result) {
            result = result.data;
            if (result && result.Data) {
              if (result.Data.data && result.Data.data.length) {
                var width = $('.nav_tabs').width();
                $scope.instaFeeds = $filter('groupByCount')(
                  result.Data.data,
                  Math.floor(width / 240)
                );
                angular.element($window).bind(
                  'resize',
                  _.throttle(function () {
                    var width = $('.nav_tabs').width();
                    $scope.instaFeeds = $filter('groupByCount')(
                      result.Data.data,
                      Math.floor(width / 240)
                    );
                    // manuall $digest required as resize event is outside of angular
                    if ($scope.$$phase) {
                      $scope.$apply();
                    }
                  }, 250)
                );
              }
            }
          });
    
          $scope.setRelatedProduct = function (relateditem, type, param, type2) {
            var item = _.filter(itemsService['orders'], function (item) {
              return item.ItemCode === relateditem.ItemCode;
            })[0];
            cartsService.showProductDetail(item, type, param, type2);
          };
    
          // customPageService.getSetting().then(function () {
          //   if (customPageService.setting['productdetails']) {
          //     companyDetails.customContentdefer.promise.then(function () {
          //       customPageService.getCustomPages('custom-product-details');
          //     });
          //   }
          // });
    
          $scope.$on('$destroy', function () {
            // Set item quantity on the viewmodel
            $rootScope.OrderQuantityCount = 1;
            cartsService.orderQuantity = {};
            cartsService.autoshipQuantity = {};
    
          });      
          $scope.ParentItemID =55;
          $scope.GetSubItems = function () {
             alert('Testing');
            var request1 = {
                  'ParentItemId': $scope.ParentItemID
              };
              $RestService.V3Post('/Proxy/senuvoservices/getsubItems', request1, '', true).then(function(result){
                  result = result.data;
                  try {
                      alert(result.Response);
                  }
                  catch (ex){
                      alsert(JSON.stringify(result));
                  }
              })
          }
          
        }
      ]);
    })();
    
 
 

Comments

3 comments
  • Akshay Bohra and/or Product Team - can we get help with this request?

    CC: Joseph Draschil

    0
  • Joseph, I created a ticket through our Zendesk Support and commented on that to you with the response from the developer. 

    0
  • Is there a public facing answer to this? I'm having troubles getting this to work as well.

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post