1'use strict'; // 2 3// **************************************************** 4// Gestion des Produits 5// **************************************************** 6angular.module('AboShopApp').factory('productsManager', ['$q','TbsWS','commonConfig','$rootScope','formulaireManager', 'dataManager', 'categoriesManager', '$state', 'googleTagManager','$timeout',function ($q, TbsWS, commonConfig, $rootScope, formulaireManager, dataManager, categoriesManager, $state, googleTagManager, $timeout) { 7 8 var factory = {}; 9 10 factory.PARAMETER_COUNTRY = "choixTerritoire"; 11 factory.PARAMETER_ZONE = "choixZone"; 12 factory.PARAMETER_TERMS = "choixDureeAbonnement"; 13 factory.PARAMETER_SUPPORT = "choixRefSupport"; 14 factory.PARAMETER_AMOUNT = "choixDuMontant"; 15 factory.PARAMETER_QUANTITY = "choixQuantite"; 16 17 18 function _initProduct(product) { 19 if (!product) { 20 product = {}; 21 product.titre = {}; 22 product.tarif = {}; 23 } else { 24 product.imageGrandFormat = product.imageGrandFormat + '?v=' + commonConfig.forceversion; 25 product.imagePetitFormat = product.imagePetitFormat + '?v=' + commonConfig.forceversion; 26 for (var i = 0; i < product.images.length; i++) { 27 product.images[i] = product.images[i] + '?v=' + commonConfig.forceversion; 28 } 29 } 30 31 if (product.tarif !== undefined && product.tarif.media !== undefined && product.tarif.media !== null && product.tarif.support === undefined) { 32 factory.PARAMETER_SUPPORT = "choixRefMedia"; 33 product.tarif.support = {}; 34 product.tarif.support.libelleSupport = product.tarif.media.libelleMedia; 35 product.tarif.support.typeSupport = product.tarif.media.typeMedia; 36 } 37 38 if (product.medias !== undefined && product.medias !== null && product.supports === undefined) { 39 product.supports = []; 40 var support = {}, media = {}, i = 0; 41 for (i = 0; i < product.medias.length; i++) { 42 media = product.medias[i]; 43 support = {}; 44 support.libelleSupport = media.libelleMedia; 45 support.typeSupport = media.typeMedia; 46 product.supports.push(support); 47 } 48 } 49 if ($state.current.data.seoMap === undefined) { 50 $state.current.data.seoMap = []; 51 } 52 if (product.seo !== undefined && product.seo !== null && 53 (product.seo.urlRewrite === undefined || product.seo.urlRewrite === null || product.seo.urlRewrite === "")) { 54 let ob = factory.getHrefProduct(product, null); 55 product.seo.urlRewrite = ob.url; 56 } 57 if (product.seo !== undefined && product.seo !== null && product.seo.urlRewrite !== undefined 58 && product.seo.urlRewrite !== null && product.seo.urlRewrite !== "") { 59 if (product.seo.urlRewrite.startsWith('/') === false) { 60 product.seo.urlRewrite = '/' + product.seo.urlRewrite; 61 } 62 } 63 $state.current.data.seoMap.push(product.seo); 64 65 product.addToCartInProgress=false; 66 if(product.devis !== undefined && product.devis){ 67 product.dicoShopNow='DICO_SHOP_DEVIS'; 68 } else { 69 product.dicoShopNow='DICO_SHOP_NOW'; 70 } 71 return product; 72 }; 73 74 factory.getHrefProduct = function getHrefProduct( product, refAboEchu ) { 75 let ob = TbsWS.getUrlHome(); 76 if(product!== undefined && product.refProduit !== undefined){ 77 if(product.estUnAbonnement || product.estUneFormule) { 78 ob.url = null; 79 if(refAboEchu != null) { 80 if(product.produitsReabonnements != null) { 81 if(product.produitsReabonnements.length == 1) { 82 if(product.produitsReabonnements[0].refProduit != null){ 83 ob.url = '/common/product-subscription/'+product.produitsReabonnements[0].refProduit+'/'+refAboEchu; 84 } 85 } else if (product.produitsReabonnements.length > 1) { 86 ob.url = '/common/product-list-subscription/'+refAboEchu; 87 } 88 } else { 89 ob.url = '/common/product-subscription/'+product.refProduit+'/'+refAboEchu; 90 } 91 } 92 93 if (ob.url == null) { 94 ob.url = '/common/product-subscription/'+product.refProduit; 95 } 96 } else if(product.estUnDon){ 97 ob.url = '/common/product-donation/'+product.refProduit; 98 } else { 99 ob.url = '/common/product-article/'+product.refProduit; 100 } 101 } 102 return ob; 103 }; 104 105 factory.initConstant = function initConstant(scope){ 106 scope.PARAMETER_COUNTRY = factory.PARAMETER_COUNTRY; 107 scope.PARAMETER_ZONE = factory.PARAMETER_ZONE; 108 scope.PARAMETER_TERMS = factory.PARAMETER_TERMS; 109 scope.PARAMETER_SUPPORT = factory.PARAMETER_SUPPORT; 110 scope.PARAMETER_AMOUNT = factory.PARAMETER_AMOUNT; 111 scope.PARAMETER_QUANTITY = factory.PARAMETER_QUANTITY; 112 }; 113 114 factory.getSearchForm = function getSearchForm(){ 115 var deferred = $q.defer(); 116 117 $timeout(function() { 118 var searchForm = {}; 119 120 searchForm.alert = {}; 121 searchForm.alert.message = []; 122 searchForm.fields = []; 123 124 var ob; 125 ob = {}; 126 formulaireManager.createTextField("searchstr",ob,"","DICO_PRODUCT_TERME_RECHERCHE",true); 127 searchForm.fields.push(ob); 128 129 deferred.resolve(searchForm); 130 },10); 131 132 /*_getFiltersOfSearch().then( 133 function(filters){ 134 var searchForm = {}; 135 136 searchForm.alert = {}; 137 searchForm.alert.message = []; 138 searchForm.fields = []; 139 140 var ob; 141 ob = {}; 142 formulaireManager.createTextField("searchstr",ob,"","DICO_PRODUCT_TERME_RECHERCHE",true); 143 searchForm.fields.push(ob); 144 145 ob = {}; 146 147 var refactoFilter=[]; 148 if(filters !== undefined){ 149 for(let p in filters){ 150 ob = {};
151 ob.key=filters[p].key; 152 ob.value=filters[p].value; 153 refactoFilter.push(ob); 154 } 155 } 156 refactoFilter.unshift({key:"nofilter",value:"DICO_NO_FILTER"}); 157 158 ob = {}; 159 formulaireManager.createSelect("filter",ob,"DICO_PRODUCT_FILTRE",refactoFilter,false); 160 ob.translated = true; 161 searchForm.fields.push(ob); 162 163 deferred.resolve(searchForm); 164 } 165 ,function(error) { 166 deferred.reject(error); 167 });*/ 168 return deferred.promise; 169 }; 170 171 function _getFiltersOfSearch(){ 172 var deferred = $q.defer(); 173 categoriesManager.getCategoriesKeyValue().then( 174 function(filters){ 175 deferred.resolve(filters); 176 } 177 ,function(error) { 178 deferred.reject(error); 179 } 180 ); 181 return deferred.promise; 182 183 } 184 185 factory.verifSearchForm = function verifSearchForm(searchForm){ 186 if(!formulaireManager.verifForm(searchForm)){ 187 return false; 188 } 189 return true; 190 }; 191 192 factory.searchProducts = function searchProducts(searchvalue, searchfilter, offset){ 193 var deferred = $q.defer(); 194 195 if( searchvalue && searchfilter && searchvalue != "" && searchfilter != "" && searchvalue !== undefined && searchfilter !== undefined ){ 196 TbsWS.call('searchproduct/' + $rootScope.preferredLanguage+ '/' + searchvalue + '/' + searchfilter +'/'+offset,'public').then( 197 function(products){ 198 googleTagManager.viewItemListEvent(products, 'searchProducts'); 199 deferred.resolve(products); 200 } 201 ,function(error) { 202 deferred.reject(error); 203 } 204 ); 205 } else { 206 deferred.reject(false); 207 } 208 209 return deferred.promise; 210 }; 211 212 factory.countSearchProducts = function countSearchProducts(searchvalue, searchfilter){ 213 var deferred = $q.defer(); 214 215 if( searchvalue && searchfilter && searchvalue != "" && searchfilter != "" && searchvalue !== undefined && searchfilter !== undefined ){ 216 TbsWS.call('countsearchproducts/' + $rootScope.preferredLanguage+ '/' + searchvalue + '/' + searchfilter,'public').then( 217 function(result){ 218 if(result && result.key === "countsearchproducts"){ 219 deferred.resolve(result.value); 220 } else { 221 deferred.resolve(0); 222 } 223 } 224 ,function(error) { 225 deferred.resolve(0); 226 } 227 ); 228 } else { 229 deferred.resolve(0); 230 } 231 232 return deferred.promise; 233 }; 234 235 factory.getCategoriesFilter = function getCategoriesFilter(products){ 236 var i = 0, 237 j = 0, 238 product, 239 cs, 240 ob, 241 categories = []; 242 if(products !== undefined){ 243 for(i = 0; i < products.length; i++){ 244 product = products[i]; 245 if(product.codeSelection !== null && product.codeSelection !== undefined && product.codeSelection[commonConfig.codecategories] !== undefined){ 246 cs = product.codeSelection[commonConfig.codecategories]; 247 product.strclasses = ""; 248 for(j = 0;j < cs.length; j++){ 249 ob = {}; 250 ob.filter = '.'+cs[j].key; 251 product.strclasses += ' '+cs[j].key; 252 ob.value = cs[j].value; 253 categories.push(ob); 254 255 } 256 257 } 258 } 259 categories = _.uniq(categories, 'filter'); 260 } 261 262 ob = {}; 263 ob.filter = '*'; 264 ob.value = 'DICO_ALL'; 265 categories.unshift(ob); 266 return categories; 267 }; 268 269 factory.nbProducts = function nbProducts(idCategory){ 270 var deferred = $q.defer(); 271 TbsWS.call('nbproducts','public').then( 272 function(result){ 273 if(result && result.key === "nbproducts"){ 274 deferred.resolve(result.value); 275 } else { 276 deferred.resolve(0); 277 } 278 } 279 ,function(error) { 280 deferred.resolve(0); 281 } 282 ); 283 284 return deferred.promise; 285 }; 286 287 factory.nbProductsByCategories = function nbProductsByCategories(idCategory,filter){ 288 var deferred = $q.defer(); 289 if(filter.year !== "all"){ 290 TbsWS.call('nbproductsbycategoriesfilterbydate/' + $rootScope.preferredLanguage+'/' + idCategory+'/' + filter.year +'/' + filter.month, 'public').then( 291 function(result){ 292 if(result && result.key === "nbproductsbycategories"){ 293 deferred.resolve(result.value); 294 } else { 295 deferred.resolve(0); 296 } 297 } 298 ,function(error) { 299 deferred.resolve(0); 300 } 301 ); 302 303 } else { 304 TbsWS.call('nbproductsbycategories/' + $rootScope.preferredLanguage+'/' + idCategory,'public').then( 305 function(result){ 306 if(result && result.key === "nbproductsbycategories"){ 307 deferred.resolve(result.value); 308 } else { 309 deferred.resolve(0); 310 } 311 } 312 ,function(error) { 313 deferred.resolve(0); 314 } 315 ); 316 } 317 318 return deferred.promise; 319 }; 320 321 factory.productsByCategories = function productsByCategories(category, offset,filter){ 322 var deferred = $q.defer(); 323 if(filter.year !== "all"){ 324 TbsWS.call('productsbycategoriesfilterbydate/' + $rootScope.preferredLanguage+'/' + category.refCategorie + '/' + offset+'/' + filter.year +'/' + filter.month ,'public').then( 325 function(products){ 326 googleTagManager.viewItemListEvent(products, category.nom, category.refCategorie); 327 deferred.resolve(_processProducts(products)); 328 } 329 ,function(error) { 330 deferred.reject([]); 331 } 332 ); 333 } else { 334 TbsWS.call('productsbycategories/' + $rootScope.preferredLanguage+'/' + category.refCategorie + '/' + offset,'public').then( 335 function(products){ 336 googleTagManager.viewItemListEvent(products, category.nom, category.refCategorie); 337 deferred.resolve(_processProducts(products)); 338 } 339 ,function(error) { 340 deferred.reject([]); 341 } 342 ); 343 } 344 345 return deferred.promise; 346 }; 347 348 349 factory.getRelatedProducts = function getRelatedProducts(product,max){ 350 var deferred = $q.defer(); 351 if(max === undefined){ 352 max = 2; 353 } 354 if(product != null && product !== undefined && product.refProduit !== undefined){ 355 TbsWS.call('relatedproducts/' + $rootScope.preferredLanguage+'/'+product.refProduit,'public').then( 356 function(products){ 357 if (commonConfig.googleTagManagerGA4) { 358 setTimeout(function () { 359 googleTagManager.viewItemListEvent(products.slice(0,max), 'relatedProducts'); 360 }, 5000); 361 } else { 362 googleTagManager.viewItemListEvent(products.slice(0,max), 'relatedProducts'); 363 }
364 deferred.resolve(_processProducts(products.slice(0,max))); 365 } 366 ,function(error) { 367 deferred.reject([]); 368 } 369 ); 370 } else { 371 deferred.reject([]); 372 } 373 return deferred.promise; 374 }; 375 376 377 function _processProducts(products) { 378 if (products !== undefined) { 379 for (var i = 0; i < products.length; i++) { 380 products[i].imageGrandFormat = products[i].imageGrandFormat + '?v=' + commonConfig.forceversion; 381 products[i].imagePetitFormat = products[i].imagePetitFormat + '?v=' + commonConfig.forceversion; 382 for (var j = 0; j < products[i].images.length; j++) { 383 products[i].images[j] = products[i].images[j] + '?v=' + commonConfig.forceversion; 384 } 385 } 386 } 387 return products; 388 } 389 390 factory.getProductsOfMonth = function getProductsOfMonth(){ 391 var deferred = $q.defer(); 392 TbsWS.call('productsofmonth/' + $rootScope.preferredLanguage,'public').then( 393 function(products){ 394 googleTagManager.viewItemListEvent(products, 'productsOfMonth'); 395 deferred.resolve(_processProducts(products)); 396 } 397 ,function(error) { 398 deferred.reject([]); 399 } 400 ); 401 return deferred.promise; 402 }; 403 404 factory.getProductsInSubscription = function getProductsInSubscription(){ 405 var deferred = $q.defer(); 406 TbsWS.call('productsinsubscriptions/' + $rootScope.preferredLanguage,'public').then( 407 function(products){ 408 googleTagManager.viewItemListEvent(products); 409 deferred.resolve(products); 410 } 411 ,function(error) { 412 console.error(error); 413 deferred.reject([]); 414 } 415 ); 416 return deferred.promise; 417 }; 418 419 factory.getProductsInFooter = function getProductsInFooter(){ 420 var deferred = $q.defer(); 421 TbsWS.call('productsinfooter/' + $rootScope.preferredLanguage,'public').then( 422 function(products){ 423 if (commonConfig.googleTagManagerGA4) { 424 setTimeout(function () { 425 googleTagManager.viewItemListEvent(products, 'productsInFooter'); 426 }, 5000); 427 } else { 428 googleTagManager.viewItemListEvent(products, 'productsInFooter'); 429 } 430 deferred.resolve(_processProducts(products)); 431 } 432 ,function(error) { 433 console.error(error); 434 deferred.reject([]); 435 } 436 ); 437 return deferred.promise; 438 }; 439 440 factory.getProductsCarousel = function getProductsCarousel(){ 441 var deferred = $q.defer(); 442 TbsWS.call('lastproducts/'+ $rootScope.preferredLanguage,'public').then( 443 function(products){ 444 googleTagManager.viewItemListEvent(products, 'productsInCarousel'); 445 deferred.resolve(_processProducts(products)); 446 } 447 ,function(error) { 448 deferred.reject(error); 449 } 450 ); 451 return deferred.promise; 452 }; 453 454 factory.getProducts = function getProducts(offset){ 455 var deferred = $q.defer(); 456 if(offset === undefined){ 457 offset = 0; 458 } 459 TbsWS.call('products/'+ $rootScope.preferredLanguage +'/'+ offset,'public').then( 460 function(products){ 461 googleTagManager.viewItemListEvent(products); 462 deferred.resolve(_processProducts(products)); 463 } 464 ,function(error) { 465 console.error(error); 466 } 467 ); 468 return deferred.promise; 469 }; 470 471 factory.loadProductsFormule = function loadProductsFormule(idProduct){ 472 var deferred = $q.defer(); 473 474 TbsWS.call('getproductsbytypeformule/'+ $rootScope.preferredLanguage+'/'+idProduct,'public').then( 475 function(products){ 476 deferred.resolve(_processProducts(products)); 477 } 478 ,function(error) { 479 deferred.reject(error); 480 } 481 ); 482 return deferred.promise; 483 }; 484 485 factory.loadProductsFromIds = function loadProductsFromIds(products){ 486 var deferred = $q.defer(),params={}; 487 params.array = products; 488 TbsWS.call('getproductsfromlist/'+ $rootScope.preferredLanguage,'public',params).then( 489 function(products){ 490 deferred.resolve(_processProducts(products)); 491 } 492 ,function(error) { 493 deferred.reject(error); 494 } 495 ); 496 return deferred.promise; 497 }; 498 499 factory.getCriteras = function getCriteras(product, territoires, zones){ 500 var criteres = {}, 501 ob, 502 def, 503 territoiresObj, 504 zonesObj; 505 506 if(product !== undefined && product.tarif !== undefined){ 507 if(product.zonesLivraison != null){ 508 if(territoires && territoires !== undefined && product.zonesLivraison.length > 0 && territoires.length > 0){ 509 territoiresObj = _.pluck(territoires, 'value'); 510 //Par defaut le territoire selectionne est le dernier selectionne 511 if(product.codeTerritoireSelect){ 512 criteres[factory.PARAMETER_COUNTRY] = _.findWhere(territoiresObj, {codeTerritoire: product.codeTerritoireSelect}); 513 } 514 515 if(criteres[factory.PARAMETER_COUNTRY] === undefined){ 516 //Sinon on prend celui selectionne par defaut par le webservices des territoires 517 // Soit FRANCE METROPOLE (ou territoire par defaut) 518 // Soit le Territoire du client 519 criteres[factory.PARAMETER_COUNTRY] = _.findWhere(territoiresObj, {estDefaut: true}); 520 if(criteres[factory.PARAMETER_COUNTRY] === undefined){ 521 //Sinon on prend le premier territoire qui correspond a la zone de livraison du tarif du produit 522 criteres[factory.PARAMETER_COUNTRY] = _.find(territoiresObj, function (x) { return x.zoneLivraison == product.tarif.zoneLivraison.codeZonePort; }); 523 } 524 product.codeTerritoireSelect = criteres[factory.PARAMETER_COUNTRY].codeTerritoire; 525 } 526 } else if(zones && zones !== undefined && product.zonesLivraison.length > 0 && zones.length > 0){ 527 zonesObj = _.pluck(zones, 'value'); 528 //Par defaut le territoire selectionne est le dernier selectionne 529 if(product.zoneSelect){ 530 criteres[factory.PARAMETER_ZONE] = _.findWhere(zonesObj, {codeZonePort: product.zoneSelect}); 531 } 532 533 if(criteres[factory.PARAMETER_ZONE] === undefined){ 534 //Sinon on prend celui selectionne par defaut par le webservices des zone
534s 535 // Soit FRANCE METROPOLE 536 // Soit la Zone du client 537 criteres[factory.PARAMETER_ZONE] = _.findWhere(zonesObj, {estDefaut: true}); 538 if(criteres[factory.PARAMETER_ZONE] === undefined){ 539 //Sinon on prend la premiere zone 540 criteres[factory.PARAMETER_ZONE] = zonesObj[0]; 541 } 542 product.zoneSelect = criteres[factory.PARAMETER_ZONE].codeZonePort; 543 } 544 } 545 } 546 if(product.tarif.codeDureeAbonnement != null && product.tarif.codeDureeAbonnement !== undefined){ 547 criteres[factory.PARAMETER_TERMS] = product.tarif.codeDureeAbonnement.key; 548 } 549 if(product.tarif.support != null && product.tarif.support !== undefined){ 550 criteres[factory.PARAMETER_SUPPORT] = product.tarif.support.typeSupport; 551 } 552 criteres[factory.PARAMETER_QUANTITY] = product.quantiteSelect; 553 } 554 return criteres; 555 }; 556 557 factory.loadProduct = function loadProduct(fakeProduct,criteres){ 558 559 var deferred = $q.defer(); 560 if(!fakeProduct || !fakeProduct.refProduit || fakeProduct.refProduit === undefined){ 561 deferred.reject("Product not conform :"+JSON.stringify(fakeProduct)); 562 } else { 563 var baseUrl = 'product/', 564 params = $rootScope.preferredLanguage +'/' +fakeProduct.refProduit, 565 url; 566 567 568 if(criteres !== undefined && fakeProduct.typeParameter !== undefined && fakeProduct.valueParameter !== undefined){ 569 if(fakeProduct.typeParameter == factory.PARAMETER_COUNTRY || fakeProduct.typeParameter == factory.PARAMETER_ZONE){ 570 baseUrl = 'updatezonedelivery/'; 571 if(fakeProduct.typeParameter == factory.PARAMETER_COUNTRY){ 572 criteres[factory.PARAMETER_COUNTRY] = fakeProduct.valueParameter; 573 } else if(fakeProduct.typeParameter == factory.PARAMETER_ZONE){ 574 criteres[factory.PARAMETER_ZONE] = fakeProduct.valueParameter; 575 } 576 } else if(fakeProduct.typeParameter == factory.PARAMETER_TERMS){ 577 baseUrl = 'updateduration/'; 578 criteres[factory.PARAMETER_TERMS] = fakeProduct.valueParameter; 579 } else if(fakeProduct.typeParameter == factory.PARAMETER_SUPPORT){ 580 baseUrl = 'updatesupport/'; 581 criteres[factory.PARAMETER_SUPPORT] = fakeProduct.valueParameter; 582 } else if(fakeProduct.typeParameter == factory.PARAMETER_QUANTITY){ 583 baseUrl = 'updatequantity/'; 584 criteres[factory.PARAMETER_QUANTITY] = fakeProduct.valueParameter; 585 } 586 } 587 588 /*if(fakeProduct.codeClientLiv !== undefined){ 589 params += '/' +fakeProduct.codeClientLiv; 590 }*/ 591 592 url = baseUrl+params; 593 594 TbsWS.call(url,'public',criteres).then( 595 function(product){ 596 product = product || {}; 597 if(product.refProduit) { 598 googleTagManager.viewItemEvent(product); 599 deferred.resolve(_initProduct(product)); 600 } else { 601 $rootScope.goPage(undefined,'/message/404'); 602 deferred.reject({}); 603 } 604 } 605 ,function(error) { 606 deferred.reject(error); 607 } 608 ); 609 } 610 return deferred.promise; 611 }; 612 613 factory.getSubscriptionForm = function getSubscriptionForm(product, territoires, zones){ 614 var subscriptionForm={}, 615 subscription, 616 ob, 617 diff, 618 terms = [], 619 supports = [], 620 territoiresObj=[], 621 zonesObj=[], 622 index=0, 623 titre, 624 i, 625 hasmultizone=false; 626 subscriptionForm.others = {}; 627 subscriptionForm.fields = []; 628 subscriptionForm.displaycombinaison = true; 629 subscriptionForm.displayzone=true; 630 subscriptionForm.displayQuantity =true; 631 632 if(product.tarif != null){ 633 634 if(product.zonesLivraison != null){ 635 if(territoires && territoires !== undefined && product.zonesLivraison.length > 0 && territoires.length > 0 && product.codeTerritoireSelect != null){ 636 637 territoiresObj = _.pluck(territoires, 'value'); 638 ob = _.findWhere(territoiresObj, {codeTerritoire: product.codeTerritoireSelect}); 639 index = _.indexOf(_.pluck(territoiresObj, 'codeTerritoire'), ob.codeTerritoire); 640 641 ob = {}; 642 formulaireManager.createSelect(factory.PARAMETER_COUNTRY,ob,"DICO_PRODUCT_CHOISISSEZ_VOTRE_ZONE_DE_LIVRAISON",territoires,true, index); 643 subscriptionForm.fields.push(ob); 644 if(territoires.length > 1){ 645 hasmultizone=true; 646 } 647 } else if(zones && zones !== undefined && product.zonesLivraison.length > 0 && zones.length > 0 && product.zoneSelect != null){ 648 //On trie les zones par codeZonePort 649 zones = _.sortBy(zones, function(o) { return o.value.codeZonePort; }); 650 zonesObj = _.pluck(zones, 'value'); 651 ob = _.findWhere(zonesObj, {codeZonePort: product.zoneSelect}); 652 index = _.indexOf(_.pluck(zonesObj, 'codeZonePort'), ob.codeZonePort); 653 654 ob = {}; 655 formulaireManager.createSelect(factory.PARAMETER_ZONE,ob,"DICO_PRODUCT_CHOISISSEZ_VOTRE_ZONE_DE_LIVRAISON",zones,true, index); 656 subscriptionForm.fields.push(ob); 657 if(zones.length > 1){ 658 hasmultizone=true; 659 } 660 } 661 662 if(product.dureesAbonnement !== undefined){ 663 for(i = 0; i < product.dureesAbonnement.length;i++){ 664 ob = {}; 665 ob.id = factory.PARAMETER_TERMS+product.dureesAbonnement[i].key; 666 ob.label = product.dureesAbonnement[i].value; 667 ob.value = product.dureesAbonnement[i].key; 668 ob.dureeAbonnement = parseInt(product.dureesAbonnement[i].key.substring(0,product.dureesAbonnement[i].key.indexOf("-"))); 669 terms.push(ob); 670 } 671 } 672 673 terms = _.sortBy(terms, function(o) { return o.dureeAbonnement; });
674 if(product.supports !== undefined){ 675 for(i = 0; i < product.supports.length;i++){ 676 ob = {}; 677 ob.id = factory.PARAMETER_SUPPORT+product.supports[i].typeSupport; 678 ob.label = product.supports[i].libelleSupport; 679 ob.value = product.supports[i].typeSupport; 680 supports.push(ob); 681 } 682 } 683 684 685 if(terms.length < supports.length){ 686 diff = supports.length - terms.length; 687 for( i = 0; i < diff;i++){ 688 ob={}; 689 ob.disabled=true; 690 ob.label=" "; 691 terms.push(ob); 692 } 693 } else if(terms.length > supports.length){ 694 diff = terms.length - supports.length; 695 for( i = 0; i < diff;i++){ 696 ob={}; 697 ob.disabled=true; 698 ob.label=" "; 699 supports.push(ob); 700 } 701 } 702 703 if(terms.length == 1){ 704 terms[0].onlyone=true; 705 } 706 707 if(supports.length == 1){ 708 supports[0].onlyone=true; 709 } 710 711 subscriptionForm.twocolumn = true; 712 713 if(product.tarif.codeDureeAbonnement){ 714 ob = {}; 715 formulaireManager.createRadioGroup(factory.PARAMETER_TERMS,ob, 716 (product.estUnArticleLibre ? "DICO_PRODUCT_CHOISISSEZ_UN_CRITERE" : "DICO_PRODUCT_CHOISISSEZ_UNE_DUREE_DENGAGEMENT"), 717 terms,true,_.indexOf(_.pluck(terms, 'value'), product.tarif.codeDureeAbonnement.key)); 718 subscriptionForm.fields.push(ob); 719 } else { 720 subscriptionForm.twocolumn = false; 721 } 722 723 if(product.tarif.support) { 724 ob = {}; 725 formulaireManager.createRadioGroup(factory.PARAMETER_SUPPORT,ob,"DICO_PRODUCT_CHOISISSEZ_UN_SUPPORT",supports,true,_.indexOf(_.pluck(supports, 'value'), product.tarif.support.typeSupport));
726 subscriptionForm.fields.push(ob); 727 } else { 728 subscriptionForm.twocolumn = false; 729 } 730 731 let hideCombinaisonIfOneCombinaison = commonConfig.hideCombinaisonIfOneCombinaison || commonConfig.tryhidezone; 732 733 if(hideCombinaisonIfOneCombinaison){ 734 subscriptionForm.displaycombinaison = !(terms.length <= 1 && supports.length <= 1); 735 if((subscriptionForm.displaycombinaison == false || commonConfig.tryhidezone == true) && (hasmultizone == false || product.tarifUnique == true)){ 736 subscriptionForm.displayzone=false; 737 } 738 } 739 740 if(subscriptionForm.displaycombinaison == true && commonConfig.hideFormQuantity == false){ 741 subscriptionForm.displayQuantity = true; 742 }else if(subscriptionForm.displaycombinaison == false && commonConfig.hideFormQuantity == false){ 743 subscriptionForm.displayQuantity = true; 744 }else if(subscriptionForm.displaycombinaison == true && commonConfig.hideFormQuantity == true){ 745 subscriptionForm.displayQuantity = false; 746 }else if(subscriptionForm.displaycombinaison == false && commonConfig.hideFormQuantity == true){ 747 subscriptionForm.displayQuantity = false; 748 } 749 750 if(commonConfig.shopWithSubscriptionNumericOnly && subscriptionForm.displayQuantity && product.devis === false){ 751 subscriptionForm.displayQuantity = false; 752 } 753 } 754 755 ob = {}; 756 formulaireManager.createTextField(factory.PARAMETER_QUANTITY,ob,product.quantiteSelect,'DICO_PRODUCT_SELECTIONNER_UNE_QUANTITE',true); 757 subscriptionForm.fields.push(ob); 758 subscriptionForm.quantity = ob; 759 product.tarif.oldMontantTtc = product.tarif.montantTtc; 760 761 if(product.tarif !== undefined && product.tarif.montantLibre){ 762 product.tarif.montantTtc = null; 763 ob = {}; 764 formulaireManager.createTextField(factory.PARAMETER_AMOUNT,ob,"","DICO_SAISISSEZ_VOTRE_MONTANT",true); 765 subscriptionForm.fields.push(ob); 766 } 767 768 if(subscriptionForm.displayzone){ 769 subscriptionForm.displayzone=product.affZoneLivraison; 770 } 771 772 let position=0; 773 774 for(i = 0; i < subscriptionForm.fields.length; i++){ 775 if(subscriptionForm.fields[i].name === factory.PARAMETER_QUANTITY && subscriptionForm.displayQuantity){ 776 position++; 777 } else if(subscriptionForm.fields[i].name === factory.PARAMETER_TERMS){ 778 position++; 779 } else if(subscriptionForm.fields[i].name === factory.PARAMETER_SUPPORT){ 780 position++; 781 } else if(subscriptionForm.fields[i].name === factory.PARAMETER_AMOUNT){ 782 position++; 783 } else if(subscriptionForm.fields[i].name === factory.PARAMETER_ZONE && subscriptionForm.displayzone){ 784 position++; 785 } else if(subscriptionForm.fields[i].name === factory.PARAMETER_COUNTRY && subscriptionForm.displayzone){ 786 position++; 787 } 788 subscriptionForm.fields[i].position = position; 789 } 790 if(position == 1){ 791 subscriptionForm.hideProductSubscriptionFormNumber = true; 792 } 793 794 } else { 795 console.error("No tarif found"); 796 } 797 798 return subscriptionForm; 799 }; 800 801 return factory; 802 }]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.