How can I get my code to save the changed quantity to the cart line? I cannot use SetCartLineQuantityOperation Request/Response pair. It wants to run the 105 operation. I have created a custom operation with ID 4002 which I added to the buttonsGrid in the Head Quarters.
When I click on my new button, it brings up the number dialog and I type in the quantity. then when it sees there is a multiple quantity, it brings up the rounding dialog. then it returns the value I selected for the rounding. however it doesn't want to save the quantity to the line.
****************
import { ExtensionOperationRequestType, ExtensionOperationRequestHandlerBase } from "PosApi/Create/Operations";
import TMCSetQtyOperationResponse from "./TMCSetQtyOperationResponse";
import TMCSetQtyOperationRequest from "./TMCSetQtyOperationRequest";
import { ClientEntities, ProxyEntities } from "PosApi/Entities";
import CartViewController from "../../CustomControlExtensions/Cart/CartViewDetailsController";
import { ObjectExtensions} from "PosApi/TypeExtensions";
import { MessageService } from "../../Controls/Dialogs/MessageBox/MessageBoxService";
import { StoreOperations } from "../../DataServices/DataServiceRequests.g";
import MultiplesListDialog from "../../Controls/Dialogs/MultiplesListDialog";
export default class TMCSetQtyOperationRequestHandler<TResponse extends TMCSetQtyOperationResponse> extends ExtensionOperationRequestHandlerBase<TResponse> {
private cart: ProxyEntities.Cart = null;
private cartLine: ProxyEntities.CartLine = null;
private enteredQty: number = 0;
/**
* Gets the supported request type.
* @return {RequestType<TResponse>} The supported request type.
*/
public supportedRequestType(): ExtensionOperationRequestType<TResponse> {
return TMCSetQtyOperationRequest;
}
public executeAsync(sqRequest: TMCSetQtyOperationRequest<TResponse>): Promise<ClientEntities.ICancelableDataResult<TResponse>> {
this.context.logger.logInformational("Log message from TMCSetQtyOperationRequestHandler executeAsync().", this.context.logger.getNewCorrelationId());
//Fetch Current cart
return this.getCurrentCart()
.then((): any => {
if (ObjectExtensions.isNullOrUndefined(this.cart)) { // return if cart not found
MessageService.ShowMessage(this, "Cart not found", "Current cart cannot be found. Cannot continue.");
return Promise.resolve(null);
}
if (ObjectExtensions.isNullOrUndefined(CartViewController.selectedCartLine)) {
return Promise.resolve(null);
}
this.cartLine = CartViewController.selectedCartLine;
return this.SetQtyRequest(sqRequest, this.cartLine.Quantity);
});
}
public getCurrentCart(): Promise<ProxyEntities.Cart> {
return this.context.runtime.executeAsync(new Commerce.GetCurrentCartClientRequest<Commerce.GetCurrentCartClientResponse>())
.then((getCurrentCartResponse: ClientEntities.ICancelableDataResult<Commerce.GetCurrentCartClientResponse>): Promise<ProxyEntities.Cart> => {
if (!(getCurrentCartResponse.canceled || ObjectExtensions.isNullOrUndefined(getCurrentCartResponse.data))) {
this.cart = getCurrentCartResponse.data.result;
return Promise.resolve(this.cart);
}
return Promise.resolve(null);
});
}
public SetQtyRequest(request: TMCSetQtyOperationRequest<TResponse>, _lineQty: number): Promise<ClientEntities.ICancelableDataResult<TResponse>> {
let dialogOptions: ClientEntities.Dialogs.INumericInputDialogOptions = {
title: this.context.resources.getString("tmc_1"),
subTitle: " ",
numPadLabel: this.context.resources.getString("tmc_2"),
defaultNumber: _lineQty.toString()
};
let showInputDialog: Commerce.ShowNumericInputDialogClientRequest<Commerce.ShowNumericInputDialogClientResponse> = new Commerce.ShowNumericInputDialogClientRequest(dialogOptions);
//return this.ExecuteAsync(showInputDialog)
return this.context.runtime.executeAsync(showInputDialog)
.then((showNumericDialogResult: ClientEntities.ICancelableDataResult<Commerce.ShowNumericInputDialogClientResponse>): any => {
this.enteredQty = parseFloat(showNumericDialogResult.data.result.value);
let mResponse: Promise<ClientEntities.ICancelableDataResult<StoreOperations.GetMultiplesActionResponse>>;
let multiRequest: StoreOperations.GetMultiplesActionRequest<StoreOperations.GetMultiplesActionResponse> =
new StoreOperations.GetMultiplesActionRequest(this.cartLine.ItemId, this.cartLine.UnitOfMeasureSymbol, this.cartLine.ProductId, this.enteredQty);
mResponse = this.context.runtime.executeAsync<StoreOperations.GetMultiplesActionResponse>(multiRequest);
return mResponse;
})
.then((response: ClientEntities.ICancelableDataResult<StoreOperations.GetMultiplesActionResponse>):
Promise<ClientEntities.ICancelableDataResult<number>> => {
let mqResult: Promise<ClientEntities.ICancelableDataResult<number>>;
if (response.data.result != null) {
var result = response.data.result;
var vMqty = result[0];
if (vMqty > 1) {
mqResult = MultiplesListDialog.show(this.context, result, this.enteredQty, this.cartLine.UnitOfMeasureSymbol);
}
}
return mqResult;
})
.then((dialogResult: ClientEntities.ICancelableDataResult<number>): Promise<ClientEntities.ICancelableDataResult<TResponse>> => {
if (!dialogResult.canceled) {
this.enteredQty = dialogResult.data;
}
this.cartLine.Quantity = this.enteredQty;
return Promise.resolve(<ClientEntities.ICancelableDataResult<TResponse>>{
canceled: false,
data: new TMCSetQtyOperationResponse(this.cart)
});
});
}
}
****************
When I step through the code I can see that cart that is passed in to TMCSetQtyOperationResponse, has my line and the quantity is that of what I added to the line. It just doesn't save it and I do not see an error in the event viewer.
I used "RetailSDK\POS\Extensions\SampleExtensions\Operations\SaveDataToSelectedCartLine" as an example. However in this example they assign extension properties to the cartLine. I do not want to update extension properties, I want to update the quantity.
Can anybody please look at my code and tell me what I'm missing.
Thank you.