Skip to content

Commit

Permalink
feat: Added basic structure for new feature lib for quick order (#11818)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydome authored Apr 8, 2021
1 parent da8ea4f commit 9e7f95f
Show file tree
Hide file tree
Showing 56 changed files with 619 additions and 27 deletions.
1 change: 1 addition & 0 deletions feature-libs/cart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Cart can be added to the existing Spartacus application by running `ng add @spar
The Spartacus Cart library contains the following packages:

- `@spartacus/cart/saved-cart` is a package that adds the saved cart feature.
- `@spartacus/cart/quick-order` is a package that adds the quick order feature.

For more information about Spartacus, see [Spartacus](https://github.com/SAP/spartacus).
1 change: 1 addition & 0 deletions feature-libs/cart/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
}

@import './saved-cart/index';
@import './quick-order/index';
3 changes: 2 additions & 1 deletion feature-libs/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"cart",
"shopping",
"shop",
"saved cart"
"saved cart",
"quick order"
],
"homepage": "https://github.com/SAP/spartacus",
"repository": "https://github.com/SAP/spartacus/tree/develop/feature-libs/cart",
Expand Down
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './styles/index';
6 changes: 6 additions & 0 deletions feature-libs/cart/quick-order/assets/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts"
}
}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/assets/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './translations/translations';
5 changes: 5 additions & 0 deletions feature-libs/cart/quick-order/assets/translations/en/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { quickOrder } from './quick-order.i18n';

export const en = {
quickOrder,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const quickOrderForm = {};

export const quickOrderList = {};

export const quickOrder = {
quickOrderForm,
quickOrderList,
};
11 changes: 11 additions & 0 deletions feature-libs/cart/quick-order/assets/translations/translations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TranslationChunksConfig, TranslationResources } from '@spartacus/core';
import { en } from './en/index';

export const quickOrderTranslations: TranslationResources = {
en,
};

// expose all translation chunk mapping for quickOrder feature
export const quickOrderTranslationChunksConfig: TranslationChunksConfig = {
quickOrder: ['quickOrderForm', 'quickOrderList'],
};
2 changes: 2 additions & 0 deletions feature-libs/cart/quick-order/components/list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './quick-order-list.component';
export * from './quick-order-list.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Quick Order List Component
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { QuickOrderListComponent } from './quick-order-list.component';

describe('QuickOrderListComponent', () => {
let component: QuickOrderListComponent;
let fixture: ComponentFixture<QuickOrderListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [QuickOrderListComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(QuickOrderListComponent);
component = fixture.componentInstance;
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'cx-quick-order-list',
templateUrl: './quick-order-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class QuickOrderListComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { AuthGuard, CmsConfig, provideDefaultConfig } from '@spartacus/core';
import { QuickOrderListComponent } from './quick-order-list.component';

@NgModule({
imports: [CommonModule],
providers: [
provideDefaultConfig(<CmsConfig>{
cmsComponents: {
AccountQuickOrderComponent: {
component: QuickOrderListComponent,
guards: [AuthGuard],
},
},
}),
],
declarations: [QuickOrderListComponent],
exports: [QuickOrderListComponent],
entryComponents: [QuickOrderListComponent],
})
export class QuickOrderListModule {}
10 changes: 10 additions & 0 deletions feature-libs/cart/quick-order/components/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core",
"@spartacus/storefront": "storefront"
}
}
}
2 changes: 2 additions & 0 deletions feature-libs/cart/quick-order/components/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './list/index';
export * from './quick-order-components.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

@NgModule({
imports: [RouterModule],
})
export class QuickOrderComponentsModule {}
2 changes: 2 additions & 0 deletions feature-libs/cart/quick-order/core/connectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './quick-order.adapter';
export * from './quick-order.connector';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { OrderEntry } from '@spartacus/core';
import { Observable } from 'rxjs';

export abstract class QuickOrderAdapter {
/**
*
* Abstract method used to add items to active cart
*/
abstract addToCart(
userId: string,
cartId: string,
entries: OrderEntry[]
): Observable<void>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { OrderEntry } from '@spartacus/core';
import { Observable } from 'rxjs';
import { QuickOrderAdapter } from './quick-order.adapter';

@Injectable({
providedIn: 'root',
})
export class QuickOrderConnector {
constructor(protected adapter: QuickOrderAdapter) {}

addToCart(
userId: string,
cartId: string,
entries: OrderEntry[]
): Observable<void> {
return this.adapter.addToCart(userId, cartId, entries);
}
}
3 changes: 3 additions & 0 deletions feature-libs/cart/quick-order/core/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './quick-order-event.builder';
export * from './quick-order-events.module';
export * from './quick-order.events';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class QuickOrderEventBuilder {
constructor() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { QuickOrderEventBuilder } from './quick-order-event.builder';

@NgModule({})
export class QuickOrderEventsModule {
constructor(_quickOrderEventBuilder: QuickOrderEventBuilder) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export abstract class QuickOrderEvent {}
9 changes: 9 additions & 0 deletions feature-libs/cart/quick-order/core/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core"
}
}
}
4 changes: 4 additions & 0 deletions feature-libs/cart/quick-order/core/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './connectors/index';
export * from './events/index';
export * from './quick-order-core.module';
export * from './services/index';
15 changes: 15 additions & 0 deletions feature-libs/cart/quick-order/core/quick-order-core.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ModuleWithProviders, NgModule } from '@angular/core';
import { QuickOrderConnector } from './connectors/quick-order.connector';
import { QuickOrderEventsModule } from './events/quick-order-events.module';

@NgModule({
imports: [QuickOrderEventsModule],
})
export class QuickOrderCoreModule {
static forRoot(): ModuleWithProviders<QuickOrderCoreModule> {
return {
ngModule: QuickOrderCoreModule,
providers: [QuickOrderConnector],
};
}
}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/core/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './quick-order.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class QuickOrderService {
constructor() {}
}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './quick-order.module';
10 changes: 10 additions & 0 deletions feature-libs/cart/quick-order/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core",
"@spartacus/storefront": "storefront"
}
}
}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/occ/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './occ-quick-order.adapter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { QuickOrderAdapter } from '@spartacus/cart/quick-order/core';
import {
ConverterService,
OccEndpointsService,
OrderEntry,
} from '@spartacus/core';
import { Observable } from 'rxjs';

@Injectable()
export class OccQuickOrderAdapter implements QuickOrderAdapter {
constructor(
protected http: HttpClient,
protected occEndpoints: OccEndpointsService,
protected converter: ConverterService
) {}

addToCart(
userId: string,
cartId: string,
entries: OrderEntry[]
): Observable<any> {
return this.http.patch<any>(
this.getQuickOrderEndpoint(userId, cartId, entries),
cartId
);
}

protected getQuickOrderEndpoint(
userId: string,
cartId: string,
entries: OrderEntry[]
): string {
return this.occEndpoints.getUrl('addToCart', {
userId,
cartId,
entries,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { OccConfig } from '@spartacus/core';

export const defaultOccQuickOrderConfig: OccConfig = {
backend: {
occ: {
endpoints: {
addToCart: 'orgUsers/${userId}/carts/${cartId}/entries',
},
},
},
};
2 changes: 2 additions & 0 deletions feature-libs/cart/quick-order/occ/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Imported for side effects (module augmentation)
import './occ-quick-order-endpoints.model';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OccEndpoint } from '@spartacus/core';

declare module '@spartacus/core' {
interface OccEndpoints {
/**
* Endpoint to add items to cart active
*
* * @member {string}
*/
addToCart?: string | OccEndpoint;
}
}
9 changes: 9 additions & 0 deletions feature-libs/cart/quick-order/occ/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core"
}
}
}
3 changes: 3 additions & 0 deletions feature-libs/cart/quick-order/occ/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './adapters/index';
export * from './model/index';
export * from './quick-order-occ.module';
18 changes: 18 additions & 0 deletions feature-libs/cart/quick-order/occ/quick-order-occ.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { provideDefaultConfig } from '@spartacus/core';
import { QuickOrderAdapter } from '@spartacus/cart/quick-order/core';
import { OccQuickOrderAdapter } from './adapters/occ-quick-order.adapter';
import { defaultOccQuickOrderConfig } from './config/default-occ-quick-order-config';

@NgModule({
imports: [CommonModule],
providers: [
provideDefaultConfig(defaultOccQuickOrderConfig),
{
provide: QuickOrderAdapter,
useClass: OccQuickOrderAdapter,
},
],
})
export class QuickOrderOccModule {}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './index';
13 changes: 13 additions & 0 deletions feature-libs/cart/quick-order/quick-order.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { QuickOrderComponentsModule } from '@spartacus/cart/quick-order/components';
import { QuickOrderCoreModule } from '@spartacus/cart/quick-order/core';
import { QuickOrderOccModule } from '@spartacus/cart/quick-order/occ';

@NgModule({
imports: [
QuickOrderCoreModule.forRoot(),
QuickOrderOccModule,
QuickOrderComponentsModule,
],
})
export class QuickOrderModule {}
10 changes: 10 additions & 0 deletions feature-libs/cart/quick-order/root/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core",
"@spartacus/storefront": "storefront"
}
}
}
1 change: 1 addition & 0 deletions feature-libs/cart/quick-order/root/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './quick-order-root.module';
Loading

0 comments on commit 9e7f95f

Please sign in to comment.