ng-easycommerce 0.0.478 → 0.0.480

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +8 -0
  2. package/bundles/ng-easycommerce.umd.js +234 -82
  3. package/bundles/ng-easycommerce.umd.js.map +1 -1
  4. package/bundles/ng-easycommerce.umd.min.js +1 -1
  5. package/bundles/ng-easycommerce.umd.min.js.map +1 -1
  6. package/esm2015/lib/core.consts.js +26 -1
  7. package/esm2015/lib/ec-component/collection-ec/collection-ec.component.js +2 -2
  8. package/esm2015/lib/ec-component/product-ec/product-ec.component.js +5 -2
  9. package/esm2015/lib/ec-directive/product-stock.directive.js +4 -2
  10. package/esm2015/lib/interfaces/analytics/event-key.model.js +1 -1
  11. package/esm2015/lib/services/parameters.service.js +2 -2
  12. package/esm2015/lib/services/products/product-detail.service.js +33 -8
  13. package/esm2015/lib/services/products/products.service.js +16 -7
  14. package/esm2015/lib/utils/analytics/facebook-pixel.service.js +9 -6
  15. package/esm2015/lib/utils/analytics/google-analytics.service.js +13 -9
  16. package/esm2015/lib/utils/analytics/gtm.service.js +134 -53
  17. package/esm5/lib/core.consts.js +26 -1
  18. package/esm5/lib/ec-component/collection-ec/collection-ec.component.js +2 -2
  19. package/esm5/lib/ec-component/product-ec/product-ec.component.js +5 -2
  20. package/esm5/lib/ec-directive/product-stock.directive.js +4 -2
  21. package/esm5/lib/interfaces/analytics/event-key.model.js +1 -1
  22. package/esm5/lib/services/parameters.service.js +2 -2
  23. package/esm5/lib/services/products/product-detail.service.js +33 -8
  24. package/esm5/lib/services/products/products.service.js +16 -7
  25. package/esm5/lib/utils/analytics/facebook-pixel.service.js +9 -6
  26. package/esm5/lib/utils/analytics/google-analytics.service.js +13 -9
  27. package/esm5/lib/utils/analytics/gtm.service.js +134 -53
  28. package/fesm2015/ng-easycommerce.js +234 -82
  29. package/fesm2015/ng-easycommerce.js.map +1 -1
  30. package/fesm5/ng-easycommerce.js +234 -82
  31. package/fesm5/ng-easycommerce.js.map +1 -1
  32. package/lib/core.consts.d.ts +19 -0
  33. package/lib/ec-component/product-ec/product-ec.component.d.ts +3 -0
  34. package/lib/interfaces/analytics/event-key.model.d.ts +1 -1
  35. package/lib/services/products/product-detail.service.d.ts +7 -1
  36. package/lib/utils/analytics/gtm.service.d.ts +2 -1
  37. package/ng-easycommerce.metadata.json +1 -1
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ # version 0.0.480
2
+ - Se cambia eventos GTM para enviar la informacion correcta.
3
+ - Se modifica el addToCart para que contemple las variantes y las pueda agregar al carrito.
4
+ - Se modifica la directiva ecProductStock para que contemple el stock de la variante en caso de tener.
5
+ - Se agrega en las constantes la variable paramsProductsWithUniqueVariant para poder configurar la muestra de las variantes en el collection.
6
+ - Se modifica y corrige en la funcion getProductsWithUniqueVariant del servicio de producto, el caso defaultFirstOption == true.
7
+ # version 0.0.479 (para prueba)
8
+ - Se cambia una función de analytics para probar GTM.
1
9
  # version 0.0.478
2
10
  - Se agrega y configura el filtro por fecha de creación, para que se agregue en los filtros_top.
3
11
  # version 0.0.477
@@ -497,6 +497,31 @@
497
497
  */
498
498
  this.setCountries = function (countries) { return _this.countries = countries; };
499
499
  this.getCountries = function () { return _this.countries; };
