/// <summary> /// Gets the store by identifier and sets it on the context. /// </summary> /// <param name="context">The context.</param> private static void PopulateContextWithOrgUnit(RequestContext context) { SearchOrgUnitDataRequest request = new SearchOrgUnitDataRequest(context.GetPrincipal().ChannelId); OrgUnit orgUnit = context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(request, context, skipRequestTriggers: true).PagedEntityCollection.SingleOrDefault(); context.SetOrgUnit(orgUnit); }
private static void SaveTransaction(RequestContext context, TransactionType transactionType, string transactionId) { string terminalId; string storeId; if (context.GetPrincipal() != null && context.GetTerminal() != null) { terminalId = context.GetTerminal().TerminalId; var getStoreDataServiceRequest = new SearchOrgUnitDataRequest(context.GetPrincipal().ChannelId); OrgUnit store = context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(getStoreDataServiceRequest, context).PagedEntityCollection.SingleOrDefault(); storeId = store.OrgUnitNumber; } else { return; } TransactionLog transaction = new TransactionLog() { TransactionType = transactionType, Id = transactionId, StaffId = context.GetPrincipal().UserId, TerminalId = terminalId, StoreId = storeId }; TransactionLogService.LogTransaction(context, transaction); }
/// <summary> /// Constructs the SalesTaxGroupPicker for store. /// </summary> /// <param name="store">The organization unit.</param> /// <param name="customer">The customer object.</param> /// <param name="context">The request context.</param> /// <param name="deliveryAddress">The delivery address.</param> /// <param name="deliveryMode">The delivery mode used.</param> /// <param name="fulfillmentStoreId">The store that fulfills the purchase (pick up from).</param> /// <param name="shippingFromInventLocation">The invent location that item shipped from.</param> /// <returns> /// The SalesTaxGroupPicker object. /// </returns> private static SalesTaxGroupPicker CreatePickerForStore( OrgUnit store, Customer customer, RequestContext context, Address deliveryAddress, string deliveryMode, string fulfillmentStoreId, string shippingFromInventLocation) { var policies = new Collection <ITaxGroupPolicy>(); bool pickUpFromStore = false; if (!string.IsNullOrWhiteSpace(deliveryMode)) { pickUpFromStore = deliveryMode.Equals(context.GetChannelConfiguration().PickupDeliveryModeCode, StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrWhiteSpace(fulfillmentStoreId)) { // same store pickup or not? if (!fulfillmentStoreId.Equals(store.OrgUnitNumber, StringComparison.CurrentCultureIgnoreCase)) { var getStoresByStoreNumbersDataRequest = new SearchOrgUnitDataRequest(new string[] { fulfillmentStoreId }, QueryResultSettings.SingleRecord); store = context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(getStoresByStoreNumbersDataRequest, context).PagedEntityCollection.Results.SingleOrDefault(); } } } // Constructs the policy checking chain in the priority of : Shipping address -> Customer -> Store. // There should be no tax fallback calculations between types of store taxes. // For example, if the store is using Customer based tax and no tax group found, // should return 0 tax instead of trying to calculate using Store based tax. if (store.UseDestinationBasedTax && !pickUpFromStore && deliveryAddress != null) { switch (context.GetChannelConfiguration().CountryRegionISOCode) { case CountryRegionISOCode.IN: policies.Add(new AddressTaxGroupPolicyIndia(context, deliveryAddress, shippingFromInventLocation)); break; default: policies.Add(new AddressTaxGroupPolicy(context, deliveryAddress)); break; } } else if (store.UseCustomerBasedTax && customer != null) { policies.Add(new CustomerTaxGroupPolicy(customer)); } else { policies.Add(new StoreTaxGroupPolicy(store)); } return(new SalesTaxGroupPicker(policies)); }
private OrgUnit GetOrgUnit() { if (this.Context.GetOrgUnit() != null) { return(this.Context.GetOrgUnit()); } long channelId = this.Context.GetPrincipal().ChannelId; var request = new SearchOrgUnitDataRequest(channelId); return(this.Context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(request, this.Context).PagedEntityCollection.SingleOrDefault()); }
/// <summary> /// Executes the workflow to get available stores. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetAvailableStoresResponse Process(GetAvailableStoresRequest request) { ThrowIf.Null(request, "request"); // Validate device token AuthenticationHelper.AuthenticateDevice(this.Context, request.DeviceToken); var getAllStoresDataRequest = new SearchOrgUnitDataRequest(new List <string>(), QueryResultSettings.AllRecords); var stores = this.Context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(getAllStoresDataRequest, this.Context).PagedEntityCollection; var response = new GetAvailableStoresResponse(stores); return(response); }
/// <summary> /// Verifies that the organization unit is published. /// </summary> /// <param name="context">The request context.</param> /// <param name="channelId">The channel identifier.</param> private static void VerifyThatOrgUnitIsPublished(RequestContext context, long channelId) { // retrieve organization unit (store) information OrgUnit orgUnit; SearchOrgUnitDataRequest getStoreDataRequest = new SearchOrgUnitDataRequest(channelId); orgUnit = context.Execute <EntityDataServiceResponse <OrgUnit> >(getStoreDataRequest).PagedEntityCollection.SingleOrDefault(); // make sure store is published before moving further if (orgUnit == null || !orgUnit.IsPublished) { string errorMessage = string.Format( CultureInfo.InvariantCulture, "The channel {0} does not exist or was not published.", channelId); throw new UserAuthorizationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidChannel, errorMessage); } }
/// <summary> /// Constructs SalesTaxGroupPicker for online channel. /// </summary> /// <param name="context">The current CRT request context object.</param> /// <param name="deliveryAddress">The delivery address.</param> /// <param name="deliveryMode">The delivery mode used.</param> /// <param name="fulfillmentStoreId">The store that fulfills the purchase (pick up from).</param> /// <param name="shippingFromInventLocation">The invent location that item shipped from.</param> /// <returns> /// The SalesTaxGroupPicker object. /// </returns> private static SalesTaxGroupPicker CreatePickerForOnlineChannel(RequestContext context, Address deliveryAddress, string deliveryMode, string fulfillmentStoreId, string shippingFromInventLocation) { var policies = new Collection <ITaxGroupPolicy>(); bool pickUpFromStore = false; OrgUnit store = null; if (!string.IsNullOrWhiteSpace(deliveryMode)) { pickUpFromStore = deliveryMode.Equals(context.GetChannelConfiguration().PickupDeliveryModeCode, StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrWhiteSpace(fulfillmentStoreId)) { var getStoresByStoreNumbersDataRequest = new SearchOrgUnitDataRequest(new string[] { fulfillmentStoreId }, QueryResultSettings.SingleRecord); store = context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(getStoresByStoreNumbersDataRequest, context).PagedEntityCollection.Results.SingleOrDefault(); } } if (pickUpFromStore && store != null) { policies.Add(new StoreTaxGroupPolicy(store)); } else { if (deliveryAddress != null) { switch (context.GetChannelConfiguration().CountryRegionISOCode) { case CountryRegionISOCode.IN: policies.Add(new AddressTaxGroupPolicyIndia(context, deliveryAddress, shippingFromInventLocation)); break; default: policies.Add(new AddressTaxGroupPolicy(context, deliveryAddress)); break; } } } return(new SalesTaxGroupPicker(policies)); }
/// <summary> /// Gets the store by identifier. /// </summary> /// <param name="context">The context.</param> /// <returns>The store.</returns> private static OrgUnit GetStoreFromContext(RequestContext context) { SearchOrgUnitDataRequest request = new SearchOrgUnitDataRequest(context.GetPrincipal().ChannelId); return(context.Runtime.Execute <EntityDataServiceResponse <OrgUnit> >(request, context).PagedEntityCollection.SingleOrDefault()); }
private Task <EntityDataServiceResponse <OrgUnit> > GetAllOrgUnitsAsync(Request request) { var orgUnitsRequest = new SearchOrgUnitDataRequest(new List <string>(), QueryResultSettings.AllRecords); return(request.RequestContext.Runtime.ExecuteAsync <EntityDataServiceResponse <OrgUnit> >(orgUnitsRequest, request.RequestContext)); }