function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vanitha ManiVanitha Mani 

Tyescript and API

I have one question on how to proceed with my code. It's a commerce cloud headless implementation. If retail parameter is true the product shouldnt be removed and if it is false it should follow existing removing logic

one.ts

/** Basket parameters */
export interface BasketModelParams extends ModelParams {
  basketId?: string,
retail?: boolean,
}

two.ts

class BasketModel extends BaseModel<Checkout.ShopperBaskets.Basket, BasketModelParams> {
  /** Customized params for Basket model */
  get params(): BasketModelParams {
    return {
      // Use ID from loaded basket data, or from original params if basket is not yet loaded
      basketId: (this._data.basketId || this._params.basketId) as string | undefined,
    };
  }

async validateBasket(): Promise<void> {
    // TODO: check basket status, whether or not is possible to remove items.
    if (!this._data.productItems) {
      return;
    }
    const basketItems = this._data.productItems;
    await this.load({ variants: { product: true } });
    const variants = _.flatten((this.included.variants || [])
      .map((v) => _.get(v, [ `data`, `variants` ])))
      .reduce((acc, cur) => ({...acc, ...(cur ? {[cur.productId]: cur} : false) }), {});

    for (const item of basketItems) {
      if (!!item.productId && !_.get(variants, [ item.productId, `orderable` ], true)) {
        await this.removeProductItem(item);
      }
    }
  }

here i need to add retail parameter logic in validate basket method

orderapicontroller.ts

type OrdersApiControllerParams = BasketModelParams & OrderModelParams & BasketModelUpdateParams & {
  adyenNotification: [{ NotificationRequestItem: CasperNotificationRequestItem }],
  couponCode?: string,
retail,
  paymentAttributes?: RequestPaymentAttributes,
}
 // Return all possible parameters needed for orders controller actions
return {
      basketId: this._commerceClient?.shopperBasketId,
      orderNo: orderNo as string | undefined,
      checkoutState,
      couponCode: couponCode as string | undefined,
      email,
      holdForArrivalDate,
      marketingOptIn,
      productItems,
      shippingAddress,
      billingAddress,
      paymentAttributes,
      retail:retail === 'true',
      siteId,
      shippingMethodsForProductItems,
      adyenNotification,
      sendTextMessageAlerts,
      textMessageNumber,
      signatureRequired,
    };

Can anyone help how to implement this logic
#Trailhead  #Automation  #Integration