feat(cart): implement cart editing policy with granular permissions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user