diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts index 777c1421..df5c7384 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts @@ -1115,11 +1115,11 @@ export class CreateProductSpecComponent implements OnInit { if(this.booleanCharSelected){ this.creatingChars=[ { - isDefault:true, + isDefault:false, value: true as any }, { - isDefault:false, + isDefault:true, value:false as any } ] diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts index 0cfb55ad..b99a0232 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts @@ -1329,11 +1329,11 @@ export class UpdateProductSpecComponent implements OnInit { if(this.booleanCharSelected){ this.creatingChars=[ { - isDefault:true, + isDefault:false, value: true as any }, { - isDefault:false, + isDefault:true, value:false as any } ] diff --git a/src/app/shared/characteristic/characteristic.component.html b/src/app/shared/characteristic/characteristic.component.html index cf1f5f00..231ae9d1 100644 --- a/src/app/shared/characteristic/characteristic.component.html +++ b/src/app/shared/characteristic/characteristic.component.html @@ -4,7 +4,7 @@

{{ characteristic.name }}

- + @if(!isDisabled){ @if (isSlider()){
@@ -32,6 +32,7 @@

{{ charact

} + } } @else {
diff --git a/src/app/shared/characteristic/characteristic.component.ts b/src/app/shared/characteristic/characteristic.component.ts index 4f06566d..0ed4214c 100644 --- a/src/app/shared/characteristic/characteristic.component.ts +++ b/src/app/shared/characteristic/characteristic.component.ts @@ -35,6 +35,8 @@ interface Characteristic { export class CharacteristicComponent implements OnInit { @Input() characteristic!: ProductSpecificationCharacteristic; @Input() readOnly: boolean = false; + @Input() isDisabled: boolean = false; + @Input() canBeDisabled: boolean = false; @Output() valueChange = new EventEmitter(); control = new FormControl(); diff --git a/src/app/shared/price-plan-drawer/price-plan-drawer.component.html b/src/app/shared/price-plan-drawer/price-plan-drawer.component.html index 7ef7edb2..f9f22af6 100644 --- a/src/app/shared/price-plan-drawer/price-plan-drawer.component.html +++ b/src/app/shared/price-plan-drawer/price-plan-drawer.component.html @@ -61,15 +61,33 @@
This price plan has an associate profile. That means that the following characteristics are already set for you.

@for (ch of filteredCharacteristics ; track ch.id) { + @if(!ch.name?.endsWith('- enabled')){ + } }
} @else if(filteredCharacteristics.length > 0) {

Please select the characteristics you need to suit this offer to you.

- @for (ch of filteredCharacteristics ; track ch.id) { - @if (!disabledCharacteristics.includes(ch.id)) { - + @for (ch of filteredCharacteristics ; track ch.id; let i = $index) { + @if(!ch.name?.endsWith('- enabled')){ +
+ @if(canBeDisabledChars.includes(ch.id)){ + + } +
+ + +
+
} }
diff --git a/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts b/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts index f477a399..e41576af 100644 --- a/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts +++ b/src/app/shared/price-plan-drawer/price-plan-drawer.component.ts @@ -65,6 +65,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { characteristics: ProductSpecificationCharacteristic[] = []; // Características dinámicas filteredCharacteristics: ProductSpecificationCharacteristic[] = []; disabledCharacteristics: any[] = []; + canBeDisabledChars: any[]=[]; @HostListener('document:keydown.escape', ['$event']) handleEscape(event: KeyboardEvent): void { @@ -231,15 +232,46 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { characteristicsGroup.addControl( characteristic.id, - this.fb.control(defaultValue || null, Validators.required) + this.fb.control(defaultValue ?? null, Validators.required) ); + if(!characteristic.name?.endsWith('- enabled') && this.filteredCharacteristics.some((char => char.name === characteristic.name+' - enabled'))){ + this.canBeDisabledChars.push(characteristic.id) + this.disabledCharacteristics.push(characteristic.id) + } } }); this.form.setControl('characteristics', characteristicsGroup); } - - + + onToggleChange(event: Event, charName: any): void { + const inputElement = event.target as HTMLInputElement; + const isChecked = inputElement.checked; + let char = this.filteredCharacteristics.find(char => char.name == charName+' - enabled') + const characteristicsGroup = this.form.get('characteristics') as FormGroup; + if(char && char.id) + characteristicsGroup.get(char.id)?.setValue(isChecked) + + const cleanName = char?.name?.replace(/- enabled$/, '').trim(); + const disabledChar = this.filteredCharacteristics.find( + item => item.name === cleanName + ); + //const isSelected = event.selectedValue === true || event.selectedValue === 'true'; + if (disabledChar) { + if (!isChecked) { + // Add it if it's not already in the array + if (!this.disabledCharacteristics.includes(disabledChar.id)) { + this.disabledCharacteristics.push(disabledChar.id); + } + } else { + // Remove it if it exists + this.disabledCharacteristics = this.disabledCharacteristics.filter( + id => id !== disabledChar.id + ); + } + } + this.calculatePrice(); + } // Handle price plan selection async onPricePlanSelected(pricePlan: any) { @@ -326,7 +358,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { const characteristicsGroup = this.form.get('characteristics') as FormGroup; characteristicsGroup.get(event.characteristicId)?.setValue(event.selectedValue); - let char = this.filteredCharacteristics.find(item => item.id === event.characteristicId); + /*let char = this.filteredCharacteristics.find(item => item.id === event.characteristicId); if (char?.name?.endsWith('- enabled')) { const cleanName = char.name.replace(/- enabled$/, '').trim(); const disabledChar = this.filteredCharacteristics.find( @@ -348,7 +380,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { } } } - console.log(char) + console.log(char)*/ this.calculatePrice(); } @@ -407,14 +439,19 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy { if(value==null && valueType=='number'){ value=0 } - - this.orderChars.push({ - "name": this.filteredCharacteristics[idx].name, - "value": value, - "valueType": valueType, - }) + + if(!this.filteredCharacteristics[idx].name?.endsWith('- enabled')){ + this.orderChars.push({ + "name": this.filteredCharacteristics[idx].name, + "value": value, + "valueType": valueType, + }) + } + } } + console.log('Calculating the price with...') + console.log(this.orderChars) } // Método para calcular el precio usando el servicio