private void DeleteShippingMethods(ShippingMethodDto dto) { foreach (var method in dto.ShippingMethod) { method.Delete(); } }
private string CheckApplicableShippings(string code) { /* load the Shipping-Method-Parameters and inspect what method will be used... * for now, just output text to the page, could also use it for loading "the right" method-guid * for the second shipment added */ string str = String.Empty; // get the rows, we don't care about the market-part now ShippingMethodDto dto = ShippingManager.GetShippingMethodsByMarket (MarketId.Default.Value, false); foreach (ShippingMethodDto.ShippingMethodRow shippingMethod in dto.ShippingMethod) { // This is the interesting part, could be complemented with dbo.ShippingOptionParameter // get the param-rows, could show the dbo.ShippingMethodParameter table in VS ShippingMethodDto.ShippingMethodParameterRow[] paramRows = shippingMethod.GetShippingMethodParameterRows(); if (paramRows.Count() != 0) { // right now we're just outputting text to the cart // ... should more likely get the guid instead // could be here we can match lineItem with the shipping method or gateway foreach (var shippingMethodParameter in paramRows) { str += shippingMethod.Name + " : " + shippingMethodParameter.Parameter + " or "; var v = shippingMethodParameter.Value; // ...not in use... yet... } } } return(str); }
/// <summary> /// Creates the empty dto. /// </summary> /// <param name="sm">The sm.</param> /// <param name="persistInSession">if set to <c>true</c> [persist in session].</param> private void CreateEmptyDto(ref ShippingMethodDto sm, bool persistInSession) { if (sm == null || sm.ShippingMethod.Count == 0) { // fill dto with all available shipping options. They will be needed for contraints to work properly when a new shipping method is created. sm = ShippingManager.GetShippingMethods(LanguageCode, true); // remove shipping methods, because we need an empty dto. if (sm != null) { if (sm.ShippingMethod.Count > 0) { while (sm.ShippingMethod.Rows.Count > 0) { sm.ShippingMethod.Rows.RemoveAt(0); } } } if (persistInSession) { Session[GetShippingMethodSessionKey()] = sm; } } }
/// <summary> /// Loads the context. /// </summary> private void LoadContext() { ShippingMethodDto sm = null; if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load { sm = LoadFresh(); CreateEmptyDto(ref sm, true); } else // load from session { sm = (ShippingMethodDto)Session[GetPackageSessionKey()]; if (sm == null) { sm = LoadFresh(); } } // Put a dictionary key that can be used by other tabs IDictionary dic = new ListDictionary(); dic.Add(_ShippingMethodDtoString, sm); // Call tabs load context ViewControl.LoadContext(dic); }
void ProcessDeleteCommand(string[] items) { // load all shipping options ShippingMethodDto dto = ShippingManager.GetShippingMethods(null, true); if (dto != null && dto.ShippingOption.Count > 0) { // delete selected for (int i = 0; i < items.Length; i++) { string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]); if (keys != null) { Guid id = new Guid(keys[0]); // delete selected shipping option ShippingMethodDto.ShippingOptionRow[] soRows = (ShippingMethodDto.ShippingOptionRow[])dto.ShippingOption.Select(String.Format("ShippingOptionId='{0}'", id)); if (soRows != null && soRows.Length > 0) { soRows[0].Delete(); } } } if (dto.HasChanges()) { ShippingManager.SaveShipping(dto); } } }
private ShippingRate GetRate(Shipment shipment, ShippingMethodDto.ShippingMethodRow shippingMethodRow) { var type = Type.GetType(shippingMethodRow.ShippingOptionRow.ClassName); var shippingGateway = (IShippingGateway)Activator.CreateInstance(type, _currentMarket.GetCurrentMarket()); string message = null; return shippingGateway.GetRate(shippingMethodRow.ShippingMethodId, shipment, ref message); }
private ShippingRate CreateShippingRate( Guid methodId, ShippingMethodDto shippingMethod, EstimateResult <ShipmentEstimate> result) { var estimate = result.Estimates.First(); var priceExclTax = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceExclTax) == "True"; var usesAdditionalServices = !string.IsNullOrEmpty(shippingMethod.GetShippingMethodParameterValue(ParameterNames.AdditionalServices)); var priceWithAdditionalServices = !priceExclTax ? (decimal)estimate.PackagePrice.PackagePriceWithAdditionalServices.AmountWithVAT : (decimal)estimate.PackagePrice.PackagePriceWithAdditionalServices.AmountWithoutVAT; var priceWithoutAdditionalServices = !priceExclTax ? (decimal)estimate.PackagePrice.PackagePriceWithoutAdditionalServices.AmountWithVAT : (decimal)estimate.PackagePrice.PackagePriceWithoutAdditionalServices.AmountWithoutVAT; var amount = AdjustPrice(shippingMethod, usesAdditionalServices ? priceWithAdditionalServices : priceWithoutAdditionalServices); var moneyAmount = new Money( amount, new Currency(estimate.PackagePrice.CurrencyIdentificationCode)); return(new BringShippingRate( methodId, estimate.GuiInformation.DisplayName, estimate.GuiInformation.MainDisplayCategory, estimate.GuiInformation.SubDisplayCategory, estimate.GuiInformation.DescriptionText, estimate.GuiInformation.HelpText, estimate.GuiInformation.Tip, estimate.ExpectedDelivery.ExpectedDeliveryDate, moneyAmount)); }
private IEnumerable <ShippingMethodAndRate> GetShippingMethodsWithRates(Cart cart, OrderAddress address) { ShippingMethodDto shippingMethods = ShippingManager.GetShippingMethods(CurrentPage.LanguageID, false); List <ShippingMethodAndRate> shippingMethodsList = new List <ShippingMethodAndRate>(); string outputMessage = string.Empty; string shippingMethodAndPrice = string.Empty; //get the one shipment in the order Shipment ship = null; if (cart.OrderForms[0].Shipments != null && cart.OrderForms[0].Shipments.Count > 0) { ship = cart.OrderForms[0].Shipments[0]; } if (ship != null) { // request rates, make sure we request rates not bound to selected delivery method foreach (ShippingMethodDto.ShippingMethodRow row in shippingMethods.ShippingMethod) { shippingMethodsList.Add(GetShippingRateInfo(row, ship)); } } return(shippingMethodsList); }
private ShipmentLeg CreateShipmentLeg(IShipment shipment, ShippingMethodDto shippingMethod) { var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod .GetShippingOptionParameterValue(ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); if (string.IsNullOrEmpty(shipment.WarehouseCode) == false) { var warehouse = _warehouseRepository.Get(shipment.WarehouseCode); var warehousePostalCode = warehouse.ContactInformation?.PostalCode; var warehouseCountryCode = warehouse.ContactInformation?.CountryCode; if (string.IsNullOrEmpty(warehousePostalCode) == false && warehouse.IsPickupLocation) { postalCodeFrom = warehousePostalCode; countryCodeFrom = warehouseCountryCode.ToIso2CountryCode(); } } var countryCodeTo = shipment.ShippingAddress.CountryCode.ToIso2CountryCode(); return(new ShipmentLeg(postalCodeFrom, shipment.ShippingAddress.PostalCode, countryCodeFrom, countryCodeTo)); }
/// <summary> /// Binds the lists. /// </summary> private void BindLists() { // bind shipment packages if (PackageList.Items.Count <= 1) { ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages(); if (shippingDto.Package != null) { foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows) { PackageList.Items.Add(new ListItem(row.Name, row.PackageId.ToString())); } } PackageList.DataBind(); } // bind warehouses if (WarehouseList.Items.Count <= 1) { WarehouseDto dto = WarehouseManager.GetWarehouseDto(); if (dto.Warehouse != null) { foreach (WarehouseDto.WarehouseRow row in dto.Warehouse.Rows) { WarehouseList.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString())); } } WarehouseList.DataBind(); } // bind merchants if (MerchantList.Items.Count <= 1) { CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto(); if (merchants.Merchant != null) { foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows) { MerchantList.Items.Add(new ListItem(row.Name, row.MerchantId.ToString())); } } MerchantList.DataBind(); } // bind tax categories if (TaxList.Items.Count <= 1) { CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories(); if (taxes.TaxCategory != null) { foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows) { TaxList.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString())); } } TaxList.DataBind(); } }
private Guid GetSipMethodByOptionParam(string itemCode) { string paramName = itemCode.Split('_')[0]; ShippingMethodDto dto = ShippingManager.GetShippingMethodsByMarket(MarketId.Default.Value, false); Guid optionParam = dto.ShippingOptionParameter.Where(r => r.Parameter.Contains(paramName)).FirstOrDefault().ShippingOptionId; return(dto.ShippingMethod.Where(r => r.ShippingOptionId == optionParam).FirstOrDefault().ShippingMethodId); }
/// <summary> /// Binds the shipping methods list. /// </summary> /// <param name="paymentRow">The payment row.</param> private void BindShippingMethodsList(PaymentMethodDto.PaymentMethodRow paymentRow) { List <ShippingMethodDto.ShippingMethodRow> leftShippings = new List <ShippingMethodDto.ShippingMethodRow>(); List <ShippingMethodDto.ShippingMethodRow> rightShippings = new List <ShippingMethodDto.ShippingMethodRow>(); ShippingMethodDto dto = ShippingManager.GetShippingMethods(paymentRow != null ? paymentRow.LanguageId : LanguageCode, true); bool allToLeft = false; // if true, then add all shipping methods to the left list if (paymentRow != null) { PaymentMethodDto.ShippingPaymentRestrictionRow[] restrictedShippingRows = paymentRow.GetShippingPaymentRestrictionRows(); if (restrictedShippingRows != null && restrictedShippingRows.Length > 0) { foreach (ShippingMethodDto.ShippingMethodRow shippingMethodRow in dto.ShippingMethod) { bool found = false; foreach (PaymentMethodDto.ShippingPaymentRestrictionRow restrictedShippingRow in restrictedShippingRows) { if (shippingMethodRow.ShippingMethodId == restrictedShippingRow.ShippingMethodId) { found = true; break; } } if (found) { rightShippings.Add(shippingMethodRow); } else { leftShippings.Add(shippingMethodRow); } } ShippingMethodsList.LeftDataSource = leftShippings; ShippingMethodsList.RightDataSource = rightShippings; } else { // add all shipping methods to the left list allToLeft = true; } } else { allToLeft = true; } if (allToLeft) { // add all shipping methods to the left list ShippingMethodsList.LeftDataSource = dto.ShippingMethod; } ShippingMethodsList.DataBind(); }
/// <summary> /// Loads the fresh. /// </summary> /// <returns></returns> private ShippingMethodDto LoadFresh() { ShippingMethodDto sm = ShippingManager.GetShippingOption(ShippingOptionId, true); // persist in session Session[GetShippingMethodSessionKey()] = sm; return(sm); }
/// <summary> /// Binds the shipping options. /// </summary> /// <param name="language">The language.</param> private void BindShippingOptions(string language) { this.ddlShippingOption.Items.Clear(); ShippingMethodDto sm = ShippingManager.GetShippingMethods(language, true); ddlShippingOption.DataSource = sm.ShippingOption; ddlShippingOption.DataBind(); }
/// <summary> /// Loads the fresh. /// </summary> /// <returns></returns> private ShippingMethodDto LoadFresh() { ShippingMethodDto sm = ShippingManager.GetShippingPackage(PackageId); // persist in session Session[GetPackageSessionKey()] = sm; return(sm); }
private ShippingMethodDto GetPackages() { if (_PackagesDto == null) { _PackagesDto = ShippingManager.GetShippingPackages(); } return(_PackagesDto); }
public void SaveChanges(IDictionary context) { //WidthValidator.Validate(); //LengthValidator.Validate(); //HeightValidator.Validate(); if (!chbDimensions.Checked || (chbDimensions.Checked && Page.IsValid)) { ShippingMethodDto dto = (ShippingMethodDto)context[_ShippingMethodDtoString]; ShippingMethodDto.PackageRow row = null; if (dto == null) { // dto must be created in base Package edit control that holds tabs return; } // create the row if it doesn't exist; or update its modified date if it exists if (dto.Package.Count > 0) { row = dto.Package[0]; } else { row = dto.Package.NewPackageRow(); row.ApplicationId = OrderConfiguration.Instance.ApplicationId; } // fill the row with values row.Name = tbName.Text; row.Description = tbDescription.Text; if (chbDimensions.Checked) { row.Width = double.Parse(tbWidth.Text); row.Length = double.Parse(tbLength.Text); row.Height = double.Parse(tbHeight.Text); } else { row.Width = 0; row.Height = 0; row.Length = 0; } // add the row to the dto if (row.RowState == DataRowState.Detached) { dto.Package.Rows.Add(row); } } else { chbDimensions.Checked = false; } }
private void AssociateShippingMethodWithMarkets(ShippingMethodDto dto, IEnumerable <IMarket> markets, IEnumerable <ShippingMethodDto.ShippingMethodRow> shippingSet) { foreach (var shippingMethod in shippingSet) { foreach (var market in markets.Where(m => m.Currencies.Contains(shippingMethod.Currency))) { dto.MarketShippingMethods.AddMarketShippingMethodsRow(market.MarketId.Value, shippingMethod); } } }
public IEstimateSettings CreateFrom(ShippingMethodDto shippingMethod) { var productId = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.BringProductId, null); var customerNumber = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.BringCustomerNumber, null); var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(BringShippingGateway.ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod.GetShippingOptionParameterValue(BringShippingGateway.ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); var ediParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.Edi, "true"); bool.TryParse(ediParameter, out var edi); var postingAtPostOfficeParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PostingAtPostOffice, "false"); bool.TryParse(postingAtPostOfficeParameter, out var postingAtPostOffice); var additionalServicesCodes = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.AdditionalServices); var services = additionalServicesCodes.Split(',') .Select(code => AdditionalService.All.FirstOrDefault(x => x.Code == code)) .Where(service => service != null); var priceExclTaxParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceExclTax); bool.TryParse(priceExclTaxParameter, out var priceExclTax); var priceRoundingParameterParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceRounding, "false"); bool.TryParse(priceRoundingParameterParameter, out bool priceRounding); var priceAdjustmentPercentParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceAdjustmentPercent, "0"); int.TryParse(priceAdjustmentPercentParameter, out var priceAdjustmentPercent); var priceAdjustmentOperatorParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceAdjustmentOperator, "true"); bool.TryParse(priceAdjustmentOperatorParameter, out var priceAdjustmentAdd); return(new BringEstimateSettings { BringProductId = productId, BringCustomerNumber = customerNumber, PostalCodeFrom = postalCodeFrom, CountryCodeFrom = countryCodeFrom, Edi = edi, PostingAtPostOffice = postingAtPostOffice, PriceExclTax = priceExclTax, PriceAdjustmentIsAddition = priceAdjustmentAdd, PriceAdjustmentPercent = priceAdjustmentPercent, PriceRounding = priceRounding, AdditionalServices = services }); }
/// <summary> /// Creates the empty dto. /// </summary> /// <param name="sm">The sm.</param> /// <param name="persistInSession">if set to <c>true</c> [persist in session].</param> private void CreateEmptyDto(ref ShippingMethodDto sm, bool persistInSession) { if (sm == null || sm.ShippingOption.Count == 0) { sm = new ShippingMethodDto(); if (persistInSession) { Session[GetShippingMethodSessionKey()] = sm; } } }
private static ShipmentLeg CreateShipmentLeg(OrderAddress orderAddress, ShippingMethodDto shippingMethod) { var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod .GetShippingOptionParameterValue(ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); var countryCodeTo = orderAddress.CountryCode.ToIso2CountryCode(); return(new ShipmentLeg(postalCodeFrom, orderAddress.PostalCode, countryCodeFrom, countryCodeTo)); }
private decimal AdjustPrice(ShippingMethodDto shippingMethod, decimal price) { var shippingMethodRow = shippingMethod.ShippingMethod[0]; var amount = shippingMethodRow.BasePrice + price; bool priceRounding; if (bool.TryParse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceRounding, "false"), out priceRounding) && priceRounding) { return(Math.Round(amount, MidpointRounding.AwayFromZero)); } return(amount); }
/// <summary> /// Loads the data and data bind. /// </summary> /// <param name="sortExpression">The sort expression.</param> private void LoadDataAndDataBind(string sortExpression) { ShippingMethodDto dto = ShippingManager.GetShippingMethods(LanguageCode, true); if (dto.ShippingMethod != null) { DataView view = dto.ShippingMethod.DefaultView; view.Sort = sortExpression; MyListView.DataSource = view; } MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("ShippingMethodId", "LanguageId"); MyListView.DataBind(); }
/// <summary> /// Binds the form. /// </summary> /// <param name="reset">if set to <c>true</c> [reset].</param> private void BindForm(bool reset) { if (SelectedLineItem != null) { if (reset) { string shippingMethod = String.Empty; ShippingMethodDto smDto = ShippingManager.GetShippingMethod(SelectedLineItem.ShippingMethodId); if (smDto != null && smDto.ShippingMethod.Count > 0) { shippingMethod = smDto.ShippingMethod[0].DisplayName; if (!String.IsNullOrEmpty(SelectedLineItem.ShippingMethodName)) { shippingMethod += String.Format(" ({0})", SelectedLineItem.ShippingMethodName); } } SetFormFieldsValues(SelectedLineItem.CatalogEntryId, SelectedLineItem.DisplayName, SelectedLineItem.ListPrice, SelectedLineItem.LineItemDiscountAmount, SelectedLineItem.Quantity, SelectedLineItem.ShippingAddressId, shippingMethod); } MetaDataTab.ObjectId = SelectedLineItem.LineItemId; } else if (reset) { CatalogEntryDto dto = GetCatalogEntryDto(); if (dto != null) { SetFormFieldsValues(CatalogEntryCode, dto.CatalogEntry[0].Name, dto.Variation.Count > 0 ? dto.Variation[0].ListPrice : 0m, 0m, 1, String.Empty, String.Empty); } else { SetFormFieldsValues(String.Empty, String.Empty, 0m, 0m, 1m, String.Empty, String.Empty); } } // Bind Meta Form BindMetaForm(); }
/// <summary> /// Loads the data and data bind. /// </summary> /// <param name="sortExpression">The sort expression.</param> private void LoadDataAndDataBind(string sortExpression) { ShippingMethodDto dto = ShippingManager.GetShippingPackages(); if (dto.Package != null) { DataView view = dto.Package.DefaultView; view.Sort = sortExpression; MyListView.DataSource = view; } MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("PackageId"); MyListView.DataBind(); }
private EstimateQuery BuildQuery( IShipment shipment, ShippingMethodDto shippingMethod, IEnumerable <ILineItem> shipmentLineItems) { var shipmentLeg = CreateShipmentLeg(shipment, shippingMethod); var packageSize = CreatePackageSize(shipmentLineItems); var additionalParameters = CreateAdditionalParameters(shippingMethod); return(new EstimateQuery( shipmentLeg, packageSize, additionalParameters.ToArray())); }
protected string GetPackageNameById(int packageId) { string name = String.Empty; ShippingMethodDto dto = GetPackages(); if (dto != null) { ShippingMethodDto.PackageRow packageRow = dto.Package.FindByPackageId(packageId); name = packageRow.Name; } return(name); }
protected virtual EstimateQuery BuildQuery( IShipment shipment, ShippingMethodDto shippingMethod, IEnumerable <ILineItem> shipmentLineItems) { var settings = _estimateSettingsFactory.CreateFrom(shippingMethod); var shipmentLeg = CreateShipmentLeg(shipment, shippingMethod, settings); var packageSize = CreatePackageSize(shipmentLineItems); var additionalParameters = CreateAdditionalParameters(shippingMethod, settings); return(new EstimateQuery( shipmentLeg, packageSize, additionalParameters.ToArray())); }
/// <summary> /// Processes the shipments. /// </summary> private void ProcessShipments() { ShippingMethodDto methods = ShippingManager.GetShippingMethods(Thread.CurrentThread.CurrentUICulture.Name); OrderGroup order = OrderGroup; // request rates, make sure we request rates not bound to selected delivery method foreach (OrderForm form in order.OrderForms) { foreach (Shipment shipment in form.Shipments) { ShippingMethodDto.ShippingMethodRow row = methods.ShippingMethod.FindByShippingMethodId(shipment.ShippingMethodId); // If shipping method is not found, set it to 0 and continue if (row == null) { Logger.Info(String.Format("Total shipment is 0 so skip shipment calculations.")); shipment.ShipmentTotal = 0; continue; } // Check if package contains shippable items, if it does not use the default shipping method instead of the one specified Logger.Debug(String.Format("Getting the type \"{0}\".", row.ShippingOptionRow.ClassName)); Type type = Type.GetType(row.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(row.ShippingOptionRow.ClassName, null); } string message = String.Empty; Logger.Debug(String.Format("Creating instance of \"{0}\".", type.Name)); IShippingGateway provider = (IShippingGateway)Activator.CreateInstance(type); List <LineItem> items = Shipment.GetShipmentLineItems(shipment); Logger.Debug(String.Format("Calculating the rates.")); ShippingRate rate = provider.GetRate(row.ShippingMethodId, items.ToArray(), ref message); if (rate != null) { Logger.Debug(String.Format("Rates calculated.")); shipment.ShipmentTotal = rate.Price; } else { Logger.Debug(String.Format("No rates has been found.")); } } } }
/// <summary> /// Saves the package. /// </summary> /// <param name="dto">The dto.</param> public static void SavePackage(ShippingMethodDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("ShippingMethodDto can not be null")); } // TODO: Check if user is allowed to perform this operation DataCommand cmd = OrderDataHelper.CreateConfigDataCommand(); using (TransactionScope scope = new TransactionScope()) { DataHelper.SaveDataSetSimple(OrderContext.MetaDataContext, cmd, dto, "Package"); scope.Complete(); } }
/// <summary> /// Checks if entered shipping package name is unique. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param> public void ShippingPackageNameCheck(object sender, ServerValidateEventArgs args) { // load shipping package ShippingMethodDto dto = ShippingManager.GetShippingPackage(args.Value); if (dto != null && dto.Package.Count > 0) { if (dto.Package[0].PackageId != PackageId) { args.IsValid = false; return; } } args.IsValid = true; }
private IEnumerable<ShippingMethodDto.ShippingMethodRow> CreateShippingMethodsForLanguageAndCurrencies(ShippingMethodDto dto, IEnumerable<IMarket> markets, string languageId) { var shippingOption = dto.ShippingOption.First(x => x.Name == "Generic Gateway"); var shippingMethods = new List<ShippingMethodDto.ShippingMethodRow>(); var sortOrder = 1; var usdCostExpress = new Money(20, Currency.USD); var usdCostFast = new Money(15, Currency.USD); var usdCostRegular = new Money(5, Currency.USD); foreach (var currency in markets.SelectMany(m => m.Currencies).Distinct()) { shippingMethods.Add(CreateShippingMethod(dto, shippingOption, languageId, sortOrder++, "Express-" + currency, "Express (1 day)", usdCostExpress, currency)); shippingMethods.Add(CreateShippingMethod(dto, shippingOption, languageId, sortOrder++, "Fast-" + currency, "Fast (2-3 days)", usdCostFast, currency)); shippingMethods.Add(CreateShippingMethod(dto, shippingOption, languageId, sortOrder++, "Regular-" + currency, "Regular (4-7 days)", usdCostRegular, currency)); } return shippingMethods; }
private ShippingMethodDto.ShippingMethodRow CreateShippingMethod(ShippingMethodDto dto, ShippingMethodDto.ShippingOptionRow shippingOption, string languageId, int sortOrder, string name, string description, Money costInUsd, Currency currency) { Money shippingCost = CurrencyFormatter.ConvertCurrency(costInUsd, currency); if (shippingCost.Currency != currency) { throw new InvalidOperationException("Cannot convert to currency " + currency + " Missing conversion data."); } return dto.ShippingMethod.AddShippingMethodRow( Guid.NewGuid(), shippingOption, AppContext.Current.ApplicationId, languageId, true, name, "", shippingCost.Amount, shippingCost.Currency, description, false, sortOrder, DateTime.Now, DateTime.Now); }
private void AssociateShippingMethodWithMarkets(ShippingMethodDto dto, IEnumerable<IMarket> markets, IEnumerable<ShippingMethodDto.ShippingMethodRow> shippingSet) { foreach (var shippingMethod in shippingSet) { foreach (var market in markets.Where(m => m.Currencies.Contains(shippingMethod.Currency))) { dto.MarketShippingMethods.AddMarketShippingMethodsRow(market.MarketId.Value, shippingMethod); } } }