1'use strict'; // 2 3// **************************************************** 4// Gestion du Panier 5// **************************************************** 6angular.module('AboShopApp').factory('cartManager', ['$q', '$rootScope','$localStorage', '$window','utils','$timeout','TbsWS','productsManager','commonConfig','formulaireManager', 'googleTagManager', 'pixelFbManager', 'atInternetManager', 'Auth', 7 function ($q, $rootScope, $localStorage, $window, utils, $timeout, TbsWS, productsManager,commonConfig,formulaireManager,googleTagManager,pixelFbManager, atInternetManager, Auth) { 8 var oldCart = null; 9 var productIndispo = false; 10 var factory = {}; 11 factory.model = {}; 12 factory.model.cart = {}; 13 14 factory.DICO_CONTENU_DU_PANIER_INCOHERENT_AVEC_ADRESSE_LIVRAISON="DICO_CONTENU_DU_PANIER_INCOHERENT_AVEC_ADRESSE_LIVRAISON"; 15 factory.CART_DELIVERY_CONTENT_OK="CHECK_DELIVERY_OK"; 16 factory.CART_CHECK_ERROR="CART_CHECK_ERROR"; 17 factory.CART_CHECK_TARIF_ERROR="CART_CHECK_TARIF_ERROR"; 18 19 factory.UPLOAD_FILE_OK = "UPLOAD_FILE_OK"; 20 factory.UPLOAD_FILE_ERROR = "UPLOAD_FILE_ERROR"; 21 22 function _init(){ 23 _saveOldCart(); 24 25 factory.model.cart.id = $localStorage[commonConfig.currentInstance.keylogin].cartId; 26 if(!factory.model.cart.id || factory.model.cart.id === undefined){ 27 factory.model.cart.id = 0; 28 $localStorage[commonConfig.currentInstance.keylogin].cartId = factory.model.cart.id; 29 $localStorage[commonConfig.currentInstance.keylogin].checkCgv=false; 30 } 31 factory.model.cart.totalQtx = 0; 32 factory.model.cart.lignes = []; 33 } 34 35 function _saveOldCart() { 36 oldCart = Object.assign({}, factory.model.cart); 37 } 38 39 function initCart(data, checkProductIndispo){ 40 if (checkProductIndispo === undefined) { 41 checkProductIndispo = false; 42 } 43 productIndispo = false; 44 var deferred = $q.defer(); 45 var ob = {}; 46 if(data && data.id !== null && data.id !== undefined) { 47 if (factory.lastStatusReservedForNew(data)) { 48 $rootScope.openModalInformation('DICO_INFORMATION', 'DICO_PANIER_PRODUITS_RESERVES_AUX_NOUVEAUX_ABONNES'); 49 } else if (factory.lastStatusSoldOut(data) || factory.lastStatusValidityDates(data)) { 50 $rootScope.openModalInformation('DICO_INFORMATION', 'DICO_PANIER_PRODUITS_INDISPOS_RETIRES'); 51 productIndispo = true; 52 } else if (factory.lastStatusPaysInterdits(data)) { 53 $rootScope.openModalInformation('DICO_INFORMATION', 'DICO_PANIER_PRODUITS_INCOMPATIBLES_AVEC_PAYS_RETIRES'); 54 productIndispo = true; 55 } else { 56 if (!oldCart) { 57 _saveOldCart(); 58 } 59 if (checkProductIndispo && oldCart && oldCart.lignes && data.lignes.length < oldCart.lignes.length) { 60 $rootScope.openModalInformation('DICO_INFORMATION', 'DICO_PANIER_PRODUITS_INDISPOS_RETIRES'); 61 productIndispo = true; 62 } 63 oldCart = null; 64 } 65 66 for(var p in data){ 67 factory.model.cart[p] = data[p]; 68 } 69 factory.model.cart.totalQtx = 0; 70 71 if(factory.model.cart.lignes.length > 0){ 72 for(var p in $rootScope.lignesPourGestionQuantite){ 73 $rootScope.lignesPourGestionQuantite[p].unwatch(); 74 } 75 $rootScope.lignesPourGestionQuantite = {}; 76 for(var i=0;i<factory.model.cart.lignes.length;i++){ 77 googleTagManager.setProductInfosCart(factory.model.cart.lignes[i]); 78 factory.model.cart.totalQtx += factory.model.cart.lignes[i].quantite; 79 ob = {}; 80 ob.refLigneCommande = factory.model.cart.lignes[i].refLigneCommande; 81 ob.refProduit = factory.model.cart.lignes[i].produit.refProduit; 82 ob.quantite = factory.model.cart.lignes[i].quantite; 83 ob.codeTarif = factory.model.cart.lignes[i].codeTarif; 84 ob.quantiteMin = factory.model.cart.lignes[i].produit.quantiteMin; 85 ob.quantiteMax = factory.model.cart.lignes[i].produit.quantiteMax; 86 ob.ligne = factory.model.cart.lignes[i];
87 88 89 if (ob.ligne.typeAdresseLiv === 7) { 90 var client = ob.ligne.clientLiv; 91 client.nomAffiche = (client.adressePrincipale.civilite?client.adressePrincipale.civilite+' ':''); 92 client.nomAffiche += (client.adressePrincipale.prenom?client.adressePrincipale.prenom+' ':''); 93 client.nomAffiche += (client.adressePrincipale.nom?client.adressePrincipale.nom.toUpperCase()+' ':''); 94 ob.ligne.clientLiv = client; 95 } 96 97 factory.model.cart.lignes[i].produit.imageGrandFormat = factory.model.cart.lignes[i].produit.imageGrandFormat + '?v=' + commonConfig.forceversion; 98 factory.model.cart.lignes[i].produit.imagePetitFormat = factory.model.cart.lignes[i].produit.imagePetitFormat + '?v=' + commonConfig.forceversion; 99 for (var j = 0; j < factory.model.cart.lignes[i].produit.images.length; j++) { 100 factory.model.cart.lignes[i].produit.images[j] = factory.model.cart.lignes[i].produit.images[j] + '?v=' + commonConfig.forceversion; 101 } 102 103 if(factory.model.cart.lignes[i].produit.zonesLivraison.length == 1 && factory.model.cart.lignes[i].produit.zonesLivraison[0].codeZonePort == "all"){ 104 factory.model.cart.lignes[i].produit.zonesLivraison[0].libZonePort = "DICO_ALL_ZONES"; 105 factory.model.cart.lignes[i].produit.zonesLivraison[0].translate = true; 106 } 107 108 if(factory.model.cart.lignes[i].produit.tarif.zoneLivraison.codeZonePort == "all"){ 109 factory.model.cart.lignes[i].produit.tarif.zoneLivraison.libZonePort = "DICO_ALL_ZONES"; 110 factory.model.cart.lignes[i].produit.tarif.zoneLivraison.translate = true; 111 } 112 113 $rootScope.lignesPourGestionQuantite[ob.refLigneCommande] = ob; 114 115 $rootScope.lignesPourGestionQuantite[ob.refLigneCommande].unwatch = $rootScope.$watch("lignesPourGestionQuantite['"+ob.refLigneCommande+"'].quantite",function(newval, oldval, rootScope){ 116 if(newval != null){ 117 var n = ~~Number(newval); 118 if(!String(n) === newval || 119 (n < ob.quantiteMin || n > ob.quantiteMax)){ 120 //restore value 121 if(ob !== undefined){ 122 ob.quantitebck = parseInt(oldval); 123 ob.quantite = parseInt(oldval); 124 } 125 } else if(newval != oldval && ob.quantitebck === undefined){ 126 var qte = 0; 127 if(newval > oldval){ 128 qte = newval-oldval; 129 } else { 130 qte = oldval-newval; 131 qte = -qte; 132 } 133 //load new value 134 $rootScope.addQtePanier(ob.ligne,qte); 135 } else { 136 delete ob.quantitebck; 137 } 138 } 139 }, true); 140 } 141 } 142 143 factory.model.cart.id = data.id; 144 $localStorage[commonConfig.currentInstance.keylogin].cartId = factory.model.cart.id; 145 146 if($rootScope.doSetCustomerToCartOnNextReadCart) { 147 $rootScope.doSetCustomerToCartOnNextReadCart = false; 148 console.log('setcustomertocart/' + factory.model.cart.id); 149 TbsWS.call('setcustomertocart/' + factory.model.cart.id,'private').then( 150 function(status){ 151 deferred.resolve(true); 152 } 153 ); 154 } else { 155 deferred.resolve(true); 156 } 157 } else { 158 _init(); 159 deferred.resolve(true); 160 } 161 return deferred.promise; 162 } 163 164 function isInCart(refProduit,refTarif){ 165 var products = utils.contains(factory.model.cart.lignes,"refProduit",refProduit); 166 products = utils.contains(products,"refTarif",refTarif); 167 if(products.length == 0){ 168 return false; 169 } else { 170 return true; 171 } 172 } 173 174 function disabledOpenCart(){ 175 $rootScope.mytimeout = $timeout(function() { 176 factory.model.cart.addproduct = true; 177 $rootScope.openModalAddToCart( "DICO_AJOUT_AU_PANIER", "DICO_AJOUT_AU_PAN
177IER_MESSAGE"); 178 }, 100); 179 } 180 181 function goToCart(){ 182 $rootScope.goPageCart(); 183 } 184 185 function commonOpenCart(){ 186 $rootScope.mytimeout = $timeout(function() { 187 var $button = $("#nav-toggle").parent().find(".navbar-toggle"); 188 if($button.is(":visible") == true){ 189 //Mode mobile on doit ouvrir le menu mobile si besoin avant douvrir le panier 190 if($button.hasClass("collapsed")){ 191 $('#nav-toggle').collapse('toggle'); 192 } 193 } 194 factory.model.cart.addproduct = true; 195 }, 100); 196 } 197 198 function openCart(){ 199 if (typeof specificOpenCart === "function") { 200 //Methode qui peut etre utilise 201 //si le header est specifique client comme la nvo par exemple 202 specificOpenCart($rootScope,factory,$timeout); 203 } else if(commonConfig.goToCart){ 204 goToCart(); 205 }else if(commonConfig.disabledPopupCart){ 206 disabledOpenCart(); 207 } else { 208 commonOpenCart(); 209 } 210 } 211 212 factory.resetCart = function resetCart(){ 213 $localStorage[commonConfig.currentInstance.keylogin].cartId = undefined; 214 $localStorage[commonConfig.currentInstance.keylogin].checkCgv=false; 215 initCart({}); 216 }; 217 218 factory.changeStateCgv = function changeStateCgv(state){ 219 $localStorage[commonConfig.currentInstance.keylogin].checkCgv=state; 220 }; 221 222 factory.getStateCgv = function getStateCgv(){ 223 let state = $localStorage[commonConfig.currentInstance.keylogin].checkCgv; 224 if(state === undefined){ 225 return false; 226 } 227 return state; 228 }; 229 230 factory.getPromoCodeField = function getPromoCodeField(){ 231 var promoForm = {},field={}; 232 promoForm.alert = {}; 233 promoForm.alert.message = []; 234 promoForm.success = {}; 235 promoForm.success.message = []; 236 promoForm.fields = []; 237 238 field = {}; 239 formulaireManager.createTextField("promo",field,"",'Enter the sale code',true); 240 promoForm.fields.push(field); 241 242 return promoForm; 243 }; 244 245 factory.addQuantity = function addQuantity(ligne, quantite){ 246 var deferred = $q.defer(); 247 248 var datas = {}; 249 250 if(quantite == null || quantite === undefined){ 251 datas.quantite = 1; 252 } else { 253 datas.quantite = quantite; 254 } 255 256 datas.refProduit = ligne.produit.refProduit; 257 datas.refTarif = ligne.produit.tarif.refTarif; 258 TbsWS.call('setquantity/'+ $rootScope.preferredLanguage+'/'+factory.model.cart.id,'public',datas).then( 259 function(data){ 260 initCart(data, true).then( 261 function(){ 262 deferred.resolve(true); 263 } 264 ); 265 googleTagManager.checkoutEvent(factory.model.cart.lignes, factory.model.cart.totalTtc, factory.model.cart.id); 266 } 267 ,function(error) { 268 deferred.resolve(false); 269 } 270 ); 271 return deferred.promise; 272 }; 273 274 factory.applyPromoCodeClient = function applyPromoCodeClient(promoForm){ 275 var deferred = $q.defer(); 276 promoForm.alert.message = []; 277 promoForm.success.message = []; 278 279 if(formulaireManager.verifForm(promoForm)){ 280 var datas = {},scope='private',codepromo; 281 codepromo = formulaireManager.getDefaultValue(_.findWhere(promoForm.fields, {name: "promo"}),""); 282 283 TbsWS.call('applycodepromoclient/'+ $rootScope.preferredLanguage+'/'+factory.model.cart.id+'/'+codepromo,scope,datas).then( 284 function(data){ 285 initCart(data, true).then( 286 function(status){ 287 if(status){ 288 if(factory.model.cart.promotion != null && factory.model.cart.promotion.codePromo == codepromo){ 289 formulaireManager.resetForm(promoForm); 290 promoForm.success.message.push('DICO_CART_CODE_VALIDE'); 291 } else if(factory.model.cart.clientreduction != null && factory.model.cart.clientreduction.codePromo == codepromo){ 292 formulaireManager.resetForm(promoForm); 293 promoForm.success.message.push('DICO_CART_CODE_VALIDE'); 294 } else if (factory.model.cart.lignes.some(function (l) { return l.tauxRemise > 0 })) { 295 formulaireManager.resetForm(promoForm); 296 promoForm.success.message.push('DICO_CART_CODE_VALIDE'); 297 } else { 298 promoForm.alert.message.push('DICO_ERREUR_CART_CODE_INVALIDE'); 299 } 300 } 301 deferred.resolve(true); 302 } 303 ); 304 } 305 ,function(error) { 306 initCart().then( 307 function(status){ 308 deferred.resolve(true); 309 } 310 ); 311 } 312 ); 313 } else { 314 deferred.resolve(false); 315 } 316 return deferred.promise; 317 }; 318 319 factory.deletePromotion = function deletePromotion(typeCodePromo){ 320 var deferred = $q.defer(); 321 TbsWS.call('deletecodepromoclient/'+ $rootScope.preferredLanguage+'/'+factory.model.cart.id+'/'+typeCodePromo,'private').then( 322 function(data){
323 initCart(data, true).then( 324 function(status){ 325 deferred.resolve(true); 326 } 327 ); 328 } 329 ,function(error) { 330 initCart().then( 331 function(status){ 332 deferred.resolve(true); 333 } 334 ); 335 } 336 ); 337 return deferred.promise; 338 }; 339 340 factory.getDonateForm = function getDonateForm(){ 341 var donateForm = {}; 342 donateForm.fields = []; 343 344 var ob; 345 ob = {}; 346 formulaireManager.createTextField("amount",ob,"","DICO_SAISISSEZ_VOTRE_MONTANT",true); 347 donateForm.fields.push(ob); 348 349 return donateForm; 350 }; 351 352 function localAddToCart(product,quantite){ 353 354 if(product.addToCartInProgress === true){ 355 return; 356 } 357 358 if (product.urlExterne != null && product.urlExterne != '') { 359 $rootScope.openExterne(product,false); 360 return; 361 } 362 363 if(product.devis && Auth.isClientConnecte() == false){ 364 $rootScope.openModalInformationWithGoLogin('DICO_INFORMATION','DICO_VOUS_DEVEZ_ETRE_CONNECTER_POUR_DEMANDER_UN_DEVIS'); 365 return; 366 } 367 368 let datas = {}; 369 370 factory.model.cart.addproduct = false; 371 372 if(quantite == null || quantite === undefined){ 373 datas.quantite = 1; 374 } else { 375 datas.quantite = quantite; 376 } 377 378 datas.refProduit = product.refProduit; 379 datas.refTarif = product.tarif.refTarif; 380 datas.refAboEchu = product.refAboEchu; 381 datas.codeClientLiv = product.codeClientLiv; 382 datas.refBoutique = commonConfig.currentInstance.idshop; 383 var gtmProductInfos = googleTagManager.getProductInfosCart(product.refProduit); 384 if (gtmProductInfos != null) { 385 datas.gtmListName = gtmProductInfos.listName; 386 datas.gtmListId = gtmProductInfos.listId; 387 datas.gtmIndex = gtmProductInfos.index; 388 datas.gtmBrand = gtmProductInfos.brand; 389 } 390 391 if(product.tarif.montantLibre){ 392 datas.montantTtc = factory.strToFloat(product.tarif.montantTtc); 393 } 394 if(product.devis){ 395 product.addToCartInProgress=true; 396 $rootScope.spinnerShow(); 397 } 398 399 if(commonConfig.shopWithSubscriptionNumericOnly && (product.estUnAbonnement || product.estUneFormule) && (product.devis === false || product.devis == null)){ 400 if(isInCart(product.refProduit, product.tarif.refTarif)){ 401 $rootScope.openModalInformation('DICO_INFORMATION','DICO_CE_PRODUIT_NE_PEUT_ETRE_AJOUTE_QU_UNE_SEULE_FOIS'); 402 return; 403 } 404 } 405 406 TbsWS.call('addtocart/'+ $rootScope.preferredLanguage+'/'+factory.model.cart.id,'public',datas).then( 407 function(data){ 408 $rootScope.spinnerHide().then( 409 function(){ 410 if(data.lastStatus == "Delivery problem"){ 411 $rootScope.openModalInformation('DICO_INFORMATION','DICO_CART_ADRESSE_DE_LIVRAISON_NON_COMPATIBLE_AVEC_CE_PRODUIT'); 412 } else if (factory.lastStatusReservedForNew(data)) { 413 $rootScope.openModalInformation('DICO_INFORMATION','DICO_CART_PRODUIT_RESERVE_AUX_NOUVEAUX_ABONNES'); 414 } else if (factory.lastStatusPaysInterdits(data)) { 415 $rootScope.openModalInformation('DICO_INFORMATION','DICO_PANIER_PRODUITS_INCOMPATIBLES_AVEC_PAYS_RETIRES'); 416 } else if (factory.lastStatusSoldOut(data) || factory.lastStatusValidityDates(data)) { 417 $rootScope.openModalInformation('DICO_INFORMATION','DICO_PANIER_PRODUITS_INDISPOS_RETIRES'); 418 } else if(data.lastStatus == null){ 419 if(product.devis){ 420 $rootScope.openModalInformation('DICO_INFORMATION','DICO_DEVIS_ENVOYE'); 421 } else { 422 initCart(data, true).then( 423 function(){ 424 openCart(); 425 } 426 ); 427 } 428 googleTagManager.push({'event': 'user_action', 'user_action_1': 'add_to_cart', 'user_action_2': product.libelle}, true); 429 googleTagManager.addToCartEvent(product, data.totalTtc, data.id); 430 pixelFbManager.send('track', 'AddToCart'); 431 } 432 $timeout(function() { 433 product.addToCartInProgress=false; 434 },2000); 435 } 436 ); 437 } 438 ,function(error) { 439 $rootScope.spinnerHide().then( 440 function(){ 441 $rootScope.openModalInformation('DICO_INFORMATION','DICO_ERREUR_CART_AJOUT_PRODUIT_DANS_PANIER'); 442 $timeout(function() { 443 product.addToCartInProgress=false; 444 },2000); 445 } 446 ); 447 } 448 ); 449 } 450
451 factory.sendMontantLibre = function sendMontantLibre(product, quantite, subscriptionForm) { 452 let ob = _.findWhere(subscriptionForm.fields, {name: productsManager.PARAMETER_AMOUNT}); 453 if(ob !== undefined){ 454 if(verifFloat(ob, product.tarif.montantTtc)){ 455 let montantTtc = factory.strToFloat(product.tarif.montantTtc); 456 let oldMontantTtc = factory.strToFloat(product.tarif.oldMontantTtc); 457 458 if(montantTtc < oldMontantTtc || montantTtc <= 0){ 459 ob.error = true; 460 ob.warningmessage = "DICO_LEMONTANT_SAISIE_EST_INFERIEUR_AU_MINIMUM"; 461 } else { 462 localAddToCart(product,quantite); 463 } 464 } 465 } 466 }; 467 var filterFloat = function (value) { 468 if(/^(\-|\+)?([0-9]+(\.[0-9]+)?)$/ 469 .test(value)) 470 return Number(value); 471 return NaN; 472 }; 473 474 function verifFloat(field, montantStr){ 475 let montant = montantStr; 476 if(montant == null || montant === undefined){ 477 field.error = true; 478 field.warningmessage = "DICO_CART_MERCI_DE_SAISIR_UN_MONTANT_NUMERIQUE"; 479 return false; 480 } else { 481 montant = montant.replace(",","."); 482 if(isNaN(filterFloat(montant))){ 483 field.error = true; 484 field.warningmessage = "DICO_CART_MERCI_DE_SAISIR_UN_MONTANT_NUMERIQUE"; 485 return false; 486 } else { 487 montant = ""+montant; 488 var ar = montant.split("."); 489 if(ar.length == 2){ 490 if(ar.length > 2){ 491 field.error = true; 492 field.warningmessage = "DICO_CART_MERCI_DE_SAISIR_UN_MONTANT_AVEC_DEUX_CHIFFRES_APRES_VIRGULES"; 493 return false; 494 } 495 } 496 } 497 } 498 return true; 499 } 500 501 factory.sendDonation = function sendDonation(donateForm) { 502 if(!formulaireManager.verifForm(donateForm)){ 503 return; 504 } else { 505 if(verifFloat(donateForm.fields[0], donateForm.fields[0].value)){ 506 TbsWS.call('adddonationtocart/'+ $rootScope.preferredLanguage+'/'+factory.model.cart.id+'/'+montant,'public').then( 507 function(data){ 508 factory.model.cart.addproduct = false; 509 if(data.lastStatus == null){ 510 initCart(data, true).then( 511 function(){ 512 openCart(); 513 } 514 ); 515 } 516 } 517 ,function(error) { 518 initCart(); 519 } 520 ); 521 } 522 } 523 }; 524 525 function _checkDeliveryVsContentOfCart(deferred){ 526 var status=""; 527 528 TbsWS.call('checkdelivery/' + factory.model.cart.id,'private').then( 529 function(result){ 530 if(result && result.key === "checkdelivery"){ 531 status = result.value; 532 if(!status || status === undefined){ 533 deferred.resolve(factory.CART_CHECK_ERROR); 534 } else { 535 status = status.replace(/"/g,''); 536 if(status === factory.CART_DELIVERY_CONTENT_OK){ 537 deferred.resolve(status); 538 } else { 539 deferred.resolve(factory.DICO_CONTENU_DU_PANIER_INCOHERENT_AVEC_ADRESSE_LIVRAISON); 540 } 541 } 542 } else { 543 deferred.resolve(factory.CART_CHECK_ERROR); 544 } 545 } 546 ); 547 return deferred.promise; 548 }; 549 550 factory.checkDeliveryVsContentOfCart = function checkDeliveryVsContentOfCart(){ 551 var deferred = $q.defer(); 552 553 $rootScope.filtrepaiement(factory.model.cart, false).then( 554 function(status){ 555 if(status !== undefined && status !== ""){ 556 status = status.replace(/"/g,''); 557 deferred.resolve(status); 558 } else { 559 _checkDeliveryVsContentOfCart(deferred); 560 } 561 } 562 ); 563 return deferred.promise; 564 }; 565 566 factory.strToFloat = function strToFloat(varStr){ 567 let value = 0; 568 if(varStr !== undefined && varStr !== ""){ 569 value = parseFloat(varStr.replace(",",".")); 570 } 571 return value; 572 }; 573 574 factory.addToCart = function addToCart(product, quantite) { 575 localAddToCart(product,quantite); 576 }; 577 578 factory.loadCart = function loadCart() {
579 initCart().then( 580 function(){ 581 TbsWS.call('getcartcontent/'+ $rootScope.preferredLanguage +'/' +factory.model.cart.id, 'public').then( 582 function(data){ 583 initCart(data, true); 584 } 585 ,function(error) { 586 initCart(); 587 } 588 ); 589 } 590 ); 591 }; 592 593 factory.loadCartWaiting = function loadCartWaiting() { 594 var deferred = $q.defer(); 595 initCart().then( 596 function(status){ 597 if(status){ 598 TbsWS.call('getcartcontent/'+ $rootScope.preferredLanguage +'/' +factory.model.cart.id, 'public').then( 599 function(data){ 600 initCart(data, true).then( 601 function(status){ 602 if($rootScope.doRefreshCartOnNextReadCart) { 603 $rootScope.doRefreshCartOnNextReadCart = false; 604 factory.refreshCart().then(function(){ 605 deferred.resolve(true); 606 }); 607 } else { 608 deferred.resolve(true); 609 } 610 } 611 ); 612 } 613 ,function(error) { 614 initCart().then( 615 function(status){ 616 deferred.resolve(true); 617 } 618 ); 619 } 620 ); 621 } else { 622 deferred.resolve(true); 623 } 624 } 625 ); 626 return deferred.promise; 627 }; 628 629 factory.loadCartCheck = function loadCartCheck() { 630 631 var cOrder = factory.model.cart; 632 633 if (commonConfig.atInternetId !== undefined){ 634 for (var i = 0; i < cOrder.lignes.length; ++i) { 635 var ligne = cOrder.lignes[i]; 636 637 var type = ''; 638 if (ligne.produit.tarif.arrondiSurTtc) { 639 type = 'PARTICULIER'; 640 } else { 641 type = 'PRO'; 642 } 643 atInternetManager.send({name: 'paiement', chapter1: 'boutiqueMM-' + commonConfig.target, chapter2: 'abonnement', chapter3: type + '-' + ligne.produit.libelle, level2: '74'}); 644 } 645 } 646 647 var deferred = $q.defer(); 648 factory.loadCartWaiting().then( 649 function() { 650 if (!productIndispo) { 651 deferred.resolve(true); 652 } 653 } 654 ); 655 return deferred.promise; 656 } 657 658 // actualise la quantité de chaque ligne pour bien appliquer les cadeaux après connexion (QIOT-1437) 659 factory.refreshCart = function refreshCart(){ 660 var deferred = $q.defer(); 661 662 if (factory.model.cart != null && factory.model.cart.lignes != null && factory.model.cart.lignes.length > 0) { 663 var refreshLignes = []; 664 for (var k = 0; k < factory.model.cart.lignes.length; ++k) { 665 var ligne = factory.model.cart.lignes[k]; 666 var datas = { 667 quantite: ligne.quantite, 668 refProduit: ligne.produit.refProduit, 669 refTarif: ligne.produit.tarif.refTarif 670 }; 671 refreshLignes.push(TbsWS.call('setquantity/'+$rootScope.preferredLanguage+'/'+factory.model.cart.id,'public',datas)); 672 } 673 Promise.all(refreshLignes).then( 674 function () { 675 deferred.resolve(true); 676 } 677 ); 678 } else { 679 deferred.resolve(true); 680 } 681 return deferred.promise; 682 }; 683 684 factory.deleteToCart = function deleteToCart(refLigneCommande) { 685 return TbsWS.call('deletetocart/'+ $rootScope.preferredLanguage + '/' + refLigneCommande,'public').then( 686 function(data){ 687 initCart(data); 688 googleTagManager.checkoutEvent(factory.model.cart.lignes, factory.model.cart.totalTtc, factory.model.cart.id); 689 $rootScope.$emit('cartItemDeleted'); 690 } 691 ,function(error) { 692 initCart(); 693 } 694 ); 695 696 }; 697 698 factory.setOffersPayment = function setOffersPayment(typePaiement){ 699 if(commonConfig.filtrepaiement !== undefined && typeof commonConfig.filtrepaiement === "function") { 700 var datas = { type: typePaiement.value.typeMoyenPaiement }; 701 TbsWS.call('setofferspayment/' + $rootScope.preferredLanguage+ '/' + factory.model.cart.id,'private', datas).then( 702 function(data) { 703 if (data != null && data !== '') { 704 initCart(data, true); 705 } 706 }, 707 function(error) {
708 initCart(); 709 } 710 ); 711 } 712 } 713 714 factory.setStartTunnelAchat = function setStartTunnelAchat(state) { 715 $rootScope.signin.fromBasket = state; 716 if(state === true){ 717 Auth.setCartIsInProgress(); 718 } 719 } 720 721 factory.uploadFileToCart = function uploadFileToCart(fichier, cs) { 722 var deferred = $q.defer(); 723 TbsWS.call('uploadfile/'+ factory.model.cart.id + '/' + cs, 'private', fichier).then( 724 function(success){ 725 let error = true; 726 let message = "DICO_ERREUR_UPLOAD_PIECE_JOINTE"; 727 if(success.key !== undefined && success.key === "uploadfile"){ 728 if(success.value == factory.UPLOAD_FILE_OK) { 729 error = false; 730 } else if(success.value.contains(factory.UPLOAD_FILE_ERROR+"##")) { 731 message = success.value.replace(factory.UPLOAD_FILE_ERROR+"##",""); 732 } 733 } 734 if(error){ 735 deferred.reject(message); 736 } else { 737 deferred.resolve(); 738 } 739 } 740 ,function(error) { 741 deferred.reject("DICO_ERREUR_UPLOAD_PIECE_JOINTE"); 742 } 743 ); 744 return deferred.promise; 745 } 746 747 factory.lastStatusReservedForNew = function lastStatusReservedForNew(cart) { 748 if (cart == null) { 749 cart = factory.model.cart; 750 } 751 return cart.lastStatus === 'Reserved for new problem'; 752 } 753 754 factory.lastStatusPaysInterdits = function lastStatusPaysInterdits(cart) { 755 if (cart == null) { 756 cart = factory.model.cart; 757 } 758 return cart.lastStatus === 'Country not authorized problem'; 759 } 760 761 factory.lastStatusSoldOut = function lastStatusSoldOut(cart) { 762 if (cart == null) { 763 cart = factory.model.cart; 764 } 765 return cart.lastStatus === 'Sold out'; 766 } 767 768 factory.lastStatusValidityDates = function lastStatusValidityDates(cart) { 769 if (cart == null) { 770 cart = factory.model.cart; 771 } 772 return cart.lastStatus === 'Validity dates problem'; 773 } 774 775 factory.addressIsRequired = function addressIsRequired() { 776 return !factory.model.cart.panierNumeriqueOnly; 777 } 778 779 return factory; 780 }]);
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.