本文整理汇总了C#中IList.IsRecurring方法的典型用法代码示例。如果您正苦于以下问题:C# IList.IsRecurring方法的具体用法?C# IList.IsRecurring怎么用?C# IList.IsRecurring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.IsRecurring方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShoppingCartTotal
//.........这里部分代码省略.........
decimal resultTemp = decimal.Zero;
resultTemp += subtotalBase;
if (shoppingCartShipping.HasValue)
{
resultTemp += shoppingCartShipping.Value;
}
resultTemp += paymentMethodAdditionalFeeWithoutTax;
resultTemp += shoppingCartTax;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = Math.Round(resultTemp, 2);
#region Order total discount
discountAmount = GetOrderTotalDiscount(customer, resultTemp, out appliedDiscount);
//sub totals with discount
if (resultTemp < discountAmount)
discountAmount = resultTemp;
//reduce subtotal
resultTemp -= discountAmount;
if (resultTemp < decimal.Zero)
resultTemp = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = Math.Round(resultTemp, 2);
#endregion
#region Applied gift cards
//let's apply gift cards now (gift cards that can be used)
appliedGiftCards = new List<AppliedGiftCard>();
if (!cart.IsRecurring())
{
//we don't apply gift cards for recurring products
var giftCards = _giftCardService.GetActiveGiftCardsAppliedByCustomer(customer);
if (giftCards!=null)
foreach (var gc in giftCards)
if (resultTemp > decimal.Zero)
{
decimal remainingAmount = gc.GetGiftCardRemainingAmount();
decimal amountCanBeUsed = decimal.Zero;
if (resultTemp > remainingAmount)
amountCanBeUsed = remainingAmount;
else
amountCanBeUsed = resultTemp;
//reduce subtotal
resultTemp -= amountCanBeUsed;
var appliedGiftCard = new AppliedGiftCard();
appliedGiftCard.GiftCard = gc;
appliedGiftCard.AmountCanBeUsed = amountCanBeUsed;
appliedGiftCards.Add(appliedGiftCard);
}
}
#endregion
if (resultTemp < decimal.Zero)
resultTemp = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = Math.Round(resultTemp, 2);
decimal? orderTotal = null;
示例2: PrepareShoppingCartModel
//.........这里部分代码省略.........
{
Id = sci.Id,
Sku = sci.Product.FormatSku(sci.AttributesXml, _productAttributeParser),
ProductId = sci.Product.Id,
ProductName = sci.Product.GetLocalized(x => x.Name),
ProductSeName = sci.Product.GetSeName(),
Quantity = sci.Quantity,
AttributeInfo = _productAttributeFormatter.FormatAttributes(sci.Product, sci.AttributesXml),
};
//allow editing?
//1. setting enabled?
//2. simple product?
//3. has attribute or gift card?
//4. visible individually?
cartItemModel.AllowItemEditing = _shoppingCartSettings.AllowCartItemEditing &&
sci.Product.ProductType == ProductType.SimpleProduct &&
(!String.IsNullOrEmpty(cartItemModel.AttributeInfo) || sci.Product.IsGiftCard) &&
sci.Product.VisibleIndividually;
//allowed quantities
var allowedQuantities = sci.Product.ParseAllowedQuatities();
foreach (var qty in allowedQuantities)
{
cartItemModel.AllowedQuantities.Add(new SelectListItem()
{
Text = qty.ToString(),
Value = qty.ToString(),
Selected = sci.Quantity == qty
});
}
//recurring info
if (sci.Product.IsRecurring)
cartItemModel.RecurringInfo = string.Format(_localizationService.GetResource("ShoppingCart.RecurringPeriod"), sci.Product.RecurringCycleLength, sci.Product.RecurringCyclePeriod.GetLocalizedEnum(_localizationService, _workContext));
//unit prices
if (sci.Product.CallForPrice)
{
cartItemModel.UnitPrice = _localizationService.GetResource("Products.CallForPrice");
}
else
{
decimal taxRate = decimal.Zero;
decimal shoppingCartUnitPriceWithDiscountBase = _taxService.GetProductPrice(sci.Product, _priceCalculationService.GetUnitPrice(sci, true), out taxRate);
decimal shoppingCartUnitPriceWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartUnitPriceWithDiscountBase, _workContext.WorkingCurrency);
cartItemModel.UnitPrice = _priceFormatter.FormatPrice(shoppingCartUnitPriceWithDiscount);
}
//subtotal, discount
if (sci.Product.CallForPrice)
{
cartItemModel.SubTotal = _localizationService.GetResource("Products.CallForPrice");
}
else
{
//sub total
decimal taxRate = decimal.Zero;
decimal shoppingCartItemSubTotalWithDiscountBase = _taxService.GetProductPrice(sci.Product, _priceCalculationService.GetSubTotal(sci, true), out taxRate);
decimal shoppingCartItemSubTotalWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartItemSubTotalWithDiscountBase, _workContext.WorkingCurrency);
cartItemModel.SubTotal = _priceFormatter.FormatPrice(shoppingCartItemSubTotalWithDiscount);
//display an applied discount amount
decimal shoppingCartItemSubTotalWithoutDiscountBase = _taxService.GetProductPrice(sci.Product, _priceCalculationService.GetSubTotal(sci, false), out taxRate);
decimal shoppingCartItemDiscountBase = shoppingCartItemSubTotalWithoutDiscountBase - shoppingCartItemSubTotalWithDiscountBase;
if (shoppingCartItemDiscountBase > decimal.Zero)
{
示例3: PreparePaymentMethodModel
protected CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<OrganizedShoppingCartItem> cart)
{
var model = new CheckoutPaymentMethodModel();
//reward points
if (_rewardPointsSettings.Enabled && !cart.IsRecurring())
{
int rewardPointsBalance = _workContext.CurrentCustomer.GetRewardPointsBalance();
decimal rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance);
decimal rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency);
if (rewardPointsAmount > decimal.Zero)
{
model.DisplayRewardPoints = true;
model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false);
model.RewardPointsBalance = rewardPointsBalance;
}
}
var paymentTypes = new PaymentMethodType[] { PaymentMethodType.Standard, PaymentMethodType.Redirection, PaymentMethodType.StandardAndRedirection };
var boundPaymentMethods = _paymentService
.LoadActivePaymentMethods(_workContext.CurrentCustomer, cart, _storeContext.CurrentStore.Id, paymentTypes)
.ToList();
var allPaymentMethods = _paymentService.GetAllPaymentMethods();
foreach (var pm in boundPaymentMethods)
{
if (cart.IsRecurring() && pm.Value.RecurringPaymentType == RecurringPaymentType.NotSupported)
continue;
var paymentMethod = allPaymentMethods.FirstOrDefault(x => x.PaymentMethodSystemName.IsCaseInsensitiveEqual(pm.Metadata.SystemName));
var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel
{
Name = _pluginMediator.GetLocalizedFriendlyName(pm.Metadata),
Description = _pluginMediator.GetLocalizedDescription(pm.Metadata),
PaymentMethodSystemName = pm.Metadata.SystemName,
PaymentInfoRoute = pm.Value.GetPaymentInfoRoute(),
RequiresInteraction = pm.Value.RequiresInteraction
};
if (paymentMethod != null)
{
pmModel.FullDescription = paymentMethod.GetLocalized(x => x.FullDescription, _workContext.WorkingLanguage.Id);
}
pmModel.BrandUrl = _pluginMediator.GetBrandImageUrl(pm.Metadata);
// payment method additional fee
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, pm.Metadata.SystemName);
decimal rateBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
if (rate != decimal.Zero)
pmModel.Fee = _priceFormatter.FormatPaymentMethodAdditionalFee(rate, true);
model.PaymentMethods.Add(pmModel);
}
// find a selected (previously) payment method
var selectedPaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(
SystemCustomerAttributeNames.SelectedPaymentMethod, _genericAttributeService, _storeContext.CurrentStore.Id);
bool selected = false;
if (selectedPaymentMethodSystemName.HasValue())
{
var paymentMethodToSelect = model.PaymentMethods.Find(pm => pm.PaymentMethodSystemName.IsCaseInsensitiveEqual(selectedPaymentMethodSystemName));
if (paymentMethodToSelect != null)
{
paymentMethodToSelect.Selected = true;
selected = true;
}
}
// if no option has been selected, let's do it for the first one
if (!selected)
{
var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault();
if (paymentMethodToSelect != null)
paymentMethodToSelect.Selected = true;
}
return model;
}
示例4: PreparePaymentMethodModel
protected CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<ShoppingCartItem> cart)
{
var model = new CheckoutPaymentMethodModel();
//reward points
if (_rewardPointsSettings.Enabled && !cart.IsRecurring())
{
int rewardPointsBalance = _workContext.CurrentCustomer.GetRewardPointsBalance();
decimal rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance);
decimal rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency);
if (rewardPointsAmount > decimal.Zero &&
_orderTotalCalculationService.CheckMinimumRewardPointsToUseRequirement(rewardPointsBalance))
{
model.DisplayRewardPoints = true;
model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false);
model.RewardPointsBalance = rewardPointsBalance;
}
}
var boundPaymentMethods = _paymentService
.LoadActivePaymentMethods(_workContext.CurrentCustomer.Id)
.Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection)
.ToList();
foreach (var pm in boundPaymentMethods)
{
if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported)
continue;
var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel()
{
Name = pm.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id),
PaymentMethodSystemName = pm.PluginDescriptor.SystemName,
};
//payment method additional fee
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, pm.PluginDescriptor.SystemName);
decimal rateBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
if (rate > decimal.Zero)
pmModel.Fee = _priceFormatter.FormatPaymentMethodAdditionalFee(rate, true);
model.PaymentMethods.Add(pmModel);
}
//find a selected (previously) payment method
var selectedPaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(
SystemCustomerAttributeNames.SelectedPaymentMethod,
_genericAttributeService, _storeContext.CurrentStore.Id);
if (!String.IsNullOrEmpty(selectedPaymentMethodSystemName))
{
var paymentMethodToSelect = model.PaymentMethods.ToList()
.Find(pm => pm.PaymentMethodSystemName.Equals(selectedPaymentMethodSystemName, StringComparison.InvariantCultureIgnoreCase));
if (paymentMethodToSelect != null)
paymentMethodToSelect.Selected = true;
}
//if no option has been selected, let's do it for the first one
if (model.PaymentMethods.FirstOrDefault(so => so.Selected) == null)
{
var paymentMethodToSelect = model.PaymentMethods.FirstOrDefault();
if (paymentMethodToSelect != null)
paymentMethodToSelect.Selected = true;
}
return model;
}
示例5: PrepareButtonPaymentMethodModel
private void PrepareButtonPaymentMethodModel(ButtonPaymentMethodModel model, IList<OrganizedShoppingCartItem> cart)
{
model.Items.Clear();
var paymentTypes = new PaymentMethodType[] { PaymentMethodType.Button, PaymentMethodType.StandardAndButton };
var boundPaymentMethods = _paymentService
.LoadActivePaymentMethods(_workContext.CurrentCustomer, cart, _storeContext.CurrentStore.Id, paymentTypes, false)
.ToList();
foreach (var pm in boundPaymentMethods)
{
if (cart.IsRecurring() && pm.Value.RecurringPaymentType == RecurringPaymentType.NotSupported)
continue;
string actionName;
string controllerName;
RouteValueDictionary routeValues;
pm.Value.GetPaymentInfoRoute(out actionName, out controllerName, out routeValues);
model.Items.Add(new ButtonPaymentMethodModel.ButtonPaymentMethodItem
{
ActionName = actionName,
ControllerName = controllerName,
RouteValues = routeValues
});
}
}
示例6: PreparePaymentMethodModel
private CheckoutPaymentMethodModel PreparePaymentMethodModel(IList<ShoppingCartItem> cart)
{
var model = new CheckoutPaymentMethodModel();
//reward points
if (_rewardPointsSettings.Enabled && !cart.IsRecurring())
{
int rewardPointsBalance = _workContext.CurrentCustomer.GetRewardPointsBalance();
decimal rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance);
decimal rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency);
if (rewardPointsAmount > decimal.Zero)
{
model.DisplayRewardPoints = true;
model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false);
model.RewardPointsBalance = rewardPointsBalance;
}
}
var boundPaymentMethods = _paymentService
.LoadActivePaymentMethods()
.Where(pm => pm.PaymentMethodType == PaymentMethodType.Standard || pm.PaymentMethodType == PaymentMethodType.Redirection)
.ToList();
foreach (var pm in boundPaymentMethods)
{
if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported)
continue;
var pmModel = new CheckoutPaymentMethodModel.PaymentMethodModel()
{
Name = pm.PluginDescriptor.FriendlyName,
PaymentMethodSystemName = pm.PluginDescriptor.SystemName,
};
//payment method additional fee
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(pm.PluginDescriptor.SystemName);
decimal rateBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
if (rate > decimal.Zero)
pmModel.Fee = _priceFormatter.FormatPaymentMethodAdditionalFee(rate, true);
model.PaymentMethods.Add(pmModel);
}
return model;
}
示例7: PrepareShoppingCartModel
//.........这里部分代码省略.........
int? defaultEstimateStateId = (setEstimateShippingDefaultAddress && _workContext.CurrentCustomer.ShippingAddress != null) ? _workContext.CurrentCustomer.ShippingAddress.StateProvinceId : model.EstimateShipping.StateProvinceId;
var states = defaultEstimateCountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(defaultEstimateCountryId.Value).ToList() : new List<StateProvince>();
if (states.Count > 0)
foreach (var s in states)
model.EstimateShipping.AvailableStates.Add(new SelectListItem() {
Text = s.GetLocalized(x => x.Name),
Value = s.Id.ToString(),
Selected = s.Id == defaultEstimateStateId
});
else
model.EstimateShipping.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });
if (setEstimateShippingDefaultAddress && _workContext.CurrentCustomer.ShippingAddress != null)
model.EstimateShipping.ZipPostalCode = _workContext.CurrentCustomer.ShippingAddress.ZipPostalCode;
}
#endregion
#region Cart items
foreach (var sci in cart)
{
var cartItemModel = new ShoppingCartModel.ShoppingCartItemModel()
{
Id = sci.Id,
Sku = sci.ProductVariant.Sku,
ProductId = sci.ProductVariant.ProductId,
ProductSeName = sci.ProductVariant.Product.GetSeName(),
Quantity = sci.Quantity,
AttributeInfo = _productAttributeFormatter.FormatAttributes(sci.ProductVariant, sci.AttributesXml),
};
//recurring info
if (sci.ProductVariant.IsRecurring)
cartItemModel.RecurringInfo = string.Format(_localizationService.GetResource("ShoppingCart.RecurringPeriod"), sci.ProductVariant.RecurringCycleLength, sci.ProductVariant.RecurringCyclePeriod.GetLocalizedEnum(_localizationService, _workContext));
//unit prices
if (sci.ProductVariant.CallForPrice)
{
cartItemModel.UnitPrice = _localizationService.GetResource("Products.CallForPrice");
}
else
{
decimal taxRate = decimal.Zero;
decimal shoppingCartUnitPriceWithDiscountBase = _taxService.GetProductPrice(sci.ProductVariant, _priceCalculationService.GetUnitPrice(sci, true), out taxRate);
decimal shoppingCartUnitPriceWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartUnitPriceWithDiscountBase, _workContext.WorkingCurrency);
cartItemModel.UnitPrice = _priceFormatter.FormatPrice(shoppingCartUnitPriceWithDiscount);
}
//subtotal, discount
if (sci.ProductVariant.CallForPrice)
{
cartItemModel.SubTotal = _localizationService.GetResource("Products.CallForPrice");
}
else
{
//sub total
decimal taxRate = decimal.Zero;
decimal shoppingCartItemSubTotalWithDiscountBase = _taxService.GetProductPrice(sci.ProductVariant, _priceCalculationService.GetSubTotal(sci, true), out taxRate);
decimal shoppingCartItemSubTotalWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartItemSubTotalWithDiscountBase, _workContext.WorkingCurrency);
cartItemModel.SubTotal = _priceFormatter.FormatPrice(shoppingCartItemSubTotalWithDiscount);
//display an applied discount amount
decimal shoppingCartItemSubTotalWithoutDiscountBase = _taxService.GetProductPrice(sci.ProductVariant, _priceCalculationService.GetSubTotal(sci, false), out taxRate);
decimal shoppingCartItemDiscountBase = shoppingCartItemSubTotalWithoutDiscountBase - shoppingCartItemSubTotalWithDiscountBase;
if (shoppingCartItemDiscountBase > decimal.Zero)
{
示例8: GetShoppingCartTotal
public override decimal? GetShoppingCartTotal(IList<global::Nop.Core.Domain.Orders.ShoppingCartItem> cart, out decimal discountAmount, out global::Nop.Core.Domain.Discounts.Discount appliedDiscount, out List<AppliedGiftCard> appliedGiftCards, out int redeemedRewardPoints, out decimal redeemedRewardPointsAmount, bool ignoreRewardPonts = false, bool usePaymentMethodAdditionalFee = true)
{
if (!_promoSettings.Enabled)
return base.GetShoppingCartTotal(cart, out discountAmount, out appliedDiscount, out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount, ignoreRewardPonts, usePaymentMethodAdditionalFee);
BasketResponse basketResponse = _promoUtilities.GetBasketResponse();
if (basketResponse == null || basketResponse.Items == null || basketResponse.Summary == null)
{
return base.GetShoppingCartTotal(cart, out discountAmount, out appliedDiscount, out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount, ignoreRewardPonts, usePaymentMethodAdditionalFee);
}
if (!basketResponse.Summary.ProcessingResult)
{
return base.GetShoppingCartTotal(cart, out discountAmount, out appliedDiscount, out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount, ignoreRewardPonts, usePaymentMethodAdditionalFee);
}
Customer customer = cart.GetCustomer();
discountAmount = decimal.Zero;
appliedDiscount = null;
decimal resultTemp = basketResponse.BasketTotal;
#region Applied gift cards
appliedGiftCards = new List<AppliedGiftCard>();
if (!cart.IsRecurring())
{
//we don't apply gift cards for recurring products
var giftCards = _giftCardService.GetActiveGiftCardsAppliedByCustomer(customer);
if (giftCards != null)
foreach (var gc in giftCards)
if (resultTemp > decimal.Zero)
{
decimal remainingAmount = gc.GetGiftCardRemainingAmount();
decimal amountCanBeUsed = decimal.Zero;
if (resultTemp > remainingAmount)
amountCanBeUsed = remainingAmount;
else
amountCanBeUsed = resultTemp;
//reduce subtotal
resultTemp -= amountCanBeUsed;
var appliedGiftCard = new AppliedGiftCard();
appliedGiftCard.GiftCard = gc;
appliedGiftCard.AmountCanBeUsed = amountCanBeUsed;
appliedGiftCards.Add(appliedGiftCard);
}
}
if (resultTemp < decimal.Zero)
resultTemp = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = RoundingHelper.RoundPrice(resultTemp);
#endregion
redeemedRewardPoints = 0;
redeemedRewardPointsAmount = Decimal.Zero;
decimal orderTotal = basketResponse.BasketTotal - appliedGiftCards.Sum(agc => agc.AmountCanBeUsed);
#region Reward points
if (_rewardPointsSettings.Enabled &&
!ignoreRewardPonts &&
customer.GetAttribute<bool>(SystemCustomerAttributeNames.UseRewardPointsDuringCheckout,
_genericAttributeService, _storeContext.CurrentStore.Id))
{
int rewardPointsBalance = customer.GetRewardPointsBalance();
if (CheckMinimumRewardPointsToUseRequirement(rewardPointsBalance))
{
decimal rewardPointsBalanceAmount = ConvertRewardPointsToAmount(rewardPointsBalance);
if (orderTotal > decimal.Zero)
{
if (orderTotal > rewardPointsBalanceAmount)
{
redeemedRewardPoints = rewardPointsBalance;
redeemedRewardPointsAmount = rewardPointsBalanceAmount;
}
else
{
redeemedRewardPointsAmount = orderTotal;
redeemedRewardPoints = ConvertAmountToRewardPoints(redeemedRewardPointsAmount);
}
}
}
}
#endregion
var shippingOption = _workContext.CurrentCustomer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _storeContext.CurrentStore.Id);
if (shippingOption == null)
{
// Where there are items in the basket that are not for shipping, ensure we carry on, otherwise placing orders gets stuck.
if(cart.Any(sci => sci.IsShipEnabled))
return null;
}
//.........这里部分代码省略.........
示例9: PrepareShoppingCartModel
//.........这里部分代码省略.........
if (model.EstimateShipping.Enabled)
{
//countries
int? defaultEstimateCountryId = (setEstimateShippingDefaultAddress && _workContext.CurrentCustomer.ShippingAddress != null) ? _workContext.CurrentCustomer.ShippingAddress.CountryId : model.EstimateShipping.CountryId;
//model.EstimateShipping.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
foreach (var c in _countryService.GetAllCountriesForShipping())
model.EstimateShipping.AvailableCountries.Add(new SelectListItem()
{
Text = c.GetLocalized(x => x.Name),
Value = c.Id.ToString(),
Selected = c.Id == defaultEstimateCountryId
});
//states
int? defaultEstimateStateId = (setEstimateShippingDefaultAddress && _workContext.CurrentCustomer.ShippingAddress != null) ? _workContext.CurrentCustomer.ShippingAddress.StateProvinceId : model.EstimateShipping.StateProvinceId;
var states = defaultEstimateCountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(defaultEstimateCountryId.Value).ToList() : new List<StateProvince>();
if (states.Count > 0)
foreach (var s in states)
model.EstimateShipping.AvailableStates.Add(new SelectListItem()
{
Text = s.GetLocalized(x => x.Name),
Value = s.Id.ToString(),
Selected = s.Id == defaultEstimateStateId
});
else
model.EstimateShipping.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });
if (setEstimateShippingDefaultAddress && _workContext.CurrentCustomer.ShippingAddress != null)
model.EstimateShipping.ZipPostalCode = _workContext.CurrentCustomer.ShippingAddress.ZipPostalCode;
}
}
#endregion
#region Cart items
foreach (var sci in cart)
{
var shoppingCartItemModel = PrepareShoppingCartItemModel(sci);
model.Items.Add(shoppingCartItemModel);
}
#endregion
#region Button payment methods
var boundPaymentMethods = _paymentService
.LoadActivePaymentMethods(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id)
.Where(pm => pm.PaymentMethodType == PaymentMethodType.Button || pm.PaymentMethodType == PaymentMethodType.StandardAndButton)
.ToList();
foreach (var pm in boundPaymentMethods)
{
if (cart.IsRecurring() && pm.RecurringPaymentType == RecurringPaymentType.NotSupported)
continue;
string actionName;
string controllerName;
RouteValueDictionary routeValues;
pm.GetPaymentInfoRoute(out actionName, out controllerName, out routeValues);
model.ButtonPaymentMethodActionNames.Add(actionName);
model.ButtonPaymentMethodControllerNames.Add(controllerName);
model.ButtonPaymentMethodRouteValues.Add(routeValues);
}
#endregion
#region Order review data
if (prepareAndDisplayOrderReviewData)
{
model.OrderReviewData.Display = true;
//billing info
var billingAddress = _workContext.CurrentCustomer.BillingAddress;
if (billingAddress != null)
model.OrderReviewData.BillingAddress.PrepareModel(billingAddress, false, _addressSettings);
//shipping info
if (cart.RequiresShipping())
{
model.OrderReviewData.IsShippable = true;
var shippingAddress = _workContext.CurrentCustomer.ShippingAddress;
if (shippingAddress != null)
model.OrderReviewData.ShippingAddress.PrepareModel(shippingAddress, false, _addressSettings);
//selected shipping method
var shippingOption = _workContext.CurrentCustomer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _storeContext.CurrentStore.Id);
if (shippingOption != null)
model.OrderReviewData.ShippingMethod = shippingOption.Name;
}
//payment info
var selectedPaymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(
SystemCustomerAttributeNames.SelectedPaymentMethod, _storeContext.CurrentStore.Id);
var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(selectedPaymentMethodSystemName);
model.OrderReviewData.PaymentMethod = paymentMethod != null ? paymentMethod.GetLocalizedValue(_localizationService, "FriendlyName", _workContext.WorkingLanguage.Id) : "";
}
#endregion
}