feat(catalog): replace stock_tecnico with maximum_addable_quantity across components and services
This commit is contained in:
@@ -11,13 +11,21 @@
|
||||
@if (!hasVariants()) {
|
||||
<div class="product-vertical-with-cart-card__summary">
|
||||
<span class="product-vertical-with-cart-card__price">{{ formattedPrice() }}</span>
|
||||
<app-quantity-selector [(quantity)]="quantity" />
|
||||
<app-quantity-selector
|
||||
[(quantity)]="quantity"
|
||||
[max]="effectiveMaximum()"
|
||||
[disabled]="unavailable()"
|
||||
/>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="product-vertical-with-cart-card__variants">
|
||||
<div class="product-vertical-with-cart-card__summary">
|
||||
<span class="product-vertical-with-cart-card__price">{{ formattedPrice() }}</span>
|
||||
<app-quantity-selector [(quantity)]="quantity" />
|
||||
<app-quantity-selector
|
||||
[(quantity)]="quantity"
|
||||
[max]="effectiveMaximum()"
|
||||
[disabled]="unavailable()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="product-vertical-with-cart-card__variant-selectors">
|
||||
@@ -29,14 +37,14 @@
|
||||
<div class="product-vertical-with-cart-card__actions">
|
||||
<app-button
|
||||
variant="primary"
|
||||
[disabled]="hasVariants() && selectedVariant() === null"
|
||||
[disabled]="unavailable() || (hasVariants() && selectedVariant() === null)"
|
||||
(click)="onBuy()"
|
||||
>
|
||||
Comprar
|
||||
</app-button>
|
||||
<app-button
|
||||
variant="secondary"
|
||||
[disabled]="saving() || (hasVariants() && selectedVariant() === null)"
|
||||
[disabled]="saving() || unavailable() || (hasVariants() && selectedVariant() === null)"
|
||||
(click)="onAddToCart()"
|
||||
>
|
||||
{{ saving() ? 'Guardando' : 'Agregar al carrito' }}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, input, model, output } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
computed,
|
||||
effect,
|
||||
input,
|
||||
model,
|
||||
output,
|
||||
} from '@angular/core';
|
||||
|
||||
import { ButtonComponent } from '../button/button.component';
|
||||
import { QuantitySelectorComponent } from '../quantity-selector/quantity-selector.component';
|
||||
@@ -10,6 +18,7 @@ import {
|
||||
export interface VerticalCartVariant extends VariantSelectorVariant {
|
||||
descripcion?: string | null;
|
||||
precio?: string | number;
|
||||
maximum_addable_quantity?: number | null;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -23,6 +32,7 @@ export class ProductVerticalWithCartCardComponent {
|
||||
readonly title = input<string>('');
|
||||
readonly description = input<string>('');
|
||||
readonly price = input<number>(0);
|
||||
readonly maximumAddableQuantity = input<number | null>(null);
|
||||
readonly variants = input<VerticalCartVariant[]>([]);
|
||||
readonly saving = input(false);
|
||||
|
||||
@@ -45,9 +55,23 @@ export class ProductVerticalWithCartCardComponent {
|
||||
});
|
||||
protected readonly formattedPrice = computed(() => this.formatCurrency(this.effectivePrice()));
|
||||
protected readonly hasVariants = computed(() => this.variants().length > 0);
|
||||
protected readonly effectiveMaximum = computed(
|
||||
() => this.selectedVariantData()?.maximum_addable_quantity ?? this.maximumAddableQuantity(),
|
||||
);
|
||||
protected readonly unavailable = computed(() => this.effectiveMaximum() === 0);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const maximum = this.effectiveMaximum();
|
||||
|
||||
if (maximum !== null && maximum > 0 && this.quantity() > maximum) {
|
||||
this.quantity.set(maximum);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected onAddToCart(): void {
|
||||
if (this.saving()) {
|
||||
if (this.saving() || this.unavailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,6 +79,8 @@ export class ProductVerticalWithCartCardComponent {
|
||||
}
|
||||
|
||||
protected onBuy(): void {
|
||||
if (this.unavailable()) return;
|
||||
|
||||
this.buy.emit({ quantity: this.quantity(), variant: this.selectedVariant() });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user