Skip to content

Commit

Permalink
Merge branch 'develop' into epic/opf
Browse files Browse the repository at this point in the history
  • Loading branch information
Matejk00 authored Jul 11, 2024
2 parents 57d4484 + 166522a commit c2c95da
Show file tree
Hide file tree
Showing 66 changed files with 493 additions and 157 deletions.
1 change: 1 addition & 0 deletions core-libs/setup/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
"../../integration-libs/cdp/customer-ticketing/public_api"
],
"@spartacus/cdp": ["../../integration-libs/cdp/public_api"],
"@spartacus/cds/assets": ["../../integration-libs/cds/assets/public_api"],
"@spartacus/cds": ["../../integration-libs/cds/public_api"],
"@spartacus/digital-payments/assets": [
"../../integration-libs/digital-payments/assets/public_api"
Expand Down
1 change: 1 addition & 0 deletions feature-libs/asm/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
"../../integration-libs/cdp/customer-ticketing/public_api"
],
"@spartacus/cdp": ["../../integration-libs/cdp/public_api"],
"@spartacus/cds/assets": ["../../integration-libs/cds/assets/public_api"],
"@spartacus/cds": ["../../integration-libs/cds/public_api"],
"@spartacus/digital-payments/assets": [
"../../integration-libs/digital-payments/assets/public_api"
Expand Down
32 changes: 0 additions & 32 deletions feature-libs/cart/base/occ/adapters/default-occ-cart-config.ts

This file was deleted.

24 changes: 20 additions & 4 deletions feature-libs/cart/base/occ/adapters/occ-cart.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
*/

import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { CartAdapter } from '@spartacus/cart/base/core';
import {
CART_NORMALIZER,
Cart,
CART_NORMALIZER,
SaveCartResult,
} from '@spartacus/cart/base/root';
import {
ConverterService,
FeatureConfigService,
InterceptorUtil,
Occ,
OCC_CART_ID_CURRENT,
OCC_USER_ID_ANONYMOUS,
Occ,
OccEndpointsService,
USE_CLIENT_TOKEN,
} from '@spartacus/core';
Expand All @@ -26,6 +27,8 @@ import { map } from 'rxjs/operators';

@Injectable()
export class OccCartAdapter implements CartAdapter {
private featureConfigService = inject(FeatureConfigService);

constructor(
protected http: HttpClient,
protected occEndpointsService: OccEndpointsService,
Expand Down Expand Up @@ -113,7 +116,20 @@ export class OccCartAdapter implements CartAdapter {
saveCartDescription,
},
});
return this.http.patch<Occ.Cart>(endpoint, cartId).pipe(

let httpParams: HttpParams = new HttpParams();

if (
this.featureConfigService?.isEnabled(
'occCartNameAndDescriptionInHttpRequestBody'
)
) {
httpParams = httpParams
.set('saveCartName', saveCartName)
.set('saveCartDescription', saveCartDescription);
}

return this.http.patch<Occ.Cart>(endpoint, httpParams).pipe(
map((cartResponse) => (cartResponse as SaveCartResult).savedCartData),
this.converterService.pipeable(CART_NORMALIZER)
);
Expand Down
6 changes: 3 additions & 3 deletions feature-libs/cart/base/occ/cart-base-occ.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import {
CART_NORMALIZER,
ORDER_ENTRY_PROMOTIONS_NORMALIZER,
} from '@spartacus/cart/base/root';
import { provideDefaultConfig } from '@spartacus/core';
import { provideDefaultConfigFactory } from '@spartacus/core';
import { OccCartNormalizer } from './adapters/converters/occ-cart-normalizer';
import { OrderEntryPromotionsNormalizer } from './adapters/converters/order-entry-promotions-normalizer';
import { defaultOccCartConfig } from './adapters/default-occ-cart-config';
import { OccCartEntryAdapter } from './adapters/occ-cart-entry.adapter';
import { OccCartValidationAdapter } from './adapters/occ-cart-validation.adapter';
import { OccCartVoucherAdapter } from './adapters/occ-cart-voucher.adapter';
import { OccCartAdapter } from './adapters/occ-cart.adapter';
import { defaultOccCartConfigFactory } from './config/default-occ-cart-config-factory';

@NgModule({
imports: [CommonModule],
providers: [
provideDefaultConfig(defaultOccCartConfig),
provideDefaultConfigFactory(defaultOccCartConfigFactory),
{
provide: CartAdapter,
useClass: OccCartAdapter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { FeatureToggles, OccConfig } from '@spartacus/core';
import { inject } from '@angular/core';

export function defaultOccCartConfigFactory(): OccConfig {
const featureToggles = inject(FeatureToggles);

return {
backend: {
occ: {
endpoints: {
/* eslint-disable max-len */
carts:
'users/${userId}/carts?fields=carts(DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user,saveTime,name,description)',
cart: 'users/${userId}/carts/${cartId}?fields=DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user,saveTime,name,description',
createCart:
'users/${userId}/carts?fields=DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),user',
addEntries: 'users/${userId}/carts/${cartId}/entries',
updateEntries:
'users/${userId}/carts/${cartId}/entries/${entryNumber}',
removeEntries:
'users/${userId}/carts/${cartId}/entries/${entryNumber}',
addEmail: 'users/${userId}/carts/${cartId}/email',
deleteCart: 'users/${userId}/carts/${cartId}',
cartVoucher: 'users/${userId}/carts/${cartId}/vouchers',
saveCart: featureToggles.occCartNameAndDescriptionInHttpRequestBody
? '/users/${userId}/carts/${cartId}/save'
: '/users/${userId}/carts/${cartId}/save?saveCartName=${saveCartName}&saveCartDescription=${saveCartDescription}',
validate: 'users/${userId}/carts/${cartId}/validate?fields=DEFAULT',
/* eslint-enable */
},
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,34 @@ <h2>
</div>

<ng-container *ngIf="savedCarts?.length > 0; else noSavedCarts">
<table class="table cx-saved-cart-list-table">
<thead class="cx-saved-cart-list-thead-mobile">
<th scope="col">
<table role="table" class="table cx-saved-cart-list-table">
<thead role="row" class="cx-saved-cart-list-thead-mobile">
<th role="columnheader" scope="col">
{{ 'savedCartList.cartName' | cxTranslate }}
</th>
<th scope="col">{{ 'savedCartList.cartId' | cxTranslate }}</th>
<th scope="col">{{ 'savedCartList.dateSaved' | cxTranslate }}</th>
<th scope="col" class="cx-saved-cart-list-th-qty">
<th role="columnheader" scope="col">
{{ 'savedCartList.cartId' | cxTranslate }}
</th>
<th role="columnheader" scope="col">
{{ 'savedCartList.dateSaved' | cxTranslate }}
</th>
<th role="columnheader" scope="col" class="cx-saved-cart-list-th-qty">
{{ 'savedCartList.quantity' | cxTranslate }}
</th>
<th scope="col" class="cx-saved-cart-list-th-total">
<th
role="columnheader"
scope="col"
class="cx-saved-cart-list-th-total"
>
{{ 'savedCartList.total' | cxTranslate }}
</th>
<th scope="col">
<th role="columnheader" scope="col">
{{ 'savedCartList.actions' | cxTranslate }}
</th>
</thead>
<tbody>
<tr
role="row"
*ngFor="let savedCart of savedCarts"
(click)="goToSavedCartDetails(savedCart)"
>
Expand Down
38 changes: 27 additions & 11 deletions feature-libs/cart/saved-cart/occ/adapters/occ-saved-cart.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import {
Cart,
CART_NORMALIZER,
SaveCartResult,
} from '@spartacus/cart/base/root';
import { SavedCartAdapter } from '@spartacus/cart/saved-cart/core';
import { ConverterService, Occ, OccEndpointsService } from '@spartacus/core';
import {
ConverterService,
FeatureConfigService,
Occ,
OccEndpointsService,
} from '@spartacus/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable()
export class OccSavedCartAdapter implements SavedCartAdapter {
private featureConfigService = inject(FeatureConfigService);

constructor(
protected http: HttpClient,
protected occEndpoints: OccEndpointsService,
Expand Down Expand Up @@ -56,15 +63,24 @@ export class OccSavedCartAdapter implements SavedCartAdapter {
cartId: string,
saveCartName: string
): Observable<Cart> {
return this.http
.post<Occ.Cart>(
this.getCloneSavedCartEndpoint(userId, cartId, saveCartName),
cartId
let httpParams: HttpParams = new HttpParams();
if (
this.featureConfigService?.isEnabled(
'occCartNameAndDescriptionInHttpRequestBody'
)
.pipe(
map((cartResponse) => (cartResponse as SaveCartResult).savedCartData),
this.converter.pipeable(CART_NORMALIZER)
);
) {
httpParams = httpParams.set('name', saveCartName);
}
const endpoint = this.getCloneSavedCartEndpoint(
userId,
cartId,
saveCartName
);

return this.http.post<Occ.Cart>(endpoint, httpParams).pipe(
map((cartResponse) => (cartResponse as SaveCartResult).savedCartData),
this.converter.pipeable(CART_NORMALIZER)
);
}

protected getSavedCartEndpoint(userId: string, cartId: string): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { FeatureToggles, OccConfig } from '@spartacus/core';
import { inject } from '@angular/core';

export function defaultOccSavedCartConfigFactory(): OccConfig {
const featureToggles = inject(FeatureToggles);

return {
backend: {
occ: {
endpoints: {
savedCarts:
'/users/${userId}/carts?savedCartsOnly=true&fields=carts(DEFAULT,potentialProductPromotions,appliedProductPromotions,potentialOrderPromotions,appliedOrderPromotions,entries(totalPrice(formattedValue),product(images(FULL),stock(FULL)),basePrice(formattedValue,value),updateable),totalPrice(formattedValue),totalItems,totalPriceWithTax(formattedValue),totalDiscounts(value,formattedValue),subTotal(formattedValue),totalUnitCount,deliveryItemsQuantity,deliveryCost(formattedValue),totalTax(formattedValue, value),pickupItemsQuantity,net,appliedVouchers,productDiscounts(formattedValue),saveTime,user,name,description)',
savedCart: '/users/${userId}/carts/${cartId}/savedcart',
restoreSavedCart: '/users/${userId}/carts/${cartId}/restoresavedcart',
cloneSavedCart:
featureToggles.occCartNameAndDescriptionInHttpRequestBody
? '/users/${userId}/carts/${cartId}/clonesavedcart'
: '/users/${userId}/carts/${cartId}/clonesavedcart?name=${saveCartName}',
},
},
},
};
}

This file was deleted.

6 changes: 3 additions & 3 deletions feature-libs/cart/saved-cart/occ/saved-cart-occ.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { SavedCartAdapter } from '@spartacus/cart/saved-cart/core';
import { provideDefaultConfig } from '@spartacus/core';
import { provideDefaultConfigFactory } from '@spartacus/core';
import { OccSavedCartAdapter } from './adapters/occ-saved-cart.adapter';
import { defaultOccSavedCartConfig } from './config/default-occ-saved-cart-config';
import { defaultOccSavedCartConfigFactory } from './config/default-occ-saved-cart-config-factory';

@NgModule({
imports: [CommonModule],
providers: [
provideDefaultConfig(defaultOccSavedCartConfig),
provideDefaultConfigFactory(defaultOccSavedCartConfigFactory),
{
provide: SavedCartAdapter,
useClass: OccSavedCartAdapter,
Expand Down
1 change: 1 addition & 0 deletions feature-libs/cart/tsconfig.schematics.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
"../../integration-libs/cdp/customer-ticketing/public_api"
],
"@spartacus/cdp": ["../../integration-libs/cdp/public_api"],
"@spartacus/cds/assets": ["../../integration-libs/cds/assets/public_api"],
"@spartacus/cds": ["../../integration-libs/cds/public_api"],
"@spartacus/digital-payments/assets": [
"../../integration-libs/digital-payments/assets/public_api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
} from '@spartacus/storefront';
import { MockFeatureDirective } from 'projects/storefrontlib/shared/test/mock-feature-directive';
import { EMPTY, Observable, of } from 'rxjs';
import { CheckoutBillingAddressFormService } from '../../checkout-billing-address';
import { CheckoutPaymentFormComponent } from './checkout-payment-form.component';
import createSpy = jasmine.createSpy;
import { CheckoutBillingAddressFormService } from '../../checkout-billing-address';

@Component({
selector: 'cx-spinner',
Expand Down Expand Up @@ -531,6 +531,12 @@ describe('CheckoutPaymentFormComponent', () => {
fixture.debugElement.queryAll(By.css('.form-check-input')).length
).toEqual(1);
});

it('should show assitive message when form is submitted with errors', () => {
component.paymentForm.setErrors({ required: true });
component.next();
expect(mockGlobalMessageService.add).toHaveBeenCalled();
});
});

describe('UI close/back button', () => {
Expand Down
Loading

0 comments on commit c2c95da

Please sign in to comment.