500
+ /**
501
+ * @description esta variable se utiliza para configurar los parametros cuando se desea mostrar
502
+ * variantes el listado de productos.
503
+ * @param {string}type tipo de options
504
+ * @param {string}code codigo de options
505
+ * @param {boolean}defaultFirstOption `true` toma el primer option del producto en general
506
+ * @param {boolean}checkIfStock `true` se realiza un chequeo de si la variante tiene stock para mostrarla
507
+ * @example ```javascript
508
+ * {
509
+ type: 'color',
510
+ code: 'color',
511
+ defaultFirstOption: false ,
512
+ checkIfStock:true
513
+ } ```
514
+ */
515
+ this.paramsProductsWithUniqueVariant = {
516
+ type: 'color',
517
+ code: 'color',
518
+ defaultFirstOption: false,
519
+ checkIfStock: true
520
+ };
521
+ this.setParamsProductsWithUniqueVariant = function (value) {
522
+ _this.paramsProductsWithUniqueVariant = __assign(__assign({}, _this.paramsProductsWithUniqueVariant), value);
523
+ };
524
+ this.getParamsProductsWithUniqueVariant = function () { return _this.paramsProductsWithUniqueVariant; };
500
525
  }
501
526
  /**
502
527
  *
@@ -1639,18 +1664,27 @@
1639
1664
  });
1640
1665
  }
1641
1666
  else {
1667
+ /**
1668
+ * se modifica el caso para cuando se toma el primer `option` del producto para
1669
+ * armar la lista de productos con variantes.
1670
+ */
1642
1671
  if (withOption.defaultFirstOption && ((_b = product.options) === null || _b === void 0 ? void 0 : _b.length)) {
1643
1672
  var firstOptions_1 = product.options[0];
1644
1673
  product.options[0].values.forEach(function (optionValue) {
1645
1674
  var modified_product = JSON.parse(JSON.stringify(product));
1646
- modified_product.options.find(function (option) { return option.type == firstOptions_1.type; }).values = [{ code: firstOptions_1.code, name: firstOptions_1.name }];
1675
+ modified_product.options.find(function (option) { return option.type == firstOptions_1.type; }).values = [{ code: optionValue.code, name: optionValue.name }];
1647
1676
  var variantAux = variants.find(function (variant) {
1648
- return ((withOption.checkIfStock && variant.stock > 0) || withOption.checkIfStock == false)
1649
- && variant.options.length
1650
- && variant.options.some(function (op) { return (op.hasOwnProperty(firstOptions_1.code.toLowerCase()) || op.hasOwnProperty(firstOptions_1.code.toUpperCase()))
1651
- && (op[firstOptions_1.code.toLowerCase()] || op[firstOptions_1.code.toUpperCase()]) === optionValue.code; });
1677
+ return variant.options.find(function (elem) { return elem[firstOptions_1.code] == optionValue.code; });
1652
1678
  });
1653
- variantAux && productsUniqueVariant.push(_this.productWithVariantValues(modified_product, variantAux, optionValue));
1679
+ if (variantAux && variantAux.images.length == 0) {
1680
+ variantAux.images = product.picturesdefault;
1681
+ }
1682
+ if (withOption.checkIfStock) {
1683
+ (variantAux && variantAux.stock > 0) ? productsUniqueVariant.push(_this.productWithVariantValues(modified_product, variantAux, optionValue)) : null;
1684
+ }
1685
+ else {
1686
+ variantAux && productsUniqueVariant.push(_this.productWithVariantValues(modified_product, variantAux, optionValue));
1687
+ }
1654
1688
  });
1655
1689
  }
