feat(cart): implement cart editing policy with granular permissions

This commit is contained in:
2026-08-19 10:16:06 -03:00
parent 8659708e1a
commit 2d0664a7c7
13 changed files with 185 additions and 32 deletions

View File

@@ -53,9 +53,11 @@ export class CartComponent {
readonly total = input<number>(0);
readonly backgroundColor = input<string>('#ffffff');
readonly readonly = input<boolean>(false);
readonly editable = input<boolean>(true);
readonly allowEditing = input<boolean>(false);
readonly allowRemove = input<boolean>(true);
readonly allowUpdateQuantity = input<boolean>(true);
readonly allowModify = input<boolean>(true);
readonly requireEditingMode = input<boolean>(false);
readonly allowUpdateVariant = input<boolean>(true);
readonly allowDelete = input<boolean>(true);
readonly persistQuantityChanges = input<boolean>(true);
readonly editingDisabled = input<boolean>(false);
readonly editing = model<boolean>(false);
@@ -125,7 +127,7 @@ export class CartComponent {
}
protected onItemQuantityChange(index: number, newQuantity: number): void {
if (!this.editable()) {
if (!this.allowUpdateQuantity()) {
return;
}
@@ -170,6 +172,8 @@ export class CartComponent {
}
protected onItemVariantChange(index: number, variantId: number): void {
if (this.readonly() || !this.allowUpdateVariant() || this.editingDisabled()) return;
const item = this.items()[index];
const cartItemId = item?.cartItemId;
@@ -200,6 +204,8 @@ export class CartComponent {
}
protected onItemRemove(index: number): void {
if (this.readonly() || !this.allowDelete() || this.editingDisabled()) return;
const target = this.resolveRemoveTarget(index);
if (!target) {
@@ -225,7 +231,7 @@ export class CartComponent {
protected readonly formattedTotal = computed(() => this.formatCurrency(this.total()));
protected toggleEditing(): void {
if (!this.editable() || this.editingDisabled()) {
if (!this.allowModify() || this.editingDisabled()) {
return;
}