Skip to content

Commit

Permalink
punchout improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
shauke committed Mar 29, 2021
1 parent 7fcf720 commit e5863ba
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
34 changes: 21 additions & 13 deletions src/app/extensions/punchout/pages/punchout/punchout-page.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { AccountFacade } from 'ish-core/facades/account.facade';
import { AppFacade } from 'ish-core/facades/app.facade';
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { CookiesService } from 'ish-core/utils/cookies/cookies.service';
import { log } from 'ish-core/utils/dev/operators';
import { whenTruthy } from 'ish-core/utils/operators';

import { PunchoutService } from '../../services/punchout/punchout.service';
Expand All @@ -26,9 +25,17 @@ export class PunchoutPageGuard implements CanActivate {
) {}

canActivate(route: ActivatedRouteSnapshot) {
// check for an 'sid' (cXML) or 'HOOK_URL' (OCI) before doing anything with the punchout route
if (!(route.queryParamMap.has('sid') || route.queryParamMap.has('HOOK_URL'))) {
this.appFacade.setBusinessError('punchout.error.missing.hook_url_sid');
// check for required start parameters before doing anything with the punchout route
// 'sid', 'access-token' (cXML) or 'HOOK_URL', 'USERNAME', 'PASSWORD' (OCI)
if (
!(
(route.queryParamMap.has('sid') && route.queryParamMap.has('access-token')) ||
(route.queryParamMap.has('HOOK_URL') &&
route.queryParamMap.has('USERNAME') &&
route.queryParamMap.has('PASSWORD'))
)
) {
this.appFacade.setBusinessError('punchout.error.missing.parameters');
return false;
}

Expand Down Expand Up @@ -64,18 +71,19 @@ export class PunchoutPageGuard implements CanActivate {
switchMap(() => {
// handle cXML punchout with sid
if (route.queryParamMap.get('sid')) {
this.cookiesService.put('punchoutSID', route.queryParamMap.get('sid'), { sameSite: 'Strict' });

// tslint:disable-next-line: no-console
console.log('STARTING cXML PUNCHOUT with sid:', route.queryParamMap.get('sid'));

// fetch sid session information (basketId, returnURL, operation, ...)
// TODO: if session error (error page) -> Logout and remove Cookies?
return this.punchoutService.getCxmlPunchoutSession(route.queryParamMap.get('sid')).pipe(
log('session data'),
// persist returnURL in a cookie for later cart transfer (TODO: should survive page reload)
tap(data => this.cookiesService.put('punchoutReturnURL', data.returnURL, { sameSite: 'Strict' })),
tap(data => this.cookiesService.put('punchoutBasketID', data.basketId, { sameSite: 'Strict' })),
// log(`STARTING cXML PUNCHOUT with sid: ${route.queryParamMap.get('sid')}`),
// persist cXML session information in cookie for later cart transfer (TODO: should survive page reload)
// persist basket and sid as well to survive page reload?
tap(data => {
this.cookiesService.put('punchoutReturnURL', data.returnURL, { sameSite: 'Strict' });
this.cookiesService.put('punchoutBasketID', data.basketId, { sameSite: 'Strict' });
this.cookiesService.put('punchoutSID', route.queryParamMap.get('sid'), { sameSite: 'Strict' });
}),
// use the basketId basket for the current PWA session (instead of default current basket)
// TODO: if load basket error (currently no error page) -> Logout and remove Cookies? (do not use default 'current' basket)
tap(data => this.checkoutFacade.loadBasketWithId(data.basketId)),
mapTo(this.router.parseUrl('/home'))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class PunchoutService {
* @param form The prepared HTML form to submit the punchout data.
* @param submit Controls whether the HTML form is actually submitted (default) or not (only created in the document body).
*/
submitPunchoutForm(form: HTMLFormElement, submit = true) {
private submitPunchoutForm(form: HTMLFormElement, submit = true) {
if (!form) {
return throwError('submitPunchoutForm() of the punchout service called without a form');
}
Expand Down Expand Up @@ -173,7 +173,7 @@ export class PunchoutService {
/**
* transferCxmlPunchoutBasket
*/
transferCxmlPunchoutBasket() {
private transferCxmlPunchoutBasket() {
const punchoutSID = this.cookiesService.get('punchoutSID');
if (!punchoutSID) {
return throwError('no punchoutSID available in cookies for cXML punchout basket transfer');
Expand Down Expand Up @@ -209,7 +209,7 @@ export class PunchoutService {
* @param browserFormPostUrl
* @returns The cXML punchout form
*/
createCxmlPunchoutForm(punchOutOrderMessage: string, browserFormPostUrl: string): HTMLFormElement {
private createCxmlPunchoutForm(punchOutOrderMessage: string, browserFormPostUrl: string): HTMLFormElement {
const cXmlForm = document.createElement('form');
cXmlForm.method = 'post';
cXmlForm.action = browserFormPostUrl;
Expand All @@ -224,7 +224,7 @@ export class PunchoutService {

// OCI PUNCHOUT SHOPPING FUNCTIONALITY

transferOciPunchoutBasket() {
private transferOciPunchoutBasket() {
return this.store.pipe(
select(getCurrentBasketId),
filter(basketId => !!basketId),
Expand All @@ -236,7 +236,7 @@ export class PunchoutService {
* Gets a JSON object with the necessary OCI punchout data for the basket transfer.
* @param basketId The basket id for the punchout.
*/
getOciPunchoutBasketData(basketId: string): Observable<Attribute<string>[]> {
private getOciPunchoutBasketData(basketId: string): Observable<Attribute<string>[]> {
if (!basketId) {
return throwError('getOciPunchoutBasketData() of the punchout service called without basketId');
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@
"promotion.detailslink.label": "Aktionsdetails",
"promotion.detailslink.text": "Details",
"promotion.removelink.text": "Entfernen",
"punchout.error.missing.hook_url_sid": "Fehler beim Verbinden zum Punchout-Katalog. Der Parameter 'HOOK_URL' oder 'sid' fehlt.",
"punchout.error.missing.parameters": "Fehler beim Verbinden zum Punchout-Katalog. Benötigte Start-Parameter fehlen.",
"punchout.login_already_exists.error": "Der angegebene Anmeldename wird bereits verwendet. Prüfen Sie bitte die Richtigkeit der Eingabe oder geben Sie einen anderen Anmeldenamen an.",
"quickorder.page.add.cart": "In den Warenkorb",
"quickorder.page.add.row": "Weitere Zeilen hinzufügen",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@
"promotion.detailslink.label": "Promotion Details",
"promotion.detailslink.text": "Details",
"promotion.removelink.text": "Remove",
"punchout.error.missing.hook_url_sid": "Error connecting to punchout catalog. Either the parameter 'HOOK_URL' or 'sid' is missing.",
"punchout.error.missing.parameters": "Error connecting to the punchout catalog. Required start parameters are missing.",
"punchout.login_already_exists.error": "A punchout user with that user name already exists. Please check the information for accuracy or enter a different name.",
"quickorder.page.add.cart": "Add to Cart",
"quickorder.page.add.row": "Add more rows",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@
"promotion.detailslink.label": "Détails de promotion",
"promotion.detailslink.text": "Détails",
"promotion.removelink.text": "Supprimer",
"punchout.error.missing.hook_url_sid": "Erreur de connexion au catalogue punchout. Le paramètre 'HOOK_URL' or 'sid' est manquant.",
"punchout.error.missing.parameters": "Erreur de connexion au catalogue punchout. Le paramètre ... est manquant.",
"punchout.login_already_exists.error": "Un utilisateur avec ce nom d’utilisateur existe déjà. Veuillez vérifier l’exactitude des informations ou entrer un nom d’utilisateur différent.",
"quickorder.page.add.cart": "Ajouter au panier",
"quickorder.page.add.row": "Ajouter lignes supplémentaires",
Expand Down

0 comments on commit e5863ba

Please sign in to comment.