ng-easycommerce 0.0.681 → 0.0.682
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.
- package/README.md +14 -0
- package/bundles/ng-easycommerce.umd.js +870 -57
- package/bundles/ng-easycommerce.umd.js.map +1 -1
- package/bundles/ng-easycommerce.umd.min.js +1 -1
- package/bundles/ng-easycommerce.umd.min.js.map +1 -1
- package/esm2015/lib/ec-component/cart-ec/cart-ec.component.js +230 -2
- package/esm2015/lib/ec-component/checkout-ec/dataform-ec/dataform-ec.component.js +6 -3
- package/esm2015/lib/ec-component/checkout-ec/detail-checkout-block-ec/detail-checkout-block-ec.component.js +13 -4
- package/esm2015/lib/ec-component/index.js +4 -1
- package/esm2015/lib/ec-component/sidebar-ec/sidebar-ec.component.js +61 -1
- package/esm2015/lib/ec-component/widgets-ec/unit-promotion-price-ec/unit-promotion-price-ec.component.js +268 -0
- package/esm2015/lib/interfaces/cart-item.js +1 -1
- package/esm2015/lib/services/cart.service.js +186 -14
- package/esm2015/lib/services/checkout/checkout.service.js +2 -2
- package/esm2015/lib/utils/order-util.service.js +87 -1
- package/esm2015/public-api.js +2 -1
- package/esm5/lib/ec-component/cart-ec/cart-ec.component.js +236 -2
- package/esm5/lib/ec-component/checkout-ec/dataform-ec/dataform-ec.component.js +6 -3
- package/esm5/lib/ec-component/checkout-ec/detail-checkout-block-ec/detail-checkout-block-ec.component.js +13 -4
- package/esm5/lib/ec-component/index.js +4 -1
- package/esm5/lib/ec-component/sidebar-ec/sidebar-ec.component.js +61 -1
- package/esm5/lib/ec-component/widgets-ec/unit-promotion-price-ec/unit-promotion-price-ec.component.js +248 -0
- package/esm5/lib/interfaces/cart-item.js +1 -1
- package/esm5/lib/services/cart.service.js +188 -14
- package/esm5/lib/services/checkout/checkout.service.js +2 -2
- package/esm5/lib/utils/order-util.service.js +88 -1
- package/esm5/public-api.js +2 -1
- package/fesm2015/ng-easycommerce.js +882 -59
- package/fesm2015/ng-easycommerce.js.map +1 -1
- package/fesm5/ng-easycommerce.js +871 -59
- package/fesm5/ng-easycommerce.js.map +1 -1
- package/lib/ec-component/cart-ec/cart-ec.component.d.ts +139 -0
- package/lib/ec-component/checkout-ec/dataform-ec/dataform-ec.component.d.ts +3 -1
- package/lib/ec-component/index.d.ts +1 -0
- package/lib/ec-component/sidebar-ec/sidebar-ec.component.d.ts +52 -0
- package/lib/ec-component/widgets-ec/unit-promotion-price-ec/unit-promotion-price-ec.component.d.ts +117 -0
- package/lib/interfaces/cart-item.d.ts +54 -0
- package/lib/services/cart.service.d.ts +98 -1
- package/lib/utils/order-util.service.d.ts +58 -0
- package/ng-easycommerce.metadata.json +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
|
@@ -39,11 +39,150 @@ export declare class CartEcComponent extends ComponentHelper implements OnInit {
|
|
|
39
39
|
showTaxLegend: boolean;
|
|
40
40
|
cartLoading: boolean;
|
|
41
41
|
enableFieldNotesInArticleFile: boolean;
|
|
42
|
+
summaryPromotionAmount$: any;
|
|
43
|
+
hasAppliedCoupon$: any;
|
|
44
|
+
activeUnitPromotionItemId: number | null;
|
|
45
|
+
activeUnitPromotionSummaryStyles: {
|
|
46
|
+
[key: string]: string;
|
|
47
|
+
};
|
|
48
|
+
supportsUnitPromotionHover: boolean;
|
|
42
49
|
constructor(cartService: CartService, authService: AuthService, consts: Constants, productsService: ProductsService, router: Router, modalService: BsModalService, toastrService: ToastService, addressingService: AddressingService, channelConfigService: ChannelConfigService);
|
|
43
50
|
ngOnChanges(): void;
|
|
44
51
|
updateLoggedIn(): void;
|
|
45
52
|
ngOnInit(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Convierte un monto crudo al formato decimal esperado por la UI.
|
|
55
|
+
*
|
|
56
|
+
* @param amount Monto en centavos o entero crudo.
|
|
57
|
+
* @returns Monto decimal.
|
|
58
|
+
*/
|
|
46
59
|
toDecimal: (amount: any) => any;
|
|
60
|
+
/** @param item Ítem del carrito. @returns Porcentaje de descuento legacy para el badge `% OFF`. */
|
|
61
|
+
getItemDiscount: (item: any) => number;
|
|
62
|
+
/**
|
|
63
|
+
* Devuelve el porcentaje efectivo total del ítem, considerando promociones unitarias.
|
|
64
|
+
*
|
|
65
|
+
* @param item Ítem del carrito.
|
|
66
|
+
* @returns Porcentaje entero calculado contra el precio de referencia del ítem.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Si existe precio tachado, compara `finalPrice` contra `strikePrice`.
|
|
70
|
+
* Si no existe, usa `basePrice` como referencia.
|
|
71
|
+
* Esto permite mostrar un badge coherente cuando el precio visible ya incluye
|
|
72
|
+
* descuentos/promociones unitarias adicionales.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* // strikePrice 240000, finalPrice 45000 => 81
|
|
77
|
+
* this.getItemEffectiveDiscount(item);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
getItemEffectiveDiscount: (item: any) => number;
|
|
81
|
+
/** @param item Ítem del carrito. @returns Subtotal actual del renglón según backend. */
|
|
82
|
+
getDisplayedItemTotal: (item: any) => number;
|
|
83
|
+
/** @param item Ítem del carrito. @returns `true` si el backend informó promociones unitarias. */
|
|
84
|
+
hasUnitPromotions: (item: any) => boolean;
|
|
85
|
+
/** @param item Ítem del carrito. @returns `true` si el resumen activo pertenece a ese ítem. */
|
|
86
|
+
isUnitPromotionSummaryOpen: (item: any) => boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Abre el resumen del ítem al entrar con el mouse en desktop.
|
|
89
|
+
*
|
|
90
|
+
* @param item Ítem del carrito.
|
|
91
|
+
* @param anchor Elemento usado como ancla visual.
|
|
92
|
+
* @returns `void`
|
|
93
|
+
*/
|
|
94
|
+
handleUnitPromotionMouseEnter: (item: any, anchor: HTMLElement) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Cierra el resumen al salir con el mouse en desktop.
|
|
97
|
+
*
|
|
98
|
+
* @param item Ítem asociado al resumen.
|
|
99
|
+
* @returns `void`
|
|
100
|
+
*/
|
|
101
|
+
handleUnitPromotionMouseLeave: (item: any) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Abre el resumen de promociones unitarias para un ítem puntual.
|
|
104
|
+
*
|
|
105
|
+
* @param item Ítem del carrito.
|
|
106
|
+
* @param anchor Elemento de referencia para posicionamiento.
|
|
107
|
+
* @returns `void`
|
|
108
|
+
*/
|
|
109
|
+
openUnitPromotionSummary: (item: any, anchor?: HTMLElement) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Cierra el resumen activo.
|
|
112
|
+
*
|
|
113
|
+
* @param item Si se envía, solo cierra cuando coincide con el ítem activo.
|
|
114
|
+
* @returns `void`
|
|
115
|
+
*/
|
|
116
|
+
closeUnitPromotionSummary: (item?: any) => void;
|
|
117
|
+
/**
|
|
118
|
+
* Alterna manualmente la apertura del resumen para un ítem.
|
|
119
|
+
*
|
|
120
|
+
* @param item Ítem del carrito.
|
|
121
|
+
* @param anchor Elemento de referencia.
|
|
122
|
+
* @param event Evento del puntero.
|
|
123
|
+
* @returns `void`
|
|
124
|
+
*/
|
|
125
|
+
toggleUnitPromotionSummary: (item: any, anchor: HTMLElement, event: Event) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Maneja el click/tap sobre el precio en dispositivos sin hover.
|
|
128
|
+
*
|
|
129
|
+
* @param item Ítem del carrito.
|
|
130
|
+
* @param anchor Elemento usado como trigger.
|
|
131
|
+
* @param event Evento de click/tap.
|
|
132
|
+
* @returns `void`
|
|
133
|
+
*/
|
|
134
|
+
handleUnitPromotionPriceClick: (item: any, anchor: HTMLElement, event: Event) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Evita que eventos dentro del resumen se propaguen al documento.
|
|
137
|
+
*
|
|
138
|
+
* @param event Evento del puntero.
|
|
139
|
+
* @returns `void`
|
|
140
|
+
*/
|
|
141
|
+
stopUnitPromotionSummaryEvent: (event: Event) => void;
|
|
142
|
+
/** @param item Ítem del carrito. @returns Precio unitario base (`saleprice` o `price`). */
|
|
143
|
+
getOriginalUnitPrice: (item: any) => number;
|
|
144
|
+
/** @param item Ítem del carrito. @returns Precio tachado legacy o `0`. */
|
|
145
|
+
getStrikeThroughUnitPrice: (item: any) => number;
|
|
146
|
+
/** @param item Ítem del carrito. @returns Suma de promociones unitarias aplicadas. */
|
|
147
|
+
getUnitPromotionTotal: (item: any) => number;
|
|
148
|
+
/** @param item Ítem del carrito. @returns Precio final unitario luego de promociones. */
|
|
149
|
+
getFinalUnitPrice: (item: any) => number;
|
|
150
|
+
/** @param item Ítem del carrito. @returns Precio principal a mostrar junto al trigger. */
|
|
151
|
+
getDisplayedUnitPrice: (item: any) => number;
|
|
152
|
+
/** @param item Ítem del carrito. @returns `true` si debe mostrarse el precio base junto al final. */
|
|
153
|
+
shouldShowOriginalUnitPrice: (item: any) => boolean;
|
|
154
|
+
/** @param item Ítem del carrito. @returns `true` si además del base price existe tachado legacy. */
|
|
155
|
+
shouldShowLegacyPriceOrigin: (item: any) => boolean;
|
|
156
|
+
/** @param item Ítem del carrito. @returns Etiqueta final del resumen. */
|
|
157
|
+
getUnitPromotionFinalPriceLabel: (item: any) => string;
|
|
158
|
+
/**
|
|
159
|
+
* Busca dentro de una lista el ítem que tiene actualmente el resumen abierto.
|
|
160
|
+
*
|
|
161
|
+
* @param items Lista de ítems del carrito.
|
|
162
|
+
* @returns Ítem activo o `null`.
|
|
163
|
+
*/
|
|
164
|
+
getActiveUnitPromotionItem: (items: any) => any;
|
|
165
|
+
/** @param item Ítem del carrito. @returns Promociones unitarias crudas del backend. */
|
|
166
|
+
getUnitPromotions: (item: any) => any[];
|
|
167
|
+
/** Cierra el resumen al hacer click fuera en desktop. */
|
|
168
|
+
handleDocumentClick(): void;
|
|
169
|
+
/** Recalcula el modo de interacción y cierra el resumen al cambiar el viewport. */
|
|
170
|
+
handleWindowResize(): void;
|
|
171
|
+
/** Cierra el resumen en mobile al hacer scroll para evitar desalineación visual. */
|
|
172
|
+
handleWindowScroll(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Detecta si el dispositivo soporta `hover` real y debe comportarse como desktop.
|
|
175
|
+
*
|
|
176
|
+
* @returns `void`
|
|
177
|
+
*/
|
|
178
|
+
private updateUnitPromotionViewportMode;
|
|
179
|
+
/**
|
|
180
|
+
* Calcula estilos inline para mantener el resumen mobile dentro del viewport.
|
|
181
|
+
*
|
|
182
|
+
* @param anchor Elemento usado como ancla visual.
|
|
183
|
+
* @returns `void`
|
|
184
|
+
*/
|
|
185
|
+
private updateUnitPromotionSummaryStyles;
|
|
47
186
|
protected actualizarCantidad(item: any, cantidad: number | string, stock: number, id?: string): void;
|
|
48
187
|
cartItemPlus: (item: any) => void;
|
|
49
188
|
cartItemLess: (item: any) => void;
|
|
@@ -12,6 +12,7 @@ import { Constants } from '../../../core.consts';
|
|
|
12
12
|
import { ParametersService } from '../../../services/parameters.service';
|
|
13
13
|
import { ChannelConfigService } from '../../../services/channel-config.service';
|
|
14
14
|
import { CheckoutService } from '../../../services/checkout/checkout.service';
|
|
15
|
+
import { OrderUtilityService } from '../../../utils/order-util.service';
|
|
15
16
|
export declare class DataFormEcComponent extends ComponentHelper implements OnInit {
|
|
16
17
|
authService: AuthService;
|
|
17
18
|
fb: FormBuilder;
|
|
@@ -19,6 +20,7 @@ export declare class DataFormEcComponent extends ComponentHelper implements OnIn
|
|
|
19
20
|
addressingService: AddressingService;
|
|
20
21
|
cartService: CartService;
|
|
21
22
|
checkoutService: CheckoutService;
|
|
23
|
+
private orderUtils;
|
|
22
24
|
private modalService;
|
|
23
25
|
paramsService: ParametersService;
|
|
24
26
|
consts: Constants;
|
|
@@ -74,7 +76,7 @@ export declare class DataFormEcComponent extends ComponentHelper implements OnIn
|
|
|
74
76
|
private suppressDirty;
|
|
75
77
|
private addressSyncedForCompletion;
|
|
76
78
|
private lastSummaryTotalsSnapshot;
|
|
77
|
-
constructor(authService: AuthService, fb: FormBuilder, toast: ToastService, addressingService: AddressingService, cartService: CartService, checkoutService: CheckoutService, modalService: BsModalService, paramsService: ParametersService, consts: Constants, channelConfig: ChannelConfigService);
|
|
79
|
+
constructor(authService: AuthService, fb: FormBuilder, toast: ToastService, addressingService: AddressingService, cartService: CartService, checkoutService: CheckoutService, orderUtils: OrderUtilityService, modalService: BsModalService, paramsService: ParametersService, consts: Constants, channelConfig: ChannelConfigService);
|
|
78
80
|
ngOnInit(): void;
|
|
79
81
|
/**
|
|
80
82
|
* @description filtra los paises de acuerdo al a los codigos retornados en la funcion getCountries.
|
|
@@ -34,6 +34,7 @@ export * from "./widgets-ec/loading-full-ec/loading-full-ec.component";
|
|
|
34
34
|
export * from "./widgets-ec/loading-inline-ec/loading-inline-ec.component";
|
|
35
35
|
export * from "./widgets-ec/mercadopago-ec/mpcredit-ec/mpcredit-ec.component";
|
|
36
36
|
export * from "./widgets-ec/price-ec/price-ec.component";
|
|
37
|
+
export * from "./widgets-ec/unit-promotion-price-ec/unit-promotion-price-ec.component";
|
|
37
38
|
export * from "./widgets-ec/redsys-catch-ec/redsys-catch-ec.component";
|
|
38
39
|
export * from "./widgets-ec/redsys-pro-ec/redsys-pro-ec.component";
|
|
39
40
|
export * from "./widgets-ec/redsys-redirect-ec/redsys-redirect-ec.component";
|
|
@@ -22,10 +22,62 @@ export declare class SidebarEcComponent {
|
|
|
22
22
|
showTaxLegend: boolean;
|
|
23
23
|
cartLoading: boolean;
|
|
24
24
|
enableFieldNotesInArticleFile: boolean;
|
|
25
|
+
summaryPromotionAmount$: any;
|
|
26
|
+
hasAppliedCoupon$: any;
|
|
25
27
|
constructor(cartService: CartService, consts: Constants, authService: AuthService, router: Router, toastrService: ToastService, channelConfigService: ChannelConfigService);
|
|
26
28
|
ngOnInit(): void;
|
|
27
29
|
protected actualizarCantidad(item: any, cantidad: number | string, stock: number, id?: string): void;
|
|
28
30
|
redirectDetailProduct(product: any): void;
|
|
29
31
|
getVariants: (product: any) => any[];
|
|
32
|
+
/**
|
|
33
|
+
* Construye el badge `% OFF` legacy a partir de `price` y `saleprice`.
|
|
34
|
+
*
|
|
35
|
+
* @param saleprice Precio de venta actual.
|
|
36
|
+
* @param price Precio original tachado.
|
|
37
|
+
* @returns Texto del badge o string vacío cuando no corresponde mostrar descuento.
|
|
38
|
+
*/
|
|
30
39
|
createDiscountMessage(saleprice: number, price: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Devuelve el porcentaje de descuento a mostrar para un ítem del sidebar.
|
|
42
|
+
*
|
|
43
|
+
* @param item Ítem del carrito.
|
|
44
|
+
* @returns Porcentaje entero de descuento.
|
|
45
|
+
*/
|
|
46
|
+
getItemDiscount: (item: any) => number;
|
|
47
|
+
/**
|
|
48
|
+
* Devuelve el porcentaje efectivo total del ítem, considerando promociones unitarias.
|
|
49
|
+
*
|
|
50
|
+
* @param item Ítem del carrito.
|
|
51
|
+
* @returns Porcentaje entero calculado contra el precio de referencia del ítem.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Si el frontend muestra el precio final unitario junto con un precio tachado legacy,
|
|
55
|
+
* este helper evita inconsistencias visuales en el badge `% OFF`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* // strikePrice 240000, finalPrice 45000 => 81
|
|
60
|
+
* this.getItemEffectiveDiscount(item);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
getItemEffectiveDiscount: (item: any) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Devuelve el precio tachado del renglón completo, escalado por cantidad.
|
|
66
|
+
*
|
|
67
|
+
* @param item Ítem del carrito.
|
|
68
|
+
* @returns Total tachado del renglón o `0` cuando no corresponde mostrarlo.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Este helper es útil en sidebars que renderizan precios por renglón, no unitarios.
|
|
72
|
+
* Ejemplo: si el precio tachado unitario es `15000` y la cantidad es `2`,
|
|
73
|
+
* el valor mostrado debe ser `30000`.
|
|
74
|
+
*/
|
|
75
|
+
getDisplayedItemStrikeThroughTotal: (item: any) => number;
|
|
76
|
+
/**
|
|
77
|
+
* Devuelve el subtotal actual del renglón según backend.
|
|
78
|
+
*
|
|
79
|
+
* @param item Ítem del carrito.
|
|
80
|
+
* @returns Monto total del renglón.
|
|
81
|
+
*/
|
|
82
|
+
getDisplayedItemTotal: (item: any) => number;
|
|
31
83
|
}
|
package/lib/ec-component/widgets-ec/unit-promotion-price-ec/unit-promotion-price-ec.component.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { OnInit } from '@angular/core';
|
|
2
|
+
import { CartService } from '../../../services/cart.service';
|
|
3
|
+
export declare class UnitPromotionPriceEcComponent implements OnInit {
|
|
4
|
+
cartService: CartService;
|
|
5
|
+
/** Ítem del carrito normalizado que se va a renderizar. */
|
|
6
|
+
item: any;
|
|
7
|
+
/** Indica si el componente se está usando en un layout mobile. */
|
|
8
|
+
mobile: boolean;
|
|
9
|
+
summaryOpen: boolean;
|
|
10
|
+
summaryStyles: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
supportsHover: boolean;
|
|
14
|
+
constructor(cartService: CartService);
|
|
15
|
+
/**
|
|
16
|
+
* Inicializa el modo de interacción según el dispositivo actual.
|
|
17
|
+
*
|
|
18
|
+
* @returns `void`
|
|
19
|
+
*/
|
|
20
|
+
ngOnInit(): void;
|
|
21
|
+
/** @returns `true` cuando el ítem tiene promociones unitarias informadas por backend. */
|
|
22
|
+
hasUnitPromotions: () => boolean;
|
|
23
|
+
/** @returns `true` cuando el popover/resumen está abierto. */
|
|
24
|
+
isSummaryOpen: () => boolean;
|
|
25
|
+
/** @returns El precio base histórico del ítem (`saleprice` si existe, si no `price`). */
|
|
26
|
+
getOriginalUnitPrice: () => number;
|
|
27
|
+
/** @returns La suma de los descuentos/promociones unitarios aplicados al ítem. */
|
|
28
|
+
getUnitPromotionTotal: () => number;
|
|
29
|
+
/** @returns El precio unitario final luego de aplicar promociones unitarias. */
|
|
30
|
+
getFinalUnitPrice: () => number;
|
|
31
|
+
/** @returns El precio principal que se renderiza junto al icono de ayuda. */
|
|
32
|
+
getDisplayedUnitPrice: () => number;
|
|
33
|
+
/** @returns Etiqueta del bloque final dentro del popover. */
|
|
34
|
+
getUnitPromotionFinalPriceLabel: () => string;
|
|
35
|
+
/** @returns Lista cruda de promociones unitarias a mostrar en el detalle. */
|
|
36
|
+
getUnitPromotions: () => any[];
|
|
37
|
+
/**
|
|
38
|
+
* Abre el popover al pasar el mouse en dispositivos con hover real.
|
|
39
|
+
*
|
|
40
|
+
* @param anchor Elemento usado como referencia visual del popover.
|
|
41
|
+
* @returns `void`
|
|
42
|
+
*/
|
|
43
|
+
handleMouseEnter: (anchor: HTMLElement) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Cierra el popover al salir con el mouse en desktop.
|
|
46
|
+
*
|
|
47
|
+
* @returns `void`
|
|
48
|
+
*/
|
|
49
|
+
handleMouseLeave: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Alterna la apertura del popover con click/tap en dispositivos sin hover.
|
|
52
|
+
*
|
|
53
|
+
* @param anchor Elemento usado como ancla para posicionar el detalle.
|
|
54
|
+
* @param event Evento del click/tap sobre el bloque de precio.
|
|
55
|
+
* @returns `void`
|
|
56
|
+
*/
|
|
57
|
+
handlePriceClick: (anchor: HTMLElement, event: Event) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Alterna manualmente el estado del resumen.
|
|
60
|
+
*
|
|
61
|
+
* @param anchor Elemento usado como ancla visual del popover.
|
|
62
|
+
* @param event Evento que dispara la interacción.
|
|
63
|
+
* @returns `void`
|
|
64
|
+
*/
|
|
65
|
+
toggleSummary: (anchor: HTMLElement, event: Event) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Cierra el popover y limpia los estilos calculados para mobile.
|
|
68
|
+
*
|
|
69
|
+
* @returns `void`
|
|
70
|
+
*/
|
|
71
|
+
closeSummary: () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Evita que un click dentro del popover se propague y lo cierre.
|
|
74
|
+
*
|
|
75
|
+
* @param event Evento del puntero.
|
|
76
|
+
* @returns `void`
|
|
77
|
+
*/
|
|
78
|
+
stopSummaryEvent: (event: Event) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Cierra el resumen cuando se hace click fuera del componente en desktop.
|
|
81
|
+
*
|
|
82
|
+
* @returns `void`
|
|
83
|
+
*/
|
|
84
|
+
handleDocumentClick(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Recalcula el modo de interacción al cambiar el viewport.
|
|
87
|
+
*
|
|
88
|
+
* @returns `void`
|
|
89
|
+
*/
|
|
90
|
+
handleWindowResize(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Cierra el resumen en mobile al hacer scroll para evitar que quede desacoplado del trigger.
|
|
93
|
+
*
|
|
94
|
+
* @returns `void`
|
|
95
|
+
*/
|
|
96
|
+
handleWindowScroll(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Abre el resumen y recalcula su posición.
|
|
99
|
+
*
|
|
100
|
+
* @param anchor Elemento de referencia para el posicionamiento.
|
|
101
|
+
* @returns `void`
|
|
102
|
+
*/
|
|
103
|
+
private openSummary;
|
|
104
|
+
/**
|
|
105
|
+
* Detecta si la interacción debe comportarse como desktop (`hover`) o mobile (`click`).
|
|
106
|
+
*
|
|
107
|
+
* @returns `void`
|
|
108
|
+
*/
|
|
109
|
+
private updateViewportMode;
|
|
110
|
+
/**
|
|
111
|
+
* Calcula estilos inline para que el resumen mobile quede dentro del viewport.
|
|
112
|
+
*
|
|
113
|
+
* @param anchor Elemento tocado por el usuario.
|
|
114
|
+
* @returns `void`
|
|
115
|
+
*/
|
|
116
|
+
private updateSummaryStyles;
|
|
117
|
+
}
|
|
@@ -1,8 +1,62 @@
|
|
|
1
1
|
import { Product } from './product';
|
|
2
|
+
/**
|
|
3
|
+
* Promoción aplicada a una unidad del producto.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* El backend nuevo informa estas promociones en `items[].unitPromotions`.
|
|
7
|
+
* Sus montos son negativos cuando representan descuentos.
|
|
8
|
+
*/
|
|
9
|
+
export interface CartItemPromotion {
|
|
10
|
+
/** Monto firmado aplicado sobre una unidad del producto. */
|
|
11
|
+
amount: number;
|
|
12
|
+
/** Tipo técnico de promoción informado por backend. */
|
|
13
|
+
type: string;
|
|
14
|
+
/** Nombre legible de la promoción o descuento. */
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Precios del ítem normalizados por el core para evitar duplicar lógica en cada frontend.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Esta estructura separa tres conceptos distintos:
|
|
22
|
+
* - `basePrice`: precio unitario histórico de la tabla (`saleprice` si existe, si no `price`)
|
|
23
|
+
* - `strikePrice`: precio tachado de la lógica legacy `price/saleprice`
|
|
24
|
+
* - `finalPrice`: precio unitario neto luego de aplicar `unitPromotions`
|
|
25
|
+
*/
|
|
26
|
+
export interface CartItemPricing {
|
|
27
|
+
/** Precio unitario base que ya usaba el frontend antes de soportar promociones unitarias. */
|
|
28
|
+
basePrice: number;
|
|
29
|
+
/** Precio unitario tachado, o `null` cuando no corresponde mostrarlo. */
|
|
30
|
+
strikePrice: number | null;
|
|
31
|
+
/** Precio unitario final luego de aplicar promociones por unidad. */
|
|
32
|
+
finalPrice: number;
|
|
33
|
+
/** Suma de todos los descuentos/promociones unitarios. */
|
|
34
|
+
unitPromotionTotal: number;
|
|
35
|
+
/** Indica si el ítem tiene precio tachado legacy. */
|
|
36
|
+
hasStrikePrice: boolean;
|
|
37
|
+
/** Indica si el ítem recibió promociones unitarias desde backend. */
|
|
38
|
+
hasUnitPromotions: boolean;
|
|
39
|
+
/** Porcentaje de descuento legacy a mostrar en badge (`price` vs `saleprice`). */
|
|
40
|
+
discountPercent: number;
|
|
41
|
+
/** Porcentaje efectivo usando como referencia el precio final unitario luego de promociones. */
|
|
42
|
+
effectiveDiscountPercent: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Ítem del carrito normalizado por el core.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Este contrato es el que consumen los componentes de carrito, sidebar y checkout.
|
|
49
|
+
* Se mantiene compatible con backends viejos: cuando no existe `unitPromotions`,
|
|
50
|
+
* el core completa `pricing` sin alterar la semántica legacy de `product.price`.
|
|
51
|
+
*/
|
|
2
52
|
export interface CartItem {
|
|
3
53
|
productCode: any;
|
|
4
54
|
product?: Product;
|
|
5
55
|
quantity: number;
|
|
6
56
|
variant_id: number;
|
|
7
57
|
total: number;
|
|
58
|
+
/** Promociones unitarias crudas devueltas por backend. */
|
|
59
|
+
unitPromotions?: CartItemPromotion[];
|
|
60
|
+
/** Precios derivados listos para usar en la UI. */
|
|
61
|
+
pricing?: CartItemPricing;
|
|
8
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Product } from '../interfaces/product';
|
|
2
|
-
import { CartItem } from '../interfaces/cart-item';
|
|
2
|
+
import { CartItem, CartItemPricing } from '../interfaces/cart-item';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
import { ConnectionService } from '../api/connection.service';
|
|
5
5
|
import { Constants } from '../core.consts';
|
|
@@ -75,9 +75,30 @@ export declare class CartService {
|
|
|
75
75
|
* CART CRUD SERVER'S SYNCRONIZED
|
|
76
76
|
*/
|
|
77
77
|
private initializeCart;
|
|
78
|
+
/**
|
|
79
|
+
* Reasigna `product.price` al precio base legacy que espera el template histórico del carrito.
|
|
80
|
+
*
|
|
81
|
+
* @param items Ítems normalizados del carrito.
|
|
82
|
+
* @returns Los mismos ítems con `product.price` alineado al precio base mostrado en la tabla.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Este método no modifica `pricing.finalPrice`. Solo preserva compatibilidad con templates
|
|
86
|
+
* viejos que todavía leen `item.product.price` directamente.
|
|
87
|
+
*/
|
|
78
88
|
private switchPriceInCartItem;
|
|
79
89
|
private stepCart;
|
|
80
90
|
private updateCartItems;
|
|
91
|
+
/**
|
|
92
|
+
* Sincroniza `cartItemsSubject` con la última respuesta del backend.
|
|
93
|
+
*
|
|
94
|
+
* @param cart Respuesta de carrito recibida desde cualquier endpoint que devuelva `items`.
|
|
95
|
+
* @returns `void`
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Se reutiliza después de actualizar cantidades, aplicar cupón o remover productos para evitar
|
|
99
|
+
* que la tabla quede con subtotales o promociones desactualizadas.
|
|
100
|
+
*/
|
|
101
|
+
private syncCartItemsFromResponse;
|
|
81
102
|
private updateCartItemQuantity;
|
|
82
103
|
private appendToCart;
|
|
83
104
|
private removeCartItem;
|
|
@@ -120,8 +141,47 @@ export declare class CartService {
|
|
|
120
141
|
getCountCartItems: () => Observable<number>;
|
|
121
142
|
getTaxesAmount: () => Observable<number>;
|
|
122
143
|
getSubTotalAmount: () => Observable<number>;
|
|
144
|
+
/**
|
|
145
|
+
* Devuelve el descuento que debe mostrarse en el resumen de compra.
|
|
146
|
+
*
|
|
147
|
+
* @returns Observable con el monto de promociones de orden.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* this.summaryPromotionAmount$ = this.cartService.getSummaryPromotionAmount();
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Si el backend nuevo informa `totals.promotionBreakdown.orderPromotions`, se usa ese valor.
|
|
156
|
+
* Si todavía no existe, el método hace fallback a `totals.promotion` para mantener compatibilidad.
|
|
157
|
+
*/
|
|
158
|
+
getSummaryPromotionAmount: () => Observable<number>;
|
|
159
|
+
/**
|
|
160
|
+
* Indica si existe un cupón aplicado en el carrito actual.
|
|
161
|
+
*
|
|
162
|
+
* @returns Observable booleano para controlar la visibilidad de `Quitar cupón`.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* No debe atarse a `getSummaryPromotionAmount()`, porque un cupón puede afectar
|
|
166
|
+
* solo promociones unitarias y dejar el descuento de orden en `0`.
|
|
167
|
+
*/
|
|
168
|
+
hasAppliedCoupon: () => Observable<boolean>;
|
|
123
169
|
toDecimal: (total: any) => any;
|
|
124
170
|
getDiscount(): Observable<number>;
|
|
171
|
+
/**
|
|
172
|
+
* Obtiene el precio normalizado de un ítem.
|
|
173
|
+
*
|
|
174
|
+
* @param item Ítem de carrito normalizado.
|
|
175
|
+
* @returns Objeto `CartItemPricing` listo para renderizar precio base, tachado y final.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const pricing = this.cartService.getItemPricing(item);
|
|
180
|
+
* const showTooltip = pricing.hasUnitPromotions;
|
|
181
|
+
* const finalPrice = pricing.finalPrice;
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
getItemPricing: (item: CartItem) => CartItemPricing;
|
|
125
185
|
addCoupon: (code: any) => Promise<any>;
|
|
126
186
|
removeCoupon: () => Promise<boolean>;
|
|
127
187
|
formatCoupon: (cart: any) => void;
|
|
@@ -132,7 +192,44 @@ export declare class CartService {
|
|
|
132
192
|
/**
|
|
133
193
|
* UTILS
|
|
134
194
|
*/
|
|
195
|
+
/**
|
|
196
|
+
* Transforma los ítems crudos del backend al contrato interno `CartItem`.
|
|
197
|
+
*
|
|
198
|
+
* @param server_item Respuesta `items` del endpoint de carrito.
|
|
199
|
+
* @returns Arreglo de ítems normalizados, cada uno con `pricing` precomputado.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* Este es el punto donde el core:
|
|
203
|
+
* - preserva `unitPromotions`
|
|
204
|
+
* - arma `pricing`
|
|
205
|
+
* - mantiene la forma histórica del item consumido por los templates
|
|
206
|
+
*/
|
|
135
207
|
transformItems: (server_item: any) => any;
|
|
208
|
+
/**
|
|
209
|
+
* Construye la normalización de precios para un ítem del carrito.
|
|
210
|
+
*
|
|
211
|
+
* @param item Ítem normalizado del carrito.
|
|
212
|
+
* @returns Estructura `CartItemPricing` con precio base, tachado, final y flags de UI.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const pricing = this.buildCartItemPricing(item);
|
|
217
|
+
* // pricing.basePrice => saleprice si existe, si no price
|
|
218
|
+
* // pricing.finalPrice => basePrice + unitPromotionTotal
|
|
219
|
+
* // pricing.effectiveDiscountPercent => % total contra el precio de referencia
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
private buildCartItemPricing;
|
|
223
|
+
/**
|
|
224
|
+
* Normaliza valores de precio provenientes del backend a `number`.
|
|
225
|
+
*
|
|
226
|
+
* @param value Valor numérico o string con formato local (`120.000`, `120000`, `120000-1`, etc.).
|
|
227
|
+
* @returns Número parseado o `NaN` si el valor no es utilizable.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Se usa para soportar respuestas con separadores de miles, coma decimal o rangos.
|
|
231
|
+
*/
|
|
232
|
+
private parsePriceValue;
|
|
136
233
|
getCreditAmount: () => Observable<number>;
|
|
137
234
|
getClientTaxes: () => Observable<number>;
|
|
138
235
|
getRemainingCredits: () => Observable<number>;
|
|
@@ -7,6 +7,64 @@ export declare class OrderUtilityService {
|
|
|
7
7
|
* @description Devuelve un listado con todas las promociones que posee el carro/orden
|
|
8
8
|
*/
|
|
9
9
|
getPromotions: (cart: any, forCart?: boolean) => CheckoutData[];
|
|
10
|
+
/**
|
|
11
|
+
* Construye el resumen de promociones que debe mostrarse en checkout y resúmenes de compra.
|
|
12
|
+
*
|
|
13
|
+
* @param cart Carrito u orden con estructura `totals` compatible.
|
|
14
|
+
* @param forCart Cuando es `true`, omite subtotal y total para devolver solo las líneas intermedias.
|
|
15
|
+
* @returns Lista de líneas normalizadas para renderizar el resumen.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* A diferencia de `getPromotions`, este método solo considera descuentos de orden.
|
|
19
|
+
*/
|
|
20
|
+
getSummaryPromotions: (cart: any, forCart?: boolean) => CheckoutData[];
|
|
21
|
+
/**
|
|
22
|
+
* Obtiene el monto de descuento que corresponde al resumen de la orden.
|
|
23
|
+
*
|
|
24
|
+
* @param cart Carrito u orden con `totals`.
|
|
25
|
+
* @returns Monto de promociones de orden.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const amount = this.orderUtils.getSummaryPromotionAmount(cart);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Si el backend nuevo informa `promotionBreakdown.orderPromotions`, ese valor tiene prioridad.
|
|
34
|
+
* Con backends viejos hace fallback a `totals.promotion` o `totals.discount`.
|
|
35
|
+
*/
|
|
36
|
+
getSummaryPromotionAmount: (cart: any) => number;
|
|
37
|
+
/**
|
|
38
|
+
* Indica si el backend ya informa el desglose nuevo de promociones.
|
|
39
|
+
*
|
|
40
|
+
* @param cart Carrito u orden con `totals`.
|
|
41
|
+
* @returns `true` cuando existe `promotionBreakdown.orderPromotions`.
|
|
42
|
+
*/
|
|
43
|
+
hasOrderPromotionsBreakdown: (cart: any) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Indica si el carrito tiene un cupón aplicado, independientemente de cómo impacte en el resumen.
|
|
46
|
+
*
|
|
47
|
+
* @param cart Carrito actual.
|
|
48
|
+
* @returns `true` cuando hay un código de cupón o una línea de descuento de tipo cupón.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Este helper evita atar la UI de `Quitar cupón` al monto de descuentos de orden.
|
|
52
|
+
* Un cupón puede afectar promociones unitarias y dejar `orderPromotions = 0`.
|
|
53
|
+
*/
|
|
54
|
+
hasAppliedCoupon: (cart: any) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Devuelve el monto efectivo de una línea de descuento/promoción.
|
|
57
|
+
*
|
|
58
|
+
* @param discount Línea cruda de descuento del backend.
|
|
59
|
+
* @param cart Carrito asociado.
|
|
60
|
+
* @returns Monto que debe mostrarse en UI.
|
|
61
|
+
*/
|
|
10
62
|
getAmount: (discount: any, cart: any) => number;
|
|
63
|
+
/**
|
|
64
|
+
* Homologa tipos crudos del backend al conjunto de tipos usado por checkout.
|
|
65
|
+
*
|
|
66
|
+
* @param type Tipo crudo (`order_promotion`, `order_coupon_promotion`, etc.).
|
|
67
|
+
* @returns Tipo normalizado consumido por los componentes del core.
|
|
68
|
+
*/
|
|
11
69
|
formatType: (type: string) => CheckoutDataType;
|
|
12
70
|
}
|