OCS_BFServiceLoader.min.js 5.6 KB

1
  1. define(["jquery","knockout","pubsub","ccConstants","koValidate","navigation","notifier","CCi18n","storeKoExtensions","swmRestClient","spinner","pageLayout/product","ccRestClient","ccResourceLoader!global/OCS_BFService","viewModels/guidedNavigationViewModel","pageLayout/search"],function(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v){"use strict";var m;return{onLoadExecution:!1,collectionTree:p.collectionTree,onLoad:function(t){m=t,m.onLoadExecution=!0,p.site=m.site,p.loadCollectionTree(m.user(),m.load),e.Topic(n.topicNames.PAGE_CHANGED).subscribe(m.executeWhenPageChange),m.overloadViewmodelsPrototypes(),p.initSWMRestClient(t.site().tenantId,t.isPreview(),t.locale());var i="cloudCatalog",s="rootCategory";t.load("categoryList",[s,i,r.CATALOG_MAX_LEVEL],function(t){var n=function(t){e.each(t,function(t,r){r.childCategories!==undefined&&(e.each(r.childCategories,function(e,t){var n=Object.assign({},r);delete n.childCategories,t.parent=n}),n(r.childCategories))})};n(t),p.ALL_COLLECTIONS({id:"ROOT",childCategories:t})},t)},beforeAppear:function(t){var n=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);n&&setTimeout(function(){e("#page").css("display","block"),e("#page").css("display","table"),e("#page").css("display","block"),setTimeout(function(){e("#page").css("display","table")},100)},500),m.onLoadExecution&&(m.onLoadExecution=!1)},executeWhenPageChange:function(e){m.putBrandClassInDom(e),m.copyWidgetAttributesToGlobal(),m.clearAppliedFilters(e)},putBrandClassInDom:function(t){var n,i=t.pageId;console.log("CBF pageType: ",i);var s=function(){var t=[];e("#page").hasClass("container")&&t.push("container"),e("#page").hasClass("background-dark")&&t.push("background-dark"),e("#page").hasClass("layout-checkout")&&t.push("layout-checkout"),e("#page").removeClassesExceptThese(t)},o=function(t){s(),e("#page").addClass(t)},u=p.CLASE_BF_CORP;if(i===r.CATEGORY_CONTEXT&&m.category())n=p.isFirstLevelCategory(m.category()),n?(u=m.categoryId(),o(u)):(u=p.getFirstLevelCategoryId(m.category()),o(u));else if(i===r.INVENTORY_PRODUCT_TYPE&&m.product()&&m.product().type&&m.product().type()===p.PRODUCT_TYPES.NAMES.automovilNuevo){var a=function(e){e&&(u=e),o(u)};p.getBrandFromProduct(m.product(),a)}else i===r.INVENTORY_PRODUCT_TYPE&&m.product()&&m.product().type&&m.product().type()===p.PRODUCT_TYPES.NAMES.automovilUsado?o(p.USADOS.collectionId):i==="searchresults"?o(p.USADOS.collectionId):o(u)},copyWidgetAttributesToGlobal:function(){p.site=m.site,p.user=m.user,p.pageContext=m.pageContext,p.product=undefined,p.product=m.product,p.dimensionId=undefined,p.dimensionId=m.dimensionId,p.categoryId=undefined,p.categoryId=m.categoryId,p.category=undefined,p.category=m.category},clearAppliedFilters:function(e){m.actualIsSearchLayout()&&(p.rangeFiltersApplied({}),m.actualIsSearchLayout(!1)),e.pageId==="searchresults"&&m.actualIsSearchLayout(!0)},actualIsSearchLayout:t.observable(!1),loadGTMScript:function(){var t=m.site().extensionSiteSettings.OCS_siteSetting_GoogleTagManager.googleTagManager_header_js,n=m.site().extensionSiteSettings.OCS_siteSetting_GoogleTagManager.googleTagManager_body_js;e("body").prepend(n),e("head").prepend(t)},overloadViewmodelsPrototypes:function(){m.cart().removeCurrentProfileOrder_OCS=function(){var t=this;if(t.user().isPunchout()==1){var n={},i={};i[r.ENDPOINT_KEY]=r.ENDPOINT_REMOVE_PROFILE_INCOMPLETE_ORDER_BY_ID,i[r.IDENTIFIER_KEY]="removeProfileIncompleteOrderById";var s=t.storeConfiguration.getFilterToUse(i);s&&(n[r.FILTER_KEY]=s),h.request(r.ENDPOINT_REMOVE_PROFILE_INCOMPLETE_ORDER_BY_ID,n,function(e){t.user().orderId(""),t.user().persistedOrder(null),t.user().setLocalData("orderId"),t.cartName("")},function(e){t.loadCart()},t.user().orderId())}else t.adapter.persistRemove("order",t.user().orderId(),null,function(n){t.user().orderId(""),t.user().persistedOrder(null),t.user().setLocalData("orderId"),t.cartName(""),e.Topic("OCS_CART_EMPTY_SUCCESS").publish()},function(e){t.loadCart()})},m.user().loginSuccessFunc=function(t){var r=this;r.loggedIn(r.client().loggedIn),r.isUserSessionExpired(!1),r.isLoginFailed(!1),r.isSesExpDuringPlaceOrder(!1),r.isUserLoggedOut(!1),r.password(""),r.password.isModified(!1),o.clearError(r.WIDGET_ID),r.id(r.client().profileId),!s.isPathEqualTo(r.myAccountHash)&&r.pageToRedirect()==r.myAccountHash&&(r.sessionExpiredProfileRedirected=!0);if(r.pageToRedirect()&&r.pageToRedirect()!=""&&r.pageToRedirect()!=r.checkoutHash){var i=r.pageToRedirect();r.pageToRedirect(null);if(s.isPathEqualTo(i)){var u=r.getLocalData();null!=u&&u.login==r.login()&&s.isPathEqualTo(r.myAccountHash)&&!r.isPasswordExpired()&&r.isSessionExpiredDuringSave()||(r.getCurrentUser(t,!0),s.isPathEqualTo(r.myAccountHash)&&(r.isSessionExpiredDuringSave(!1),e.Topic(n.topicNames.USER_PROFILE_SESSION_RESET).publish()))}r.isPageRedirected(!0),s.goTo(i)}else r.getCurrentUser(t,!0),null==r.onLoadCartSubscribe&&(r.onLoadCartSubscribe=e.Topic(n.topicNames.CART_LOADED_FOR_PROFILE).subscribe(function(){if(!r.registeringUser||!r.loggedinAtCheckout()){r.registeringUser=!1;var i=s.getPathWithoutLocale().split("?"),o={pageId:s.getPath(),parameters:i[1],onLogin:!0};r.pageAppeared=e.Deferred(),e.when(e.Topic(n.topicNames.PAGE_VIEW_CHANGED).publish(o)).done(function(){t&&(r.storeConfiguration.enablePrioritizedLoading?e.when(r.pageAppeared).done(function(){r.autoLoginComplete.resolve(),r.pageAppeared=e.Deferred()}):r.autoLoginComplete.resolve())})}}));r.isPasswordExpired(!1)};var t=v.getInstance();d.prototype.createSpinnerAndHandleRedirect=function(e){var n=this;d.prototype.createSpinner(),s.goTo(n.searchResultsHash+t.getFilteredNavState(e)+"&"+r.SEARCH_TYPE+"="+r.SEARCH_TYPE_GUIDED+"&"+r.PARAMETERS_TYPE+"="+r.PARAMETERS_SEARCH_QUERY+"&"+r.SEARCH_SORT_ORDER+"="+"sku.activePrice|1")}}}})