1656
1690
  else {
@@ -2033,11 +2067,14 @@
2033
2067
  this.document = document;
2034
2068
  this.enabled = false;
2035
2069
  this.initialize = function (pixel_id) {
2036
- var new_analityc_script = _this.renderer.createElement('script');
2037
- new_analityc_script.type = 'text/javascript';
2038
- new_analityc_script.text = "!function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window, document,'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', " + pixel_id + ");";
2039
- _this.renderer.appendChild(_this.document.body, new_analityc_script);
2040
- _this.enabled = true;
2070
+ if (!_this.document.getElementById('facebook_pixel')) {
2071
+ var new_analityc_script = _this.renderer.createElement('script');
2072
+ new_analityc_script.id = "facebook_pixel";
2073
+ new_analityc_script.type = 'text/javascript';
2074
+ new_analityc_script.text = "!function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window, document,'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', " + pixel_id + ");";
2075
+ _this.renderer.appendChild(_this.document.body, new_analityc_script);
2076
+ _this.enabled = true;
2077
+ }
2041
2078
  setTimeout(function () { return _this.callEvent('initialize'); }, 1000);
2042
2079
  };
2043
2080
  this.callEvent = function (event_name, data) {
@@ -2396,14 +2433,18 @@
2396
2433
  }
2397
2434
  GoogleAnalyticsService.prototype.initialize = function (gtm_id) {
2398
2435
  var _this = this;
2399
- var declaration = this.renderer.createElement('script');
2400
- declaration.async = true;
2401
- declaration.src = "https://www.googletagmanager.com/gtag/js?id=" + gtm_id;
2402
- var initialization = this.renderer.createElement('script');
2403
- initialization.text = "window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '" + gtm_id + "')";
2404
- this.renderer.appendChild(this.document.head, initialization);
2405
- this.renderer.appendChild(this.document.head, declaration);
2406
- this.enabled = true;
2436
+ if (!document.getElementById('google_tag_manager')) {
2437
+ console.log('hay elemento');
2438
+ var declaration = this.renderer.createElement('script');
2439
+ declaration.async = true;
2440
+ declaration.id = 'google_tag_manager';
2441
+ declaration.src = "https://www.googletagmanager.com/gtag/js?id=" + gtm_id;
2442
+ var initialization = this.renderer.createElement('script');
2443
+ initialization.text = "window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '" + gtm_id + "')";
2444
+ this.renderer.appendChild(this.document.head, initialization);
2445
+ this.renderer.appendChild(this.document.head, declaration);
2446
+ this.enabled = true;
2447
+ }
2407
2448
  setTimeout(function () { return _this.startListeningPageViews(gtm_id); }, 1000);
2408
2449
  };
2409
2450
  GoogleAnalyticsService.ctorParameters = function () { return [
@@ -2477,29 +2518,31 @@
2477
2518
  };
2478
2519
  this.translateEventName = function (event_name) {
2479
2520
  switch (event_name) {
2480
- case 'view_item': return 'view_item_gtm';
2481
- case 'view_item_list': return 'view_item_list_gtm';
2482
- case 'checkout_init': return 'begin_checkout_gtm';
2483
- case 'shipping_info': return 'add_shipping_info_gtm';
2484
- case 'add_payment_info': return 'add_payment_info_gtm';
2485
- case 'purchase': return 'purchase_gtm';
2486
- case 'add_to_cart': return 'add_to_cart_gtm';
2487
- case 'remove_from_cart': return 'remove_from_cart_gtm';
2488
- case 'sign_up': return 'sign_up_gtm';
2521
+ case 'view_item': return 'view_item';
2522
+ case 'view_item_list': return 'view_item_list';
2523
+ case 'checkout_init': return 'begin_checkout';
2524
+ case 'shipping_info': return 'add_shipping_info';
2525
+ case 'add_payment_info': return 'add_payment_info';
2526
+ case 'purchase': return 'purchase';
2527
+ case 'add_to_cart': return 'add_to_cart';
2528
+ case 'remove_from_cart': return 'remove_from_cart';
2529
+ case 'sign_up': return 'sign_up';
2530
+ case 'select_promotion': return 'select_promotion';
2489
2531
  default: return null;
2490
2532
  }
2491
2533
  };
2492
2534
  this.evalEvent = function (event_name, data) {
2493
2535
  switch (event_name) {
2494
- case 'view_item_gtm': return _this.toViewItem(data);
2495
- case 'view_item_list_gtm': return _this.toViewItemList(data);
2496
- case 'checkout_init_gtm': return _this.toCheckoutInit(data);
2497
- case 'shipping_info_gtm': return _this.toShippingInfo(data);
2498
- case 'add_payment_info_gtm': return _this.toPaymentInfo(data);
2499
- case 'purchase_gtm': return _this.toPurchase(data);
2500
- case 'add_to_cart_gtm': return _this.toAddToCart(data);
2501
- case 'remove_from_cart_gtm': return _this.toRemoveToCart(data);
2502
- case 'sign_up_gtm': return _this.toSignUp(data);
2536
+ case 'view_item': return _this.toViewItem(data);
2537
+ case 'view_item_list': return _this.toViewItemList(data);
2538
+ case 'checkout_init': return _this.toCheckoutInit(data);
2539
+ case 'shipping_info': return _this.toShippingInfo(data);
2540
+ case 'add_payment_info': return _this.toPaymentInfo(data);
2541
+ case 'purchase': return _this.toPurchase(data);
2542
+ case 'add_to_cart': return _this.toAddToCart(data);
2543
+ case 'remove_from_cart': return _this.toRemoveToCart(data);
2544
+ case 'sign_up': return _this.toSignUp(data);
2545
+ case 'select_promotion': return _this.toSelectPromotion(data);
2503
2546
  default: return data;
2504
2547
  }
2505
2548
  };
@@ -2513,13 +2556,28 @@
2513
2556
  value: data.totals.total,
2514
2557
  transaction_id: data.number,
2515
2558
  countItems: ((_a = data.items) === null || _a === void 0 ? void 0 : _a.length) || 0,
2516
- items: data.items.map(function (item) { return ({
2517
- id: item.product.id,
2518
- name: item.product.name,
2519
- category: item.product.category,
2520
- price: item.total,
2521
- quantity: item.quantity
2522
- }); })
2559
+ items: data.items.map(function (item) {
2560
+ var _a, _b, _c, _d;
2561
+ return ({
2562
+ item_id: item.product.id,
2563
+ item_name: item.product.name,
2564
+ //coupon:'',
2565
+ discount: item.product.discount || 0,
2566
+ //index:'',
2567
+ item_brand: ((_a = item.product.attributes) === null || _a === void 0 ? void 0 : _a.length) ? item.product.attributes[0].name : '',
2568
+ item_category: item.product.category,
2569
+ // item_category2: product.category,
2570
+ // item_category3: product.category,
2571
+ // item_category4: product.category,
2572
+ // item_category5: product.category,
2573
+ //item_list_id: '',
2574
+ //item_list_name: '',
2575
+ item_variant: ((_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
2576
+ //location_id: '',
2577
+ price: ((_c = item.product.variants[0]) === null || _c === void 0 ? void 0 : _c.saleprice) || ((_d = item.product.variants[0]) === null || _d === void 0 ? void 0 : _d.price),
2578
+ quantity: item.product.quantity || 1,
2579
+ });
2580
+ })
2523
2581
  };
2524
2582
  };
2525
2583
  this.toCheckoutInit = function (data) {
@@ -2527,13 +2585,28 @@
2527
2585
  return {
2528
2586
  coupon: _this.toCartDiscount(data),
2529
2587
  currency: data.currency || "USD",
2530
- items: data.items.map(function (item) { return ({
2531
- id: item.product.id,
2532
- name: item.product.name,
2533
- category: item.product.category,
2534
- price: item.total,
2535
- quantity: item.quantity
2536
- }); }),
2588
+ items: data.items.map(function (item) {
2589
+ var _a, _b, _c, _d;
2590
+ return ({
2591
+ item_id: item.product.id,
2592
+ item_name: item.product.name,
2593
+ //coupon:'',
2594
+ discount: item.product.discount || 0,
2595
+ //index:'',
2596
+ item_brand: ((_a = item.product.attributes) === null || _a === void 0 ? void 0 : _a.length) ? item.product.attributes[0].name : '',
2597
+ item_category: item.product.category,
2598
+ // item_category2: product.category,
2599
+ // item_category3: product.category,
2600
+ // item_category4: product.category,
2601
+ // item_category5: product.category,
2602
+ //item_list_id: '',
2603
+ //item_list_name: '',
2604
+ item_variant: ((_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
2605
+ //location_id: '',
2606
+ price: ((_c = item.product.variants[0]) === null || _c === void 0 ? void 0 : _c.saleprice) || ((_d = item.product.variants[0]) === null || _d === void 0 ? void 0 : _d.price),
2607
+ quantity: item.product.quantity || 1,
2608
+ });
2609
+ }),
2537
2610
  value: ((_a = data.totals) === null || _a === void 0 ? void 0 : _a.total) || 0,
2538
2611
  };
2539
2612
  };
@@ -2553,11 +2626,9 @@
2553
2626
  };
2554
2627
  this.disable = function () { return _this.enabled = false; };
2555
2628
  this.toViewItem = function (product) {
2556
- var _a, _b;
2557
2629
  return {
2558
2630
  currency: product.currency,
2559
- items: [_this.toItem(product)],
2560
- value: ((_a = product.variants[0]) === null || _a === void 0 ? void 0 : _a.saleprice) || ((_b = product.variants[0]) === null || _b === void 0 ? void 0 : _b.price),
2631
+ items: [_this.toItem(product)]
2561
2632
  };
2562
2633
  };
2563
2634
  this.toViewItemList = function (data) {
@@ -2566,6 +2637,11 @@
2566
2637
  item_list_name: data.item_list_name || 'Collection',
2567
2638
  item_list_id: data.item_list_id || 'collection'
2568
2639
  };
2640
+ console.log('toViewItemList ', {
2641
+ items: data.products.map(function (product) { return _this.toItem(product); }),
2642
+ item_list_name: data.item_list_name || 'Collection',
2643
+ item_list_id: data.item_list_id || 'collection'
2644
+ });
2569
2645
  };
2570
2646
  this.toRemoveToCart = function (product) {
2571
2647
  var _a, _b;
@@ -2577,13 +2653,24 @@
2577
2653
  };
2578
2654
  };
2579
2655
  this.toItem = function (product) {
2580
- var _a, _b, _c;
2656
+ var _a, _b, _c, _d;
2581
2657
  return ({
2582
- item_name: product.name,
2583
2658
  item_id: product.id,
2659
+ item_name: product.name,
2660
+ //coupon:'',
2661
+ discount: product.discount || 0,
2662
+ //index:'',
2584
2663
  item_brand: ((_a = product.attributes) === null || _a === void 0 ? void 0 : _a.length) ? product.attributes[0].name : '',
2585
2664
  item_category: product.category,
2586
- price: ((_b = product.variants[0]) === null || _b === void 0 ? void 0 : _b.saleprice) || ((_c = product.variants[0]) === null || _c === void 0 ? void 0 : _c.price),
2665
+ // item_category2: product.category,
2666
+ // item_category3: product.category,
2667
+ // item_category4: product.category,
2668
+ // item_category5: product.category,
2669
+ //item_list_id: '',
2670
+ //item_list_name: '',
2671
+ item_variant: ((_b = product.variants[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
2672
+ //location_id: '',
2673
+ price: ((_c = product.variants[0]) === null || _c === void 0 ? void 0 : _c.saleprice) || ((_d = product.variants[0]) === null || _d === void 0 ? void 0 : _d.price),
2587
2674
  quantity: product.quantity || 1,
2588
2675
  });
2589
2676
  };
@@ -2592,15 +2679,30 @@
2592
2679
  return {
2593
2680
  coupon: _this.toCartDiscount(data),
2594
2681
  currency: data.currency || "USD",
2595
- items: data.items.map(function (item) { return ({
2596
- id: item.product.id,
2597
- name: item.product.name,
2598
- category: item.product.category,
2599
- price: item.total,
2600
- quantity: item.quantity
2601
- }); }),
2602
2682
  payment_type: ((_b = (_a = data.payments[0]) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.code) || 'not-payments',
2603
2683
  value: ((_c = data.totals) === null || _c === void 0 ? void 0 : _c.total) || 0,
2684
+ items: data.items.map(function (item) {
2685
+ var _a, _b, _c, _d;
2686
+ return ({
2687
+ item_id: item.product.id,
2688
+ item_name: item.product.name,
2689
+ //coupon:'',
2690
+ discount: item.product.discount || 0,
2691
+ //index:'',
2692
+ item_brand: ((_a = item.product.attributes) === null || _a === void 0 ? void 0 : _a.length) ? item.product.attributes[0].name : '',
2693
+ item_category: item.product.category,
2694
+ // item_category2: product.category,
2695
+ // item_category3: product.category,
2696
+ // item_category4: product.category,
2697
+ // item_category5: product.category,
2698
+ //item_list_id: '',
2699
+ //item_list_name: '',
2700
+ item_variant: ((_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
2701
+ //location_id: '',
2702
+ price: ((_c = item.product.variants[0]) === null || _c === void 0 ? void 0 : _c.saleprice) || ((_d = item.product.variants[0]) === null || _d === void 0 ? void 0 : _d.price),
2703
+ quantity: item.product.quantity || 1,
2704
+ });
2705
+ }),
2604
2706
  };
2605
2707
  };
2606
2708
  this.toShippingInfo = function (data) {
@@ -2608,20 +2710,40 @@
2608
2710
  return {
2609
2711
  coupon: _this.toCartDiscount(data),
2610
2712
  currency: data.currency || "USD",
2611
- items: data.items.map(function (item) { return ({
2612
- id: item.product.id,
2613
- name: item.product.name,
2614
- category: item.product.category,
2615
- price: item.total,
2616
- quantity: item.quantity
2617
- }); }),
2618
2713
  shipping_tier: ((_b = (_a = data.shipments[0]) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.code) || 'not-shipping',
2619
2714
  value: ((_c = data.totals) === null || _c === void 0 ? void 0 : _c.total) || 0,
2715
+ items: data.items.map(function (item) {
2716
+ var _a, _b, _c, _d;
2717
+ return ({
2718
+ item_id: item.product.id,
2719
+ item_name: item.product.name,
2720
+ //coupon:'',
2721
+ discount: item.product.discount || 0,
2722
+ //index:'',
2723
+ item_brand: ((_a = item.product.attributes) === null || _a === void 0 ? void 0 : _a.length) ? item.product.attributes[0].name : '',
2724
+ item_category: item.product.category,
2725
+ // item_category2: product.category,
2726
+ // item_category3: product.category,
2727
+ // item_category4: product.category,
2728
+ // item_category5: product.category,
2729
+ //item_list_id: '',
2730
+ //item_list_name: '',
2731
+ item_variant: ((_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
2732
+ //location_id: '',
2733
+ price: ((_c = item.product.variants[0]) === null || _c === void 0 ? void 0 : _c.saleprice) || ((_d = item.product.variants[0]) === null || _d === void 0 ? void 0 : _d.price),
2734
+ quantity: item.product.quantity || 1,
2735
+ });
2736
+ }),
2620
2737
  };
2621
2738
  };
2622
2739
  this.toSignUp = function (data) {
2623
2740
  return __assign$5({}, data);
2624
2741
  };
2742
+ this.toSelectPromotion = function (data) {
2743
+ return {
2744
+ prueba: true
2745
+ };
2746
+ };
2625
2747
  }
2626
2748
  GTMService.prototype.getDataLayer = function () {
2627
2749
  var window = this.browserGlobals.windowRef();
@@ -5601,7 +5723,7 @@
5601
5723
  this.waitUntilData = function (next) {
5602
5724
  var subscription = _this.parameters.subscribe(function (res) {
5603
5725
  if (res) {
5604
- _this.insertAnalitycs();
5726
+ next(res);
5605
5727
  subscription.unsubscribe();
5606
5728
  }
5607
5729
  });
@@ -7909,7 +8031,7 @@
7909
8031
  ((_a = items) === null || _a === void 0 ? void 0 : _a.length) && _this.cartService.addAllToCart(items);
7910
8032
  };
7911
8033
  _this.getObjectWithVariant = function () {
7912
- return { type: 'color', code: 'color', defaultFirstOption: false, checkIfStock: true };
8034
+ return _this.consts.getParamsProductsWithUniqueVariant();
7913
8035
  };
7914
8036
  _this.paramsSrv.parameters.subscribe(function (param) { return _this.params = param; });
7915
8037
  _this.defaultFilters = _this.consts.getDefaultFilters();
@@ -9119,22 +9241,47 @@
9119
9241
  return _this.productsService.getProductsWithUniqueVariant([product], withOption);
9120
9242
  };
9121
9243
  }
9122
- ProductDetailService.prototype.addToCart = function (quantity) {
9244
+ /**
9245
+ * @description agrega/actualiza un item en el carrito
9246
+ * @param quantity cantidad a agregar
9247
+ * @param variant_code **(opcional)** codigo de la variante seleccionada del producto.
9248
+ * @returns
9249
+ */
9250
+ ProductDetailService.prototype.addToCart = function (quantity, variant_code) {
9123
9251
  quantity = parseInt(quantity);
9124
9252
  if (!this.variants.length) {
9125
9253
  this.toastrService.show('cant-buy');
9126
9254
  return;
9127
9255
  }
9128
9256
  var product_selected = _.clone(this.productSubject.value);
9129
- if (this.variants.length > 1 || this.variants.length == 0 || this.asociatedDataSubject.value.stock == 0) {
9130
- this.variants.length == 0 && this.toastrService.show('no-variants');
9131
- (this.variants.length > 1 && this.asociatedDataSubject.value.stock > 0) && this.toastrService.show('variants-left');
9132
- (this.variants.length != 0 && this.asociatedDataSubject.value.stock == 0) && this.toastrService.show('out-of-stock');
9133
- return;
9257
+ var variant;
9258
+ switch (this.variants.length) {
9259
+ case 0:
9260
+ this.toastrService.show('no-variants');
9261
+ break;
9262
+ case 1:
9263
+ this.asociatedDataSubject.value.stock == 0 ?
9264
+ this.toastrService.show('out-of-stock') :
9265
+ variant = this.variants[0];
9266
+ break;
9267
+ default:
9268
+ if (variant_code) {
9269
+ variant = this.variants.find(function (variant) { return variant.code === variant_code; });
9270
+ if (variant.stock == 0) {
9271
+ this.toastrService.show('out-of-stock');
9272
+ variant = undefined;
9273
+ }
9274
+ }
9275
+ else {
9276
+ this.toastrService.show('variants-left');
9277
+ }
9278
+ break;
9134
9279
  }
9280
+ if (!variant)
9281
+ return;
9135
9282
  if (!this.validateQuantity(quantity))
9136
9283
  return;
9137
- this.cartService.addToCart(this.makeAffordableProduct(product_selected), quantity, this.variants[0].code);
9284
+ this.cartService.addToCart(this.makeAffordableProduct(product_selected), quantity, variant.code);
9138
9285
  };
9139
9286
  ;
9140
9287
  ProductDetailService.prototype.makeAffordableProduct = function (product_selected) {
@@ -9443,8 +9590,11 @@
9443
9590
  _this.quantity > 1 ? _this.quantity = _this.quantity - 1 : null;
9444
9591
  }
9445
9592
  };
9593
+ /**
9594
+ * @description Agrega el producto al carrito. Si es una variante se enviara el codigo de la variante.
9595
+ */
9446
9596
  _this.addToCart = function () {
9447
- _this.productService.addToCart(+_this.quantity);
9597
+ _this.product.currentOption ? _this.productService.addToCart(+_this.quantity, _this.product.currentOption.variantCode) : _this.productService.addToCart(+_this.quantity);
9448
9598
  };
9449
9599
  _this.getBrandName = function (product) {
9450
9600
  if (product && product.attributes)
@@ -16625,7 +16775,9 @@
16625
16775
  }
16626
16776
  });
16627
16777
  if (!existMark) {
16628
- existMark = _this.productDirective.variants.find(function (v) { return v.stock > 0; }) == undefined;
16778
+ existMark = _this.productDirective.variant_id ?
16779
+ _this.productDirective.variants.find(function (v) { return v.code == _this.productDirective.variant_id && v.stock > 0; }) == undefined :
16780
+ _this.productDirective.variants.find(function (v) { return v.stock > 0; }) == undefined;
16629
16781
  }
16630
16782
  return existMark;
16631
16783
  };