Skip to content

Commit 7aa0f17

Browse files
authored
FIX QA tickets (#136)
* FIX ticket #831964 now unable to purchase if not billing address and checks if the billing address is valid * FIX Ticket#831455 categories’ filter in Services remains active in the background * FIX ticket #831764 order not does not visualize after checkout
1 parent b3598fe commit 7aa0f17

4 files changed

Lines changed: 82 additions & 35 deletions

File tree

src/app/pages/checkout/checkout.component.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ <h1 class="mb-4 pb-2 mt-4 text-4xl font-extrabold leading-none tracking-tight te
8282
</div>
8383
<div class="block">
8484
<div>
85-
<textarea id="large-input" name="orderNote"
85+
<textarea id="large-input" name="orderNote" [(ngModel)]="orderNote"
8686
class="flex w-full min-h-fit dark:text-white dark:bg-secondary-300 dark:border-secondary-200 dark:focus:border-primary-100 items-center rounded px-4 py-3 text-sm text-heading transition duration-300 ease-in-out focus:outline-0 focus:ring-0 border border-border-base focus:border-accent"
8787
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
8888
rows="4">
@@ -185,7 +185,17 @@ <h1 class="mb-4 pb-2 mt-4 text-4xl font-extrabold leading-none tracking-tight te
185185
class="text-sm text-body dark:text-gray-200">{{ 'SHOPPING_CART._calculated' | translate }}</span></div>
186186
</div>
187187
-->
188-
188+
@if(!validBillAddr){
189+
<div class="flex items-center p-4 text-sm text-primary-50" role="alert">
190+
<svg class="flex-shrink-0 inline w-4 h-4 me-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
191+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
192+
</svg>
193+
<span class="sr-only">Info</span>
194+
<p class="text-center">
195+
You need to create at least one valid billing address.
196+
</p>
197+
</div>
198+
}
189199
<button data-cy="checkout" class="inline-flex items-center justify-center shrink-0 font-semibold leading-none rounded outline-none transition duration-300 ease-in-out focus:outline-0 focus:shadow focus:ring-1 focus:ring-accent-700 bg-primary-50 dark:bg-primary-100 text-white border border-transparent hover:bg-secondary-100 dark:hover:bg-primary-50 px-5 py-0 h-12 mt-5 w-full"
190200
(click)="orderProduct()" [disabled]="items.length==0 || !this.validBillAddr" [ngClass]="(items.length==0 || !this.validBillAddr)? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'">
191201
{{ 'SHOPPING_CART._checkout' | translate }}

src/app/pages/checkout/checkout.component.ts

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class CheckoutComponent implements OnInit {
5151
showError: boolean = false;
5252
providerId:any = null;
5353
loadingItems:boolean=false;
54+
orderNote: string = '';
5455

5556
constructor(
5657
private localStorage: LocalStorageService,
@@ -66,15 +67,16 @@ export class CheckoutComponent implements OnInit {
6667
private route: ActivatedRoute) {
6768
// Bind the method to preserve context
6869
this.orderProduct = this.orderProduct.bind(this);
69-
this.eventMessage.messages$.subscribe(ev => {
70+
this.eventMessage.messages$.subscribe(async ev => {
7071
if (ev.type === 'BillAccChanged') {
7172
this.getBilling();
7273
}
7374
if (ev.value == true) {
7475
this.addBill = false;
7576
}
7677
if (ev.type === 'ChangedSession') {
77-
this.initCheckoutData();
78+
console.log('changing session...')
79+
await this.initCheckoutData();
7880
}
7981
if(ev.type === 'AddedCartItem') {
8082
this.loadingItems=true;
@@ -198,11 +200,11 @@ export class CheckoutComponent implements OnInit {
198200

199201
console.log('Productos creados:', products);
200202

201-
const productOrder = this.createProductOrder(products);
202-
console.log('--- order ---');
203-
console.log(productOrder);
204-
205203
try {
204+
const productOrder = this.createProductOrder(products);
205+
console.log('--- order ---');
206+
console.log(productOrder);
207+
206208
const response = await firstValueFrom(this.orderService.postProductOrder(productOrder));
207209
const redirectUrl = response.headers.get('X-Redirect-URL');
208210

@@ -254,22 +256,35 @@ export class CheckoutComponent implements OnInit {
254256
}
255257

256258
private createProductOrder(products: any[]) {
257-
return {
258-
productOrderItem: products,
259-
relatedParty: [
260-
{
261-
id: this.relatedParty,
262-
href: this.relatedParty,
263-
role: 'Customer'
264-
}
265-
],
266-
priority: '4',
267-
billingAccount: {
268-
id: this.selectedBillingAddress.id,
269-
href: this.selectedBillingAddress.id
270-
},
271-
notificationContact: this.selectedBillingAddress.email
272-
};
259+
260+
let po:any = {
261+
productOrderItem: products,
262+
relatedParty: [
263+
{
264+
id: this.relatedParty,
265+
href: this.relatedParty,
266+
role: 'Customer'
267+
}
268+
],
269+
priority: '4',
270+
billingAccount: {
271+
id: this.selectedBillingAddress.id,
272+
href: this.selectedBillingAddress.id
273+
},
274+
notificationContact: this.selectedBillingAddress.email
275+
};
276+
277+
if(this.orderNote!=''){
278+
const newNote = {
279+
text: this.orderNote,
280+
id: `urn:ngsi-ld:note:${uuidv4()}`,
281+
author: this.relatedParty,
282+
date: new Date().toISOString()
283+
};
284+
po['note']=[newNote]
285+
}
286+
287+
return po
273288
}
274289

275290
private async emptyShoppingCart() {
@@ -348,7 +363,7 @@ export class CheckoutComponent implements OnInit {
348363
}
349364
}
350365

351-
initCheckoutData() {
366+
async initCheckoutData() {
352367
this.providerId = this.route.snapshot.paramMap.get('id');
353368
let aux = this.localStorage.getObject('login_items') as LoginInfo;
354369
if (aux) {
@@ -365,7 +380,8 @@ export class CheckoutComponent implements OnInit {
365380
console.log('--- Login Info ---')
366381
console.log(aux)
367382

368-
this.cartService.getShoppingCart().then(async data => {
383+
let data = await this.cartService.getShoppingCart();
384+
//this.cartService.getShoppingCart().then(async data => {
369385
console.log('---CARRITO API---')
370386
console.log(data)
371387
this.items = data;
@@ -377,12 +393,12 @@ export class CheckoutComponent implements OnInit {
377393
this.cdr.detectChanges();
378394
this.getTotalPrice();
379395
console.log('------------------')
380-
})
396+
//})
381397
console.log('--- ITEMS ---')
382398
console.log(this.items)
383399

384400
this.loading_baddrs = true;
385-
this.getBilling();
401+
await this.getBilling();
386402
}
387403

388404
async getProviderInfo(){
@@ -405,10 +421,12 @@ export class CheckoutComponent implements OnInit {
405421
}
406422

407423

408-
getBilling() {
424+
async getBilling() {
425+
this.selectedBillingAddress=null;
409426
let isBillSelected = false;
410427
this.billingAddresses = [];
411-
this.account.getBillingAccount().then(data => {
428+
let data = await this.account.getBillingAccount();
429+
//this.account.getBillingAccount().then(data => {
412430
for (let i = 0; i < data.length; i++) {
413431
isBillSelected = false;
414432
let email = ''
@@ -455,17 +473,21 @@ export class CheckoutComponent implements OnInit {
455473
this.billingAddresses.push(baddr)
456474
if (isBillSelected) {
457475
this.selectedBillingAddress = baddr
476+
this.cdr.detectChanges();
458477
}
459478
}
460479
console.log('billing account...')
461480
console.log(this.billingAddresses)
481+
462482
this.loading_baddrs = false;
463483
if (this.billingAddresses.length > 0) {
464484
this.preferred = false;
465485
} else {
466486
this.preferred = true;
467487
}
468-
})
488+
//})
489+
this.validBillAddr = !!this.selectedBillingAddress?.id;
490+
this.cdr.detectChanges();
469491
}
470492

471493
async onSelected(baddr: billingAccountCart) {

src/app/pages/search-catalog/search-catalog.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef, HostListener } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, HostListener, OnDestroy } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { ApiServiceService } from 'src/app/services/product-service.service';
44
import { PriceServiceService } from 'src/app/services/price-service.service';
@@ -19,7 +19,7 @@ import * as moment from 'moment';
1919
templateUrl: './search-catalog.component.html',
2020
styleUrl: './search-catalog.component.css'
2121
})
22-
export class SearchCatalogComponent implements OnInit{
22+
export class SearchCatalogComponent implements OnInit, OnDestroy{
2323
constructor(
2424
private route: ActivatedRoute,
2525
private api: ApiServiceService,
@@ -136,6 +136,13 @@ export class SearchCatalogComponent implements OnInit{
136136
this.router.navigate([path]);
137137
}
138138

139+
ngOnDestroy(){
140+
let storedFilters = this.localStorage.getObject('selected_categories') as Category[] || [];
141+
for(let i=0;i<storedFilters.length;i++){
142+
this.localStorage.removeCategoryFilter(storedFilters[i]);
143+
this.eventMessage.emitRemovedFilter(storedFilters[i]);
144+
}
145+
}
139146

140147
async getProducts(next:boolean){
141148
let filters = this.localStorage.getObject('selected_categories') as Category[] || [];

src/app/pages/search/search.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ChangeDetectorRef, SimpleChanges, OnChanges, HostListener, AfterViewInit } from '@angular/core';
1+
import { Component, OnInit, ChangeDetectorRef, SimpleChanges, OnChanges, HostListener, AfterViewInit, OnDestroy } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import {CategoriesFilterComponent} from "../../shared/categories-filter/categories-filter.component";
44
import {components} from "../../models/product-catalog";
@@ -21,7 +21,7 @@ import * as moment from 'moment';
2121
templateUrl: './search.component.html',
2222
styleUrl: './search.component.css'
2323
})
24-
export class SearchComponent implements OnInit {
24+
export class SearchComponent implements OnInit, OnDestroy {
2525

2626
products: ProductOffering[]=[];
2727
nextProducts: ProductOffering[]=[];
@@ -159,6 +159,14 @@ export class SearchComponent implements OnInit {
159159
}
160160
}
161161

162+
ngOnDestroy(){
163+
let storedFilters = this.localStorage.getObject('selected_categories') as Category[] || [];
164+
for(let i=0;i<storedFilters.length;i++){
165+
this.localStorage.removeCategoryFilter(storedFilters[i]);
166+
this.eventMessage.emitRemovedFilter(storedFilters[i]);
167+
}
168+
}
169+
162170
async getProducts(next:boolean){
163171
let filters = this.localStorage.getObject('selected_categories') as Category[] || [];
164172
if(next==false){

0 commit comments

Comments
 (0)