SAP Spartacus 2211: Override OccCartAdapter to add extra params to /email query

SAP Spartacus 2211
I need to add 2 more params to the request that adds a guest customer to the backend. The endpoint is called addEmail:

addEmail: ‘users/${userId}/carts/${cartId}/email’

Which is already sending the email address as an http param on the body request.

What I did was:

  1. Override CheckoutLoginComponent with custom one to add my extra fields in the UI
  2. Created a DataService to store the extra parameters
  3. Override the function onSubmit on my CustomCheckoutLoginComponent, to set the extra fields values in the new DataService.
  4. Created a CustomOccCartAdapter that extends OccCartAdapter, and overrides the function “addEmail”, getting the extra fields from the injected DataService and adding them to the http request.

The problem is my CustomOccCartAdapter is not getting called, I tried several ways and can’t find the proper steps to override the OOTB OccCartAdapter.

This is my CustomCheckoutLoginComponent:

import { Component } from '@angular/core';
import {CheckoutLoginComponent} from "@spartacus/checkout/base/components";
import {UntypedFormBuilder, Validators} from "@angular/forms";
import {AuthRedirectService} from "@spartacus/core";
import {ActiveCartFacade} from "@spartacus/cart/base/root";
import {SfLoginStateService} from "../cart/sf-login-state-service";

@Component({
  selector: 'app-sf-checkout-login',
  templateUrl: './sf-checkout-login.component.html',
  styleUrl: './sf-checkout-login.component.scss'
})
export class CustomCheckoutLoginComponent extends CheckoutLoginComponent {

  constructor(
    protected override formBuilder: UntypedFormBuilder,
    protected override authRedirectService: AuthRedirectService,
    protected override activeCartFacade: ActiveCartFacade,
    private customLoginStateService: CustomLoginStateService
  ) {
    super(formBuilder, authRedirectService, activeCartFacade);
    this.extendForm();
  }

  private extendForm() {
    this.checkoutLoginForm.addControl('firstName', this.formBuilder.control('', Validators.required));
    this.checkoutLoginForm.addControl('lastName', this.formBuilder.control('', Validators.required));
    this.checkoutLoginForm.addControl('phone', this.formBuilder.control('', Validators.required));
  }

  override onSubmit() {
    if (this.checkoutLoginForm.valid) {

      const firstName = this.checkoutLoginForm.get('firstName')?.value;
      const lastName = this.checkoutLoginForm.get('lastName')?.value;
      const name = firstName + " " + lastName;
      const phone = this.checkoutLoginForm.get('phone')?.value;
      this.customLoginStateService.setData(name, phone);

      const email = this.checkoutLoginForm.get('email')?.value;
      this.activeCartFacade.addEmail(email);

      if (!this.sub) {
        this.sub = this.activeCartFacade.isGuestCart().subscribe((isGuest) => {
          if (isGuest) {
            this.authRedirectService.redirect();
          }
        });
      }
    } else {
      this.checkoutLoginForm.markAllAsTouched();
    }
  }

}

This is my custom adapter:

import {Injectable} from "@angular/core";
import {OccCartAdapter} from "@spartacus/cart/base/occ";
import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
import {ConverterService, InterceptorUtil, OccEndpointsService, USE_CLIENT_TOKEN} from "@spartacus/core";
import {SfLoginStateService} from "./sf-login-state-service";
import {Observable} from "rxjs";

@Injectable({
  providedIn: 'root'
})
export class CustomOccCartAdapter extends OccCartAdapter {
  constructor(
    protected override http: HttpClient,
    protected override occEndpointsService: OccEndpointsService,
    protected override converterService: ConverterService,
    private customLoginStateService: CustomLoginStateService
  ) {
    super(http, occEndpointsService, converterService);
  }

  override addEmail(userId: string, cartId: string, email: string): Observable<{}> {
    let headers = new HttpHeaders({
      'Content-Type': 'application/x-www-form-urlencoded',
    });
    headers = InterceptorUtil.createHeader(USE_CLIENT_TOKEN, true, headers);

    const customerData = this.customLoginStateService.getData();

    const httpParams: HttpParams = new HttpParams();
    httpParams.set('email', email);
    httpParams.set('name', customerData.name);
    httpParams.set('phone', customerData.phone);

    const url = this.occEndpointsService.buildUrl('addEmail', {
      urlParams: {
        userId,
        cartId,
      },
    });

    return this.http.put(url, httpParams, { headers });
  }
}

I tried doing this in my app.module.ts :

providers: [{
  provide: CartAdapter,
  useClass: CustomOccCartAdapter
}
...
]

But didn’t work, the OOTB adapter is still being called.

How to I get the OOTB OccCartAdapter effectively overriten by my CustomOccCartAdapter ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật