
Hi All,
I have a requirement to apply a gender based discount like line discount. I have created a button in the POS. On the select of this i am able to get the whole cart details instead of the selected cart line.
By using this below code I am able to get the whole cart details
let cartRequest: CartOperations.GetCurrentCartClientRequest<CartOperations.GetCurrentCartClientResponse> =
new CartOperations.GetCurrentCartClientRequest();
// Get cart first and then find the first available cartline which does not have any discounts applied.
return context.runtime.executeAsync(cartRequest)
.then((result: ClientEntities.ICancelableDataResult<CartOperations.GetCurrentCartClientResponse>): void => {
if (!result.canceled) {
cart = result.data.result;
}
}).then((): CancelableDiscountRequest => {
if (ObjectExtensions.isNullOrUndefined(cart)) {
return <CancelableDiscountRequest>{
canceled: true,
data: null
};
}
Can you please guide me how to get the selected line from the cart?
Hi, you can create an extension of CartView controller - to catch selected lines, save them into global variable - and use this selection in your code. Sample is below (ExtendedSessionInformation.instance in Singleton)
export default class CartViewController extends CartView.CartExtensionViewControllerBase {
public _selectedCartLines: ProxyEntities.CartLine[];
constructor(context: IExtensionCartViewControllerContext) {
super(context);
this.cartLineSelectedHandler = (data: CartView.CartLineSelectedData): void => {
this._selectedCartLines = data.cartLines;
ExtendedSessionInformation.instance.selectedCartLines = data.cartLines;
};
this.cartLineSelectionClearedHandler = (): void => {
this._selectedCartLines = undefined;
ExtendedSessionInformation.instance.selectedCartLines = [];
};
}
}