private static void LoadItemInfo(ProcessMaskSegmentsServiceRequest serviceRequest, Barcode barcode, int position, BarcodeMaskSegment segment) { if (barcode.ItemBarcode != null && !string.IsNullOrWhiteSpace(barcode.ItemBarcode.ItemId)) { // Skip item barcode lookup if it is already set. return; } string barcodeText = serviceRequest.Barcode.BarcodeId.Substring(0, position + segment.Length); barcodeText += '%'; GetProductBarcodeDataRequest dataRequest = new GetProductBarcodeDataRequest(barcodeText); ItemBarcode itemBarcode = serviceRequest.RequestContext.Runtime.Execute <GetProductBarcodeDataResponse>(dataRequest, serviceRequest.RequestContext).Barcode; if (itemBarcode == null) { barcodeText = barcodeText.Substring(0, barcodeText.Length - 1); barcodeText += Convert.ToString(CalculateCheckDigit(barcodeText), CultureInfo.CurrentCulture); dataRequest = new GetProductBarcodeDataRequest(barcodeText); itemBarcode = serviceRequest.RequestContext.Runtime.Execute <GetProductBarcodeDataResponse>(dataRequest, serviceRequest.RequestContext).Barcode; } if (itemBarcode != null) { barcode.ItemBarcode = itemBarcode; barcode.Mask.MaskType = BarcodeMaskType.Item; } }
private static ItemBarcode GetItemBarcode(RequestContext context, string barcodeId) { GetProductBarcodeDataRequest productBarcodeRequest = new GetProductBarcodeDataRequest(barcodeId); GetProductBarcodeDataResponse productBarcodeResponse = context.Execute <GetProductBarcodeDataResponse>(productBarcodeRequest); return(productBarcodeResponse.Barcode); }
/// <summary> /// Executes the workflow for a get price check for a product. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override PriceCheckResponse Process(PriceCheckRequest request) { ThrowIf.Null(request, "request"); ItemBarcode itemBarcode = null; if (string.IsNullOrEmpty(request.Barcode) && string.IsNullOrEmpty(request.ItemId)) { throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ItemIdBarcodeMissing, "Either an item identifier or barcode is required."); } if (string.IsNullOrEmpty(request.ItemId)) { GetProductBarcodeDataRequest dataRequest = new GetProductBarcodeDataRequest(request.Barcode); itemBarcode = this.Context.Runtime.Execute <GetProductBarcodeDataResponse>(dataRequest, this.Context).Barcode; } SalesTransaction salesTransaction = new SalesTransaction() { Id = Guid.NewGuid().ToString(), CustomerId = request.CustomerAccountNumber, }; SalesLine salesLine = new SalesLine() { ItemId = request.ItemId, InventoryDimensionId = request.InventoryDimensionId ?? itemBarcode.InventoryDimensionId, SalesOrderUnitOfMeasure = request.UnitOfMeasureSymbol ?? itemBarcode.UnitId, Quantity = 1m, LineId = Guid.NewGuid().ToString() }; salesTransaction.SalesLines.Add(salesLine); GetIndependentPriceDiscountServiceRequest priceRequest = new GetIndependentPriceDiscountServiceRequest(salesTransaction); GetPriceServiceResponse pricingServiceResponse = this.Context.Execute <GetPriceServiceResponse>(priceRequest); SalesLine resultLine = pricingServiceResponse.Transaction.SalesLines[0]; ProductPrice productPrice = GetProductPrice( resultLine.ItemId, resultLine.InventoryDimensionId, resultLine.BasePrice, resultLine.TotalAmount, this.Context.GetChannelConfiguration().Currency); var productPrices = new List <ProductPrice> { productPrice }; return(new PriceCheckResponse(productPrices.AsPagedResult())); }
private static GetProductBarcodeDataResponse GetProductBarcodeData(GetProductBarcodeDataRequest request) { string barcode = request.Barcode; RequestContext context = request.RequestContext; ThrowIf.Null(barcode, "barcode"); ThrowIf.Null(context, "context"); ColumnSet columns = request.QueryResultSettings != null ? request.QueryResultSettings.ColumnSet : new ColumnSet(); ItemL2CacheDataStoreAccessor level2CacheDataAccessor = GetCacheAccessor(request.RequestContext); bool found; bool updateL2Cache; ItemBarcode result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetItemsByBarcode(barcode, columns), out found, out updateL2Cache); if (!found) { var query = new SqlPagedQuery(QueryResultSettings.AllRecords) { Select = columns, From = BarcodesViewName, Where = string.Format("{0} LIKE {1} AND {2} = {3}", ItemBarcodeColumnName, ItemBarcodeVariableName, DataAreaIdColumnName, DataAreaIdVariableName), }; query.Parameters[ItemBarcodeVariableName] = barcode; query.Parameters[DataAreaIdVariableName] = context.GetChannelConfiguration().InventLocationDataAreaId; IEnumerable <ItemBarcode> itemBarcodes; using (DatabaseContext databaseContext = new DatabaseContext(context)) { itemBarcodes = databaseContext.ReadEntity <ItemBarcode>(query).Results; } // If the barcode matches with more than one variant, then we should set the variant details to null/ empty. // When this scenario occurs, the client should pop up new dialog to get the variant details. if (itemBarcodes.Count() > 1) { ItemBarcode itemBarcode = itemBarcodes.FirstOrDefault(); if (itemBarcode != null) { itemBarcode.SetVariantDetailsToEmpty(); result = itemBarcode; } } else { using (DatabaseContext databaseContext = new DatabaseContext(context)) { result = databaseContext.ReadEntity <ItemBarcode>(query).SingleOrDefault(); } } updateL2Cache &= result != null; } if (updateL2Cache) { level2CacheDataAccessor.PutItemsByBarcode(barcode, columns, result); } return(new GetProductBarcodeDataResponse(result)); }
/// <summary> /// Executes the workflow for a get nearby stores with availability. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetStoreProductAvailabilityResponse Process(GetStoreProductAvailabilityRequest request) { ThrowIf.Null(request, "request"); string variantId = request.VariantId; if (request.Items == null || !request.Items.Any()) { if (string.IsNullOrWhiteSpace(request.ItemId) && string.IsNullOrWhiteSpace(request.Barcode)) { throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ItemIdBarcodeMissing, "Please specify either an item id or a barcode."); } List <string> itemIds = new List <string>(1); if (!string.IsNullOrWhiteSpace(request.Barcode)) { GetProductBarcodeDataRequest dataRequest = new GetProductBarcodeDataRequest(request.Barcode) { QueryResultSettings = new QueryResultSettings(new ColumnSet("ITEMID"), PagingInfo.AllRecords) }; ItemBarcode itemBarcode = this.Context.Runtime.Execute <GetProductBarcodeDataResponse>(dataRequest, this.Context).Barcode; if (itemBarcode == null) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_BarcodeNotFound, string.Format("The specified barcode ({0}) was not found.", request.Barcode)); } itemIds.Add(itemBarcode.ItemId); variantId = itemBarcode.VariantId; } else { itemIds.Add(request.ItemId); } var getItemsRequest = new GetItemsDataRequest(itemIds) { QueryResultSettings = new QueryResultSettings(new ColumnSet("INVENTUNITID"), PagingInfo.AllRecords) }; var getItemsResponse = request.RequestContext.Runtime.Execute <GetItemsDataResponse>(getItemsRequest, request.RequestContext); ReadOnlyCollection <Item> items = getItemsResponse.Items; if (items == null || items.Count == 0) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, string.Format("No items were found for the specified item identifiers ({0}).", string.Join(", ", itemIds))); } if (items.Count > 1) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_DuplicateObject, string.Format("More than one item was found for the specified item identifiers ({0}).", string.Join(", ", itemIds))); } var getStoresRequest = new GetStoresDataRequest(this.Context.GetPrincipal().ChannelId, request.SearchArea, QueryResultSettings.AllRecords); ReadOnlyCollection <OrgUnitLocation> storeLocations = this.Context.Execute <EntityDataServiceResponse <OrgUnitLocation> >(getStoresRequest).PagedEntityCollection.Results; var productAvailabilityRequest = new Services.GetStoreAvailabilityServiceRequest(items[0].ItemId, variantId ?? string.Empty); var productAvailabilityResponse = this.Context.Execute <Services.GetStoreAvailabilityServiceResponse>(productAvailabilityRequest); var storeAvailabilities = GetStoreAvailabilities(productAvailabilityResponse.ItemsAvailability, storeLocations, items[0].InventoryUnitOfMeasure); return(new GetStoreProductAvailabilityResponse(storeAvailabilities.AsPagedResult())); } else { ThrowIf.Null(request.Items, "request.Items"); var getStoresRequest = new GetStoresDataRequest(this.Context.GetPrincipal().ChannelId, request.SearchArea, QueryResultSettings.AllRecords); ReadOnlyCollection <OrgUnitLocation> storeLocations = this.Context.Execute <EntityDataServiceResponse <OrgUnitLocation> >(getStoresRequest).PagedEntityCollection.Results; var storeAvailabilities = ChannelAvailabilityHelper.GetChannelAvailabiltiy(this.Context, storeLocations, request.Items); return(new GetStoreProductAvailabilityResponse(storeAvailabilities.AsPagedResult())); } }
private static SearchProductsServiceResponse SearchProducts(SearchProductsServiceRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings"); if (request.ChannelId < 0) { throw new ArgumentOutOfRangeException("request", request.ChannelId, "Channel identifier cannot be less than zero."); } if (request.CatalogId < 0) { throw new ArgumentOutOfRangeException("request", request.CatalogId, "Catalog identifier cannot be less than zero."); } long currentChannelId = request.RequestContext.GetPrincipal().ChannelId; if (request.ChannelId != currentChannelId && request.CategoryId.HasValue) { RemoteSearchProductsRealtimeRequest realtimeRequest = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings); SearchProductsRealtimeResponse realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest); return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults)); } else if (request.ChannelId != currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText)) { var realtimeRequest = new RemoteSearchProductsRealtimeRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings); SearchProductsRealtimeResponse realtimeResponse = request.RequestContext.Execute <SearchProductsRealtimeResponse>(realtimeRequest); return(new SearchProductsServiceResponse(realtimeResponse.ProductSearchResults)); } GetProductSearchResultsDataRequest dataRequest = null; if (request.ChannelId == currentChannelId && request.CategoryId.HasValue) { dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.CategoryId.Value, request.QueryResultSettings); } else if (request.ChannelId == currentChannelId && !string.IsNullOrWhiteSpace(request.SearchText)) { GetProductBarcodeDataRequest productBarcodeRequest = new GetProductBarcodeDataRequest(request.SearchText); GetProductBarcodeDataResponse productBarcodeResponse = request.RequestContext.Execute <GetProductBarcodeDataResponse>(productBarcodeRequest); if (productBarcodeResponse != null && productBarcodeResponse.Barcode != null && !string.IsNullOrWhiteSpace(productBarcodeResponse.Barcode.ItemId)) { dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, productBarcodeResponse.Barcode.ItemId, request.QueryResultSettings); dataRequest.UseFuzzySearch = false; } else { dataRequest = new GetProductSearchResultsDataRequest(request.ChannelId, request.CatalogId, request.SearchText, request.QueryResultSettings); } } else { throw new NotSupportedException("A valid category identifier or search text has not been specified. One of these values need to be set correctly."); } var dataResponse = request.RequestContext.Execute <EntityDataServiceResponse <ProductSearchResult> >(dataRequest); return(new SearchProductsServiceResponse(dataResponse.PagedEntityCollection)); }