How to use @spartacus/core - 10 common examples

To help you get started, we’ve selected a few @spartacus/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-components / checkout / components / shipping-address / address-form / address-form.component.ts View on Github external
this.checkoutDeliveryService.clearAddressVerificationResults();
        } else if (results.decision === 'ACCEPT') {
          this.submitAddress.emit(this.address.value);
        } else if (results.decision === 'REJECT') {
          // TODO: Workaround: allow server for decide is titleCode mandatory (if yes, provide personalized message)
          if (
            results.errors.errors.some(error => error.subject === 'titleCode')
          ) {
            this.globalMessageService.add(
              { key: 'addressForm.titleRequired' },
              GlobalMessageType.MSG_TYPE_ERROR
            );
          } else {
            this.globalMessageService.add(
              { key: 'addressForm.invalidAddress' },
              GlobalMessageType.MSG_TYPE_ERROR
            );
          }
          this.checkoutDeliveryService.clearAddressVerificationResults();
        } else if (results.decision === 'REVIEW') {
          this.openSuggestedAddress(results);
        }
      });
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / lib / checkout / components / multi-step-checkout / shipping-address / address-form / address-form.component.ts View on Github external
.subscribe((results: AddressValidation) => {
        if (results === 'FAIL') {
          this.checkoutService.clearAddressVerificationResults();
        } else if (results.decision === 'ACCEPT') {
          this.submitAddress.emit(this.address.value);
        } else if (results.decision === 'REJECT') {
          // TODO: Workaround: allow server for decide is titleCode mandatory (if yes, provide personalized message)
          if (
            results.errors.errors.some(error => error.subject === 'titleCode')
          ) {
            this.globalMessageService.add({
              type: GlobalMessageType.MSG_TYPE_ERROR,
              text: 'Title is required',
            });
          } else {
            this.globalMessageService.add({
              type: GlobalMessageType.MSG_TYPE_ERROR,
              text: 'Invalid Address',
            });
          }
          this.checkoutService.clearAddressVerificationResults();
        } else if (results.decision === 'REVIEW') {
          this.openSuggestedAddress(results);
        }
      });
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / lib / cms / cms.module.ts View on Github external
CmsConfig,
  CmsModule as CmsCoreModule,
  defaultCmsModuleConfig,
} from '@spartacus/core';

// guards
import { guards } from './guards/index';

import { OutletModule } from '../outlet/outlet.module';
import { OutletDirective } from '../outlet/outlet.directive';

@NgModule({
  imports: [
    CommonModule,
    HttpClientModule,
    ConfigModule.withConfig(defaultCmsModuleConfig),
    OutletModule,
    CmsCoreModule,
  ],
  providers: [...guards, { provide: CmsConfig, useExisting: Config }],
  declarations: [],
  exports: [OutletDirective],
})
export class CmsModule {}
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / lib / ui / pages / pages.module.ts View on Github external
PageLayoutModule,
} from '../../../cms-structure/page/index';
import { CartPageModule } from './cart-page/cart-page.module';
import { OrderConfirmationPageModule } from './order-confirmation-page/order-confirmation-page.module';
import { ProductPageModule } from './product-page/product-page.module';
import { defaultRoutingConfig } from './default-routing-config';

const pageModules = [
  CartPageModule,
  OrderConfirmationPageModule,
  ProductPageModule,
];

@NgModule({
  imports: [
    ConfigModule.withConfig(defaultRoutingConfig),
    CommonModule,
    ...pageModules,
    PageLayoutModule,
    RouterModule.forChild([
      {
        // This route can be dropped only when we have a mapping path to page label for content pages
        path: null,
        canActivate: [CmsPageGuard],
        component: PageLayoutComponent,
        data: { pageLabel: 'homepage', cxRoute: 'home' },
      },
      {
        path: null,
        canActivate: [LogoutGuard],
        component: PageLayoutComponent,
        data: { cxRoute: 'logout' },
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-components / myaccount / consent-management / components / consent-management.component.spec.ts View on Github external
it('should reset the processing state and display a success message', () => {
          spyOn(userService, 'resetWithdrawConsentProcessState').and.stub();
          spyOn(globalMessageService, 'add').and.stub();

          component[onConsentWithdrawnSuccessMethod](true);

          expect(
            userService.resetWithdrawConsentProcessState
          ).toHaveBeenCalled();
          expect(globalMessageService.add).toHaveBeenCalledWith(
            { key: 'consentManagementForm.message.success.withdrawn' },
            GlobalMessageType.MSG_TYPE_CONFIRMATION
          );
        });
      });
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-components / myaccount / update-profile / update-profile.component.spec.ts View on Github external
it('should add a global message and navigate to a url ', () => {
        spyOn(globalMessageService, 'add').and.stub();
        spyOn(routingService, 'go').and.stub();

        component.onSuccess(true);
        expect(globalMessageService.add).toHaveBeenCalledWith(
          { key: 'updateProfileForm.profileUpdateSuccess' },
          GlobalMessageType.MSG_TYPE_CONFIRMATION
        );
        expect(routingService.go).toHaveBeenCalledWith({ cxRoute: 'home' });
      });
    });
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-structure / pwa / services / add-to-home-screen.service.spec.ts View on Github external
it('should disableAddToHomeScreen after appinstalled is fired', () => {
    spyOn(addToHomeService, 'disableAddToHomeScreen').and.stub();

    const event = new Event('appinstalled');
    winRef.nativeWindow.dispatchEvent(event);
    expect(addToHomeService.disableAddToHomeScreen).toHaveBeenCalled();
    expect(globalMessageService.add).toHaveBeenCalledWith(
      { key: 'pwa.addedToHomeScreen' },
      GlobalMessageType.MSG_TYPE_CONFIRMATION
    );
  });
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-components / myaccount / my-coupons / coupon-claim / coupon-claim.component.spec.ts View on Github external
it('should be able to add global message', () => {
    userService.getClaimCustomerCouponResultSuccess.and.returnValue(of(true));
    routingService.getRouterState.and.returnValue(of(mockRouterState));
    routingService.go.and.stub();
    fixture.detectChanges();
    expect(globalMessageService.add).toHaveBeenCalledWith(
      { key: 'myCoupons.claimCustomerCoupon' },
      GlobalMessageType.MSG_TYPE_CONFIRMATION
    );
    expect(routingService.go).toHaveBeenCalledWith('/my-account/coupons');
  });
});
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / cms-components / myaccount / order / cancellations-returns / cancel-or-return.service.spec.ts View on Github external
it('should add global message and redirect to order history page after cancel success', () => {
    service.cancelSuccess('1');
    expect(service.clearCancelOrReturnRequestInputs).toHaveBeenCalled();
    expect(userOrderService.resetCancelOrderProcessState).toHaveBeenCalled();
    expect(routingService.go).toHaveBeenCalledWith({
      cxRoute: 'orders',
    });
    expect(messageService.add).toHaveBeenCalledWith(
      {
        key: 'orderDetails.cancellationAndReturn.cancelSuccess',
        params: { orderCode: '1' },
      },
      GlobalMessageType.MSG_TYPE_CONFIRMATION
    );
  });
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / global-message / http-interceptors / http-error.interceptor.spec.ts View on Github external
it(`should catch 502 of error`, inject([HttpClient], (http: HttpClient) => {
    http
      .get('/test')
      .pipe(catchError((error: any) => throwError(error)))
      .subscribe(_result => {}, error => (this.error = error));

    const mockReq = httpMock.expectOne(req => {
      return req.method === 'GET';
    });

    mockReq.flush({}, { status: 502, statusText: 'Bad Gateway' });
    expect(mockMessageService.add).toHaveBeenCalledWith({
      type: GlobalMessageType.MSG_TYPE_ERROR,
      text: 'A server error occurred. Please try again later.'
    });
  }));