Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-11818 feature lib for quick order #11856

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
11 changes: 11 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,11 @@
{
"$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "./public_api.ts",
"umdModuleIds": {
"@spartacus/core": "core",
"@ngrx/effects": "effects",
"@ngrx/store": "store"
}
}
}
6 changes: 6 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,6 @@
export * from './connectors/index';
export * from './events/index';
export * from './quick-order-core.module';
export * from './services/index';
export * from './store/actions/index';
export * from './store/quick-order-constants';
16 changes: 16 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,16 @@
import { ModuleWithProviders, NgModule } from '@angular/core';
import { QuickOrderConnector } from './connectors/quick-order.connector';
import { QuickOrderEventsModule } from './events/quick-order-events.module';
import { QuickOrderStoreModule } from './store/quick-order-store.module';

@NgModule({
imports: [QuickOrderStoreModule, 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() {}
}
3 changes: 3 additions & 0 deletions feature-libs/cart/quick-order/core/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as QuickOrderActions from './quick-order.action';

export { QuickOrderActions };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { StateUtils } from '@spartacus/core';

export class LoadSavedCart extends StateUtils.EntityLoadAction {}
5 changes: 5 additions & 0 deletions feature-libs/cart/quick-order/core/store/effects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { QuickOrderEffects } from './quick-order.effect';

export const effects: any[] = [QuickOrderEffects];

export * from './quick-order.effect';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable()
export class QuickOrderEffects {
constructor() {}
}
3 changes: 3 additions & 0 deletions feature-libs/cart/quick-order/core/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './actions/index';
export * from './effects/index';
export * from './quick-order-constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const QUICK_ORDER_LIST_PROCESS_ID = 'quick-order-list';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { effects } from './effects/index';

@NgModule({
imports: [EffectsModule.forFeature(effects)],
})
export class QuickOrderStoreModule {}
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';
Loading