本文整理汇总了C#中IList.GetCustomer方法的典型用法代码示例。如果您正苦于以下问题:C# IList.GetCustomer方法的具体用法?C# IList.GetCustomer怎么用?C# IList.GetCustomer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.GetCustomer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShoppingCartShippingTotal
/// <summary>
/// Gets shopping cart shipping total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="includingTax">A value indicating whether calculated price should include tax</param>
/// <param name="taxRate">Applied tax rate</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Shipping total</returns>
public virtual decimal? GetShoppingCartShippingTotal(IList<OrganizedShoppingCartItem> cart, bool includingTax,
out decimal taxRate, out Discount appliedDiscount)
{
decimal? shippingTotal = null;
decimal? shippingTotalTaxed = null;
appliedDiscount = null;
taxRate = decimal.Zero;
var customer = cart.GetCustomer();
bool isFreeShipping = IsFreeShipping(cart);
if (isFreeShipping)
return decimal.Zero;
ShippingOption shippingOption = null;
if (customer != null)
shippingOption = customer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _genericAttributeService, _storeContext.CurrentStore.Id);
if (shippingOption != null)
{
//use last shipping option (get from cache)
//adjust shipping rate
var shippingMethods = _shippingService.GetAllShippingMethods();
shippingTotal = AdjustShippingRate(shippingOption.Rate, cart, shippingOption.Name, shippingMethods, out appliedDiscount);
}
else
{
//use fixed rate (if possible)
Address shippingAddress = null;
if (customer != null)
shippingAddress = customer.ShippingAddress;
var shippingRateComputationMethods = _shippingService.LoadActiveShippingRateComputationMethods(_storeContext.CurrentStore.Id);
if (!shippingRateComputationMethods.Any())
throw new SmartException(T("Shipping.CouldNotLoadMethod"));
if (shippingRateComputationMethods.Count() == 1)
{
var getShippingOptionRequest = _shippingService.CreateShippingOptionRequest(cart, shippingAddress, _storeContext.CurrentStore.Id);
var shippingRateComputationMethod = shippingRateComputationMethods.First();
decimal? fixedRate = shippingRateComputationMethod.Value.GetFixedRate(getShippingOptionRequest);
if (fixedRate.HasValue)
{
//adjust shipping rate
shippingTotal = AdjustShippingRate(fixedRate.Value, cart, null, null, out appliedDiscount);
}
}
}
if (shippingTotal.HasValue)
{
if (shippingTotal.Value < decimal.Zero)
shippingTotal = decimal.Zero;
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotal = Math.Round(shippingTotal.Value, 2);
shippingTotalTaxed = _taxService.GetShippingPrice(shippingTotal.Value,
includingTax,
customer,
out taxRate);
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalTaxed = Math.Round(shippingTotalTaxed.Value, 2);
}
return shippingTotalTaxed;
}
示例2: PrepareWishlistModel
protected virtual void PrepareWishlistModel(WishlistModel model,
IList<ShoppingCartItem> cart, bool isEditable = true)
{
if (cart == null)
throw new ArgumentNullException("cart");
if (model == null)
throw new ArgumentNullException("model");
//load settings for a chosen store scope
var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
var AUConsignorSettings = _settings.LoadSetting<Nop.Plugin.Misc.AUConsignor.Domain.AUConsignorSettings>(storeScope);
AUStoreTypeEnum storeType = (AUStoreTypeEnum)AUConsignorSettings.StoreTypeId;
model.StoreType = storeType;
//needed this beyond IsEditable because if don't come in with customer guid from share wishlist email you
//still don;t want them to enter bids if they're a guest
if (_workContext.CurrentCustomer.IsGuest())
{
model.IsGuest = true;
}
else
{
model.IsGuest = false;
}
model.EmailWishlistEnabled = _shoppingCartSettings.EmailWishlistEnabled;
model.IsEditable = isEditable;
model.DisplayAddToCart = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart);
model.DisplayTaxShippingInfo = _catalogSettings.DisplayTaxShippingInfoWishlist;
if (cart.Count == 0)
return;
#region Simple properties
var customer = cart.GetCustomer();
model.CustomerGuid = customer.CustomerGuid;
model.CustomerFullname = customer.GetFullName();
model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart;
model.ShowSku = _catalogSettings.ShowProductSku;
//cart warnings
var cartWarnings = _shoppingCartService.GetShoppingCartWarnings(cart, "", false);
foreach (var warning in cartWarnings)
model.Warnings.Add(warning);
#endregion
#region Cart items
foreach (var sci in cart)
{
var cartItemModel = new WishlistModel.ShoppingCartItemModel
{
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),
LotBidEntry = _lotService.GetLotBidEntryModel(sci.Product.Id)
};
//NJM: count lots as separate from products so can determine if need to show product wishlist and lot wishlist in view
if (cartItemModel.LotBidEntry.ProductIsLot)
{
model.TotalLots += 1;
}
//TODO: fill in the lot bid entry model in the shopping cart only if auction site
//allowed quantities
var allowedQuantities = sci.Product.ParseAllowedQuantities();
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));
//rental info
if (sci.Product.IsRental)
{
var rentalStartDate = sci.RentalStartDateUtc.HasValue ? sci.Product.FormatRentalDate(sci.RentalStartDateUtc.Value) : "";
var rentalEndDate = sci.RentalEndDateUtc.HasValue ? sci.Product.FormatRentalDate(sci.RentalEndDateUtc.Value) : "";
cartItemModel.RentalInfo = string.Format(_localizationService.GetResource("ShoppingCart.Rental.FormattedDate"),
//.........这里部分代码省略.........
示例3: GetShoppingCartTotal
/// <summary>
/// Gets shopping cart total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="appliedGiftCards">Applied gift cards</param>
/// <param name="discountAmount">Applied discount amount</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <param name="redeemedRewardPoints">Reward points to redeem</param>
/// <param name="redeemedRewardPointsAmount">Reward points amount in primary store currency to redeem</param>
/// <param name="ignoreRewardPonts">A value indicating whether we should ignore reward points (if enabled and a customer is going to use them)</param>
/// <param name="usePaymentMethodAdditionalFee">A value indicating whether we should use payment method additional fee when calculating order total</param>
/// <returns>Shopping cart total;Null if shopping cart total couldn't be calculated now</returns>
public virtual decimal? GetShoppingCartTotal(IList<ShoppingCartItem> cart,
out decimal discountAmount, out Discount appliedDiscount,
out List<AppliedGiftCard> appliedGiftCards,
out int redeemedRewardPoints, out decimal redeemedRewardPointsAmount,
bool ignoreRewardPonts = false, bool usePaymentMethodAdditionalFee = true)
{
redeemedRewardPoints = 0;
redeemedRewardPointsAmount = decimal.Zero;
var customer = cart.GetCustomer();
string paymentMethodSystemName = "";
if (customer != null)
{
paymentMethodSystemName = customer.GetAttribute<string>(
SystemCustomerAttributeNames.SelectedPaymentMethod,
_genericAttributeService,
_storeContext.CurrentStore.Id);
}
//subtotal without tax
decimal subtotalBase = decimal.Zero;
decimal orderSubTotalDiscountAmount = decimal.Zero;
Discount orderSubTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
GetShoppingCartSubTotal(cart, false,
out orderSubTotalDiscountAmount, out orderSubTotalAppliedDiscount,
out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
//subtotal with discount
subtotalBase = subTotalWithDiscountBase;
//shipping without tax
decimal? shoppingCartShipping = GetShoppingCartShippingTotal(cart, false);
//payment method additional fee without tax
decimal paymentMethodAdditionalFeeWithoutTax = decimal.Zero;
if (usePaymentMethodAdditionalFee && !String.IsNullOrEmpty(paymentMethodSystemName))
{
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, paymentMethodSystemName);
paymentMethodAdditionalFeeWithoutTax = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee,
false, customer);
}
//tax
decimal shoppingCartTax = GetTaxTotal(cart, usePaymentMethodAdditionalFee);
//order total
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
//.........这里部分代码省略.........
示例4: CreateShippingOptionRequests
/// <summary>
/// Create shipment packages (requests) from shopping cart
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <param name="shippingAddress">Shipping address</param>
/// <returns>Shipment packages (requests)</returns>
public virtual IList<GetShippingOptionRequest> CreateShippingOptionRequests(IList<ShoppingCartItem> cart,
Address shippingAddress)
{
//if we always ship from the default shipping origin, then there's only one request
//if we ship from warehouses, then there could be several requests
//key - warehouse identifier (0 - default shipping origin)
//value - request
var requests = new Dictionary<int, GetShippingOptionRequest>();
foreach (var sci in cart)
{
if (!sci.IsShipEnabled)
continue;
Warehouse warehouse = null;
if (_shippingSettings.UseWarehouseLocation)
{
warehouse = GetWarehouseById(sci.Product.WarehouseId);
}
GetShippingOptionRequest request = null;
if (requests.ContainsKey(warehouse != null ? warehouse.Id : 0))
{
request = requests[warehouse != null ? warehouse.Id : 0];
//add item
request.Items.Add(sci);
}
else
{
request = new GetShippingOptionRequest();
//add item
request.Items.Add(sci);
//customer
request.Customer = cart.GetCustomer();
//ship to
request.ShippingAddress = shippingAddress;
//ship from
Address originAddress = null;
if (warehouse != null)
{
//warehouse address
originAddress = _addressService.GetAddressById(warehouse.AddressId);
}
if (originAddress == null)
{
//no warehouse address. in this case use the default shipping origin
originAddress = _addressService.GetAddressById(_shippingSettings.ShippingOriginAddressId);
}
if (originAddress != null)
{
request.CountryFrom = originAddress.Country;
request.StateProvinceFrom = originAddress.StateProvince;
request.ZipPostalCodeFrom = originAddress.ZipPostalCode;
request.CityFrom = originAddress.City;
request.AddressFrom = originAddress.Address1;
}
requests.Add(warehouse != null ? warehouse.Id : 0, request);
}
}
return requests.Values.ToList();
}
示例5: IsFreeShipping
/// <summary>
/// Gets a value indicating whether shipping is free
/// </summary>
/// <param name="cart">Cart</param>
/// <returns>A value indicating whether shipping is free</returns>
public virtual bool IsFreeShipping(IList<ShoppingCartItem> cart)
{
Customer customer = cart.GetCustomer();
if (customer != null)
{
//check whether customer is in a customer role with free shipping applied
var customerRoles = customer.CustomerRoles.Where(cr => cr.Active);
foreach (var customerRole in customerRoles)
if (customerRole.FreeShipping)
return true;
}
bool shoppingCartRequiresShipping = cart.RequiresShipping();
if (!shoppingCartRequiresShipping)
return true;
//check whether all shopping cart items are marked as free shipping
bool allItemsAreFreeShipping = true;
foreach (var sc in cart)
{
if (sc.IsShipEnabled && !sc.IsFreeShipping)
{
allItemsAreFreeShipping = false;
break;
}
}
if (allItemsAreFreeShipping)
return true;
//free shipping over $X
if (_shippingSettings.FreeShippingOverXEnabled)
{
//check whether we have subtotal enough to have free shipping
decimal subTotalDiscountAmount = decimal.Zero;
Discount subTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
GetShoppingCartSubTotal(cart, _shippingSettings.FreeShippingOverXIncludingTax, out subTotalDiscountAmount,
out subTotalAppliedDiscount, out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
if (subTotalWithDiscountBase > _shippingSettings.FreeShippingOverXValue)
return true;
}
//otherwise, return false
return false;
}
示例6: GetShoppingCartShippingTotal
/// <summary>
/// Gets shopping cart shipping total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="includingTax">A value indicating whether calculated price should include tax</param>
/// <param name="taxRate">Applied tax rate</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Shipping total</returns>
public virtual decimal? GetShoppingCartShippingTotal(IList<ShoppingCartItem> cart, bool includingTax,
out decimal taxRate, out Discount appliedDiscount)
{
decimal? shippingTotal = null;
decimal? shippingTotalTaxed = null;
appliedDiscount = null;
taxRate = decimal.Zero;
var customer = cart.GetCustomer();
bool isFreeShipping = IsFreeShipping(cart);
if (isFreeShipping)
return decimal.Zero;
ShippingOption shippingOption = null;
if (customer != null)
shippingOption = customer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _genericAttributeService, _storeContext.CurrentStore.Id);
if (shippingOption != null)
{
//use last shipping option (get from cache)
//adjust shipping rate
shippingTotal = AdjustShippingRate(shippingOption.Rate, cart, out appliedDiscount);
}
else
{
//use fixed rate (if possible)
Address shippingAddress = null;
if (customer != null)
shippingAddress = customer.ShippingAddress;
var shippingRateComputationMethods = _shippingService.LoadActiveShippingRateComputationMethods(_storeContext.CurrentStore.Id);
if (shippingRateComputationMethods == null || shippingRateComputationMethods.Count == 0)
throw new NopException("Shipping rate computation method could not be loaded");
if (shippingRateComputationMethods.Count == 1)
{
var shippingRateComputationMethod = shippingRateComputationMethods[0];
var shippingOptionRequests = _shippingService.CreateShippingOptionRequests(cart, shippingAddress);
decimal? fixedRate = null;
foreach (var shippingOptionRequest in shippingOptionRequests)
{
//calculate fixed rates for each request-package
var fixedRateTmp = shippingRateComputationMethod.GetFixedRate(shippingOptionRequest);
if (fixedRateTmp.HasValue)
{
if (!fixedRate.HasValue)
fixedRate = decimal.Zero;
fixedRate += fixedRateTmp.Value;
}
}
if (fixedRate.HasValue)
{
//adjust shipping rate
shippingTotal = AdjustShippingRate(fixedRate.Value, cart, out appliedDiscount);
}
}
}
if (shippingTotal.HasValue)
{
if (shippingTotal.Value < decimal.Zero)
shippingTotal = decimal.Zero;
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotal = Math.Round(shippingTotal.Value, 2);
shippingTotalTaxed = _taxService.GetShippingPrice(shippingTotal.Value,
includingTax,
customer,
out taxRate);
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalTaxed = Math.Round(shippingTotalTaxed.Value, 2);
}
return shippingTotalTaxed;
}
示例7: GetShoppingCartShippingTotal
/// <summary>
/// Gets shopping cart shipping total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="includingTax">A value indicating whether calculated price should include tax</param>
/// <param name="taxRate">Applied tax rate</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Shipping total</returns>
public virtual decimal? GetShoppingCartShippingTotal(IList<ShoppingCartItem> cart, bool includingTax,
out decimal taxRate, out Discount appliedDiscount)
{
decimal? shippingTotalWithoutDiscount = null;
decimal? shippingTotalWithDiscount = null;
decimal? shippingTotalWithDiscountTaxed = null;
appliedDiscount = null;
taxRate = decimal.Zero;
var customer = cart.GetCustomer();
bool isFreeShipping = _shippingService.IsFreeShipping(cart);
if (isFreeShipping)
return decimal.Zero;
//free shipping over $X
if (_shippingSettings.FreeShippingOverXEnabled)
{
//check whether we have subtotal enough to have free shipping
decimal subTotalDiscountAmount = decimal.Zero;
Discount subTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
GetShoppingCartSubTotal(cart, includingTax, out subTotalDiscountAmount,
out subTotalAppliedDiscount, out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
if (subTotalWithDiscountBase > _shippingSettings.FreeShippingOverXValue)
return decimal.Zero;
}
ShippingOption lastShippingOption = null;
if (customer != null)
lastShippingOption = customer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.LastShippingOption);
if (lastShippingOption != null)
{
//use last shipping option (get from cache)
//we have already discounted cache value
shippingTotalWithoutDiscount = lastShippingOption.Rate;
//discount
decimal discountAmount = GetShippingDiscount(customer,
shippingTotalWithoutDiscount.Value, out appliedDiscount);
shippingTotalWithDiscount = shippingTotalWithoutDiscount - discountAmount;
if (shippingTotalWithDiscount < decimal.Zero)
shippingTotalWithDiscount = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalWithDiscount = Math.Round(shippingTotalWithDiscount.Value, 2);
}
else
{
//use fixed rate (if possible)
Address shippingAddress = null;
if (customer != null)
shippingAddress = customer.ShippingAddress;
var shippingRateComputationMethods = _shippingService.LoadActiveShippingRateComputationMethods();
if (shippingRateComputationMethods == null || shippingRateComputationMethods.Count == 0)
throw new NopException("Shipping rate computation method could not be loaded");
if (shippingRateComputationMethods.Count == 1)
{
var getShippingOptionRequest = _shippingService.CreateShippingOptionRequest(cart, shippingAddress);
var shippingRateComputationMethod = shippingRateComputationMethods[0];
decimal? fixedRate = shippingRateComputationMethod.GetFixedRate(getShippingOptionRequest);
if (fixedRate.HasValue)
{
decimal additionalShippingCharge = _shippingService.GetShoppingCartAdditionalShippingCharge(cart);
shippingTotalWithoutDiscount = fixedRate.Value + additionalShippingCharge;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalWithoutDiscount = Math.Round(shippingTotalWithoutDiscount.Value, 2);
decimal shippingTotalDiscount = GetShippingDiscount(customer, shippingTotalWithoutDiscount.Value, out appliedDiscount);
shippingTotalWithDiscount = shippingTotalWithoutDiscount.Value - shippingTotalDiscount;
if (shippingTotalWithDiscount.Value < decimal.Zero)
shippingTotalWithDiscount = decimal.Zero;
}
}
}
if (shippingTotalWithDiscount.HasValue)
{
shippingTotalWithDiscountTaxed = _taxService.GetShippingPrice(shippingTotalWithDiscount.Value,
includingTax,
customer,
out taxRate);
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalWithDiscountTaxed = Math.Round(shippingTotalWithDiscountTaxed.Value, 2);
}
//.........这里部分代码省略.........
示例8: CreateShippingOptionRequest
/// <summary>
/// Create shipment package from shopping cart
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <param name="shippingAddress">Shipping address</param>
/// <returns>Shipment package</returns>
public virtual GetShippingOptionRequest CreateShippingOptionRequest(IList<ShoppingCartItem> cart,
Address shippingAddress)
{
var request = new GetShippingOptionRequest();
request.Customer = cart.GetCustomer();
request.Items = new List<ShoppingCartItem>();
foreach (var sc in cart)
if (sc.IsShipEnabled)
request.Items.Add(sc);
request.ShippingAddress = shippingAddress;
request.CountryFrom = null;
request.StateProvinceFrom = null;
request.ZipPostalCodeFrom = string.Empty;
return request;
}
示例9: PrepareOrderTotalsModel
//.........这里部分代码省略.........
displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Count > 0;
displayTax = !displayTaxRates;
model.Tax = _priceFormatter.FormatPrice(shoppingCartTax, true, false);
foreach (var tr in taxRates)
{
model.TaxRates.Add(new OrderTotalsModel.TaxRate
{
Rate = _priceFormatter.FormatTaxRate(tr.Key),
Value = _priceFormatter.FormatPrice(_currencyService.ConvertFromPrimaryStoreCurrency(tr.Value, _workContext.WorkingCurrency), true, false),
});
}
}
}
*/
model.DisplayTaxRates = displayTaxRates;
model.DisplayTax = displayTax;
//Find total taxes from products in cart
var taxRate = _orderTotalCalculationService.GetTaxTotalByCity(cart);
decimal totalTax = 0;
foreach (var item in cart)
{
if (item.Product.IsEnabledAreaRate)
{
//totalTax = totalTax + (taxRate * item.Product.Price);
totalTax = totalTax + (item.Product.Price * item.Quantity);
}
}
totalTax = Math.Round(totalTax * taxRate, 2);
model.Tax = totalTax.ToString();
//apply gift card
var customer = cart.GetCustomer();
string gcCode = _giftCardService.GetCustomerGiftCard(customer);
if (gcCode.Length > 0)
customer.ApplyGiftCardCouponCode(gcCode);
//total
decimal orderTotalDiscountAmountBase;
Discount orderTotalAppliedDiscount;
List<AppliedGiftCard> appliedGiftCards;
int redeemedRewardPoints;
decimal redeemedRewardPointsAmount;
decimal? shoppingCartTotalBase = _orderTotalCalculationService.GetShoppingCartTotal(cart,
out orderTotalDiscountAmountBase, out orderTotalAppliedDiscount,
out appliedGiftCards, out redeemedRewardPoints, out redeemedRewardPointsAmount);
if (shoppingCartTotalBase.HasValue)
{
decimal shoppingCartTotal = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartTotalBase.Value, _workContext.WorkingCurrency);
model.OrderTotal = _priceFormatter.FormatPrice(shoppingCartTotal, true, false);
}
//discount
if (orderTotalDiscountAmountBase > decimal.Zero)
{
decimal orderTotalDiscountAmount = _currencyService.ConvertFromPrimaryStoreCurrency(orderTotalDiscountAmountBase, _workContext.WorkingCurrency);
model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderTotalDiscountAmount, true, false);
model.AllowRemovingOrderTotalDiscount = orderTotalAppliedDiscount != null &&
orderTotalAppliedDiscount.RequiresCouponCode &&
!String.IsNullOrEmpty(orderTotalAppliedDiscount.CouponCode) &&
model.IsEditable;
}
//gift cards
if (appliedGiftCards != null && appliedGiftCards.Count > 0 && blnApplyGiftCard)
示例10: GetShippingOptions
/// <summary>
/// Gets available shipping options
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <param name="shippingAddress">Shipping address</param>
/// <param name="allowedShippingRateComputationMethodSystemName">Filter by shipping rate computation method identifier; null to load shipping options of all shipping rate computation methods</param>
/// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param>
/// <returns>Shipping options</returns>
public virtual GetShippingOptionResponse GetShippingOptions(IList<ShoppingCartItem> cart,
Address shippingAddress, string allowedShippingRateComputationMethodSystemName = "",
int storeId = 0)
{
if (cart == null)
throw new ArgumentNullException("cart");
var result = new GetShippingOptionResponse();
//create a package
bool shippingFromMultipleLocations;
var shippingOptionRequests = CreateShippingOptionRequests(cart, shippingAddress, storeId, out shippingFromMultipleLocations);
result.ShippingFromMultipleLocations = shippingFromMultipleLocations;
var shippingRateComputationMethods = LoadActiveShippingRateComputationMethods(storeId);
//filter by system name
if (!String.IsNullOrWhiteSpace(allowedShippingRateComputationMethodSystemName))
{
shippingRateComputationMethods = shippingRateComputationMethods
.Where(srcm => allowedShippingRateComputationMethodSystemName.Equals(srcm.PluginDescriptor.SystemName, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
if (shippingRateComputationMethods.Count == 0)
throw new NopException("Shipping rate computation method could not be loaded");
//request shipping options from each shipping rate computation methods
foreach (var srcm in shippingRateComputationMethods)
{
//request shipping options (separately for each package-request)
IList<ShippingOption> srcmShippingOptions = null;
foreach (var shippingOptionRequest in shippingOptionRequests)
{
var getShippingOptionResponse = srcm.GetShippingOptions(shippingOptionRequest);
if (getShippingOptionResponse.Success)
{
//success
if (srcmShippingOptions == null)
{
//first shipping option request
srcmShippingOptions = getShippingOptionResponse.ShippingOptions;
}
else
{
//get shipping options which already exist for prior requested packages for this scrm (i.e. common options)
srcmShippingOptions = srcmShippingOptions
.Where(existingso => getShippingOptionResponse.ShippingOptions.Any(newso => newso.Name == existingso.Name))
.ToList();
//and sum the rates
foreach (var existingso in srcmShippingOptions)
{
existingso.Rate += getShippingOptionResponse
.ShippingOptions
.First(newso => newso.Name == existingso.Name)
.Rate;
}
}
}
else
{
//errors
foreach (string error in getShippingOptionResponse.Errors)
{
result.AddError(error);
_logger.Warning(string.Format("Shipping ({0}). {1}", srcm.PluginDescriptor.FriendlyName, error));
}
//clear the shipping options in this case
srcmShippingOptions = new List<ShippingOption>();
break;
}
}
// add this scrm's options to the result
if (srcmShippingOptions != null)
{
foreach (var so in srcmShippingOptions)
{
so.ShippingRateComputationMethodSystemName = srcm.PluginDescriptor.SystemName;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
so.Rate = RoundingHelper.RoundPrice(so.Rate);
//if free shipping exist in customer benefit table, then set so.rate = 0.00
//var customer = cart.CustomerId;
var customerid = cart.GetCustomer().Id;
List<int> freeShipping = _dbContext.SqlQuery<int>("exec CustomerBenefit_Load @CustomerId", new System.Data.SqlClient.SqlParameter("@CustomerId", customerid)).ToList();
//string gcCode = _giftCardService.GetCustomerGiftCard(cart.GetCustomer());
if (freeShipping.Count > 0 && freeShipping[0] != 0)
//.........这里部分代码省略.........
示例11: IsFreeShipping
/// <summary>
/// Gets a value indicating whether shipping is free
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="subTotal">Subtotal amount; pass null to calculate subtotal</param>
/// <returns>A value indicating whether shipping is free</returns>
public virtual bool IsFreeShipping(IList<ShoppingCartItem> cart, decimal? subTotal = null)
{
if (!cart.RequiresShipping())
return true;
//check whether customer is in a customer role with free shipping applied
var customer = cart.GetCustomer();
if (customer != null && customer.CustomerRoles.Where(role => role.Active).Any(role => role.FreeShipping))
return true;
//check whether all shopping cart items are marked as free shipping
if (cart.All(item => item.IsShipEnabled && item.IsFreeShipping))
return true;
//free shipping over $X
if (_shippingSettings.FreeShippingOverXEnabled)
{
if (!subTotal.HasValue)
{
decimal discountAmount;
List<Discount> appliedDiscounts;
decimal subTotalWithoutDiscount;
decimal subTotalWithDiscount;
GetShoppingCartSubTotal(cart, _shippingSettings.FreeShippingOverXIncludingTax, out discountAmount,
out appliedDiscounts, out subTotalWithoutDiscount, out subTotalWithDiscount);
subTotal = subTotalWithDiscount;
}
//check whether we have subtotal enough to have free shipping
if (subTotal.Value > _shippingSettings.FreeShippingOverXValue)
return true;
}
return false;
}
示例12: UpdateOrderTotals
/// <summary>
/// Update order totals
/// </summary>
/// <param name="updateOrderParameters">Parameters for the updating order</param>
/// <param name="restoredCart">Shopping cart</param>
public virtual void UpdateOrderTotals(UpdateOrderParameters updateOrderParameters, IList<ShoppingCartItem> restoredCart)
{
var updatedOrder = updateOrderParameters.UpdatedOrder;
var updatedOrderItem = updateOrderParameters.UpdatedOrderItem;
//get the customer
var customer = restoredCart.GetCustomer();
#region Sub total
var subTotalExclTax = decimal.Zero;
var subTotalInclTax = decimal.Zero;
var subTotalTaxRates = new SortedDictionary<decimal, decimal>();
foreach (var shoppingCartItem in restoredCart)
{
var itemSubTotalExclTax = decimal.Zero;
var itemSubTotalInclTax = decimal.Zero;
var taxRate = decimal.Zero;
var itemDiscounts = new List<Discount>();
//calculate subtotal for the updated order item
if (shoppingCartItem.Id == updatedOrderItem.Id)
{
//update order item
updatedOrderItem.UnitPriceExclTax = updateOrderParameters.PriceExclTax;
updatedOrderItem.UnitPriceInclTax = updateOrderParameters.PriceInclTax;
updatedOrderItem.DiscountAmountExclTax = updateOrderParameters.DiscountAmountExclTax;
updatedOrderItem.DiscountAmountInclTax = updateOrderParameters.DiscountAmountInclTax;
updatedOrderItem.PriceExclTax = itemSubTotalExclTax = updateOrderParameters.SubTotalExclTax;
updatedOrderItem.PriceInclTax = itemSubTotalInclTax = updateOrderParameters.SubTotalInclTax;
updatedOrderItem.Quantity = shoppingCartItem.Quantity;
taxRate = Math.Round((100 * (itemSubTotalInclTax - itemSubTotalExclTax)) / itemSubTotalExclTax, 3);
}
else
{
//get the already calculated subtotal from the order item
itemSubTotalExclTax = updatedOrder.OrderItems.FirstOrDefault(item => item.Id == shoppingCartItem.Id).PriceExclTax;
itemSubTotalInclTax = updatedOrder.OrderItems.FirstOrDefault(item => item.Id == shoppingCartItem.Id).PriceInclTax;
taxRate = Math.Round((100 * (itemSubTotalInclTax - itemSubTotalExclTax)) / itemSubTotalExclTax, 3);
}
foreach (var discount in itemDiscounts)
if (!updateOrderParameters.AppliedDiscounts.ContainsDiscount(discount))
updateOrderParameters.AppliedDiscounts.Add(discount);
subTotalExclTax += itemSubTotalExclTax;
subTotalInclTax += itemSubTotalInclTax;
//tax rates
var itemTaxValue = itemSubTotalInclTax - itemSubTotalExclTax;
if (taxRate > decimal.Zero && itemTaxValue > decimal.Zero)
{
if (!subTotalTaxRates.ContainsKey(taxRate))
subTotalTaxRates.Add(taxRate, itemTaxValue);
else
subTotalTaxRates[taxRate] = subTotalTaxRates[taxRate] + itemTaxValue;
}
}
if (subTotalExclTax < decimal.Zero)
subTotalExclTax = decimal.Zero;
if (subTotalInclTax < decimal.Zero)
subTotalInclTax = decimal.Zero;
//We calculate discount amount on order subtotal excl tax (discount first)
//calculate discount amount ('Applied to order subtotal' discount)
List<Discount> subTotalDiscounts;
var discountAmountExclTax = GetOrderSubtotalDiscount(customer, subTotalExclTax, out subTotalDiscounts);
if (subTotalExclTax < discountAmountExclTax)
discountAmountExclTax = subTotalExclTax;
var discountAmountInclTax = discountAmountExclTax;
//add tax for shopping items
var tempTaxRates = new Dictionary<decimal, decimal>(subTotalTaxRates);
foreach (var kvp in tempTaxRates)
{
if (kvp.Value != decimal.Zero && subTotalExclTax > decimal.Zero)
{
var discountTaxValue = kvp.Value * (discountAmountExclTax / subTotalExclTax);
discountAmountInclTax += discountTaxValue;
subTotalTaxRates[kvp.Key] = kvp.Value - discountTaxValue;
}
}
//rounding
if (_shoppingCartSettings.RoundPricesDuringCalculation)
{
subTotalExclTax = RoundingHelper.RoundPrice(subTotalExclTax);
subTotalInclTax = RoundingHelper.RoundPrice(subTotalInclTax);
discountAmountExclTax = RoundingHelper.RoundPrice(discountAmountExclTax);
discountAmountInclTax = RoundingHelper.RoundPrice(discountAmountInclTax);
}
//.........这里部分代码省略.........
示例13: GetTaxTotalByCity
/// <summary>
/// Gets tax For each City based on Shipping Address
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <param name="taxRates">Tax rates</param>
/// <param name="usePaymentMethodAdditionalFee">A value indicating whether we should use payment method additional fee when calculating tax</param>
/// <returns>Tax total</returns>
public virtual decimal GetTaxTotalByCity(IList<ShoppingCartItem> cart)
{
if (cart == null)
throw new ArgumentNullException("cart");
decimal taxTotal = 0;
var customer = cart.GetCustomer();
if (cart[0].Customer.ShippingAddress != null)
{
var shippingZipcode = cart[0].Customer.ShippingAddress.ZipPostalCode;
//string paymentMethodSystemName = "";
List<TaxRatesByZipcode> taxRate = _dbContext.SqlQuery<TaxRatesByZipcode>("exec TaxRate_Load_ByZipcode @zipcode", new System.Data.SqlClient.SqlParameter("@zipcode", shippingZipcode)).ToList();
//var customerIdParameter = _dataProvider.GetParameter();
//customerIdParameter.ParameterName = "CustomerId";
//customerIdParameter.Value = customer.Id;
//customerIdParameter.DbType = DbType.Int32;
//var taxRates = _dbContext.ExecuteStoredProcedureList<TaxRatesByZipcode>(
// "TaxRate_Load_ByZipcode",
// customerIdParameter);
if (taxRate.Count == 1) //1 row returned
{
taxTotal = taxRate[0].TaxRate;
}
}
return taxTotal;
}
示例14: AdjustShippingRate
/// <summary>
/// Adjust shipping rate (free shipping, additional charges, discounts)
/// </summary>
/// <param name="shippingRate">Shipping rate to adjust</param>
/// <param name="cart">Cart</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Adjusted shipping rate</returns>
public virtual decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedShoppingCartItem> cart,
string shippingMethodName, IList<ShippingMethod> shippingMethods, out Discount appliedDiscount)
{
appliedDiscount = null;
//free shipping
if (IsFreeShipping(cart))
return decimal.Zero;
decimal adjustedRate = decimal.Zero;
decimal bundlePerItemShipping = decimal.Zero;
bool ignoreAdditionalShippingCharge = false;
ShippingMethod shippingMethod;
foreach (var sci in cart)
{
if (sci.Item.Product != null && sci.Item.Product.ProductType == ProductType.BundledProduct && sci.Item.Product.BundlePerItemShipping)
{
if (sci.ChildItems != null)
{
foreach (var childItem in sci.ChildItems.Where(x => x.Item.IsShipEnabled && !x.Item.IsFreeShipping))
bundlePerItemShipping += shippingRate;
}
}
else if (adjustedRate == decimal.Zero)
{
adjustedRate = shippingRate;
}
}
adjustedRate += bundlePerItemShipping;
if (shippingMethodName.HasValue() && shippingMethods != null &&
(shippingMethod = shippingMethods.FirstOrDefault(x => x.Name.IsCaseInsensitiveEqual(shippingMethodName))) != null)
{
ignoreAdditionalShippingCharge = shippingMethod.IgnoreCharges;
}
//additional shipping charges
if (!ignoreAdditionalShippingCharge)
{
decimal additionalShippingCharge = GetShoppingCartAdditionalShippingCharge(cart);
adjustedRate += additionalShippingCharge;
}
//discount
var customer = cart.GetCustomer();
decimal discountAmount = GetShippingDiscount(customer, adjustedRate, out appliedDiscount);
adjustedRate = adjustedRate - discountAmount;
if (adjustedRate < decimal.Zero)
adjustedRate = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
adjustedRate = Math.Round(adjustedRate, 2);
return adjustedRate;
}
示例15: GetShoppingCartShippingTotal
public override decimal? GetShoppingCartShippingTotal(IList<global::Nop.Core.Domain.Orders.ShoppingCartItem> cart, bool includingTax,
out decimal taxRate, out global::Nop.Core.Domain.Discounts.Discount appliedDiscount)
{
if (!_promoSettings.Enabled)
return base.GetShoppingCartShippingTotal(cart, includingTax, out taxRate, out appliedDiscount);
#region old code
BasketResponse basketResponse = _promoUtilities.GetBasketResponse();
decimal? shippingTotal = null;
if (basketResponse == null)
{
return base.GetShoppingCartShippingTotal(cart, includingTax, out taxRate, out appliedDiscount);
}
taxRate = Decimal.Zero;
appliedDiscount = null;
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, we need to ensure we return a zero.
if (cart.Any(sci => sci.IsShipEnabled))
return null;
else
return Decimal.Zero;
}
shippingTotal = basketResponse.DeliveryPrice;
if ((basketResponse.DeliveryPromotionDiscount > Decimal.Zero))
{
if (basketResponse.BasketLevelDiscountIncludesDeliveryAmount())
{
shippingTotal = basketResponse.DeliveryOriginalPrice;
}
else
{
appliedDiscount = new Discount();
appliedDiscount.DiscountAmount = basketResponse.DeliveryPromotionDiscount;
appliedDiscount.Name = basketResponse.DeliveryPromo().PromotionName;
}
}
#endregion
#region new code
decimal? shippingTotalTaxed = shippingTotal;
Customer customer = cart.GetCustomer();
if (shippingTotal.HasValue)
{
if (shippingTotal.Value < decimal.Zero)
shippingTotal = decimal.Zero;
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotal = RoundingHelper.RoundPrice(shippingTotal.Value);
shippingTotalTaxed = _taxService.GetShippingPrice(shippingTotal.Value,
includingTax,
customer,
out taxRate);
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalTaxed = RoundingHelper.RoundPrice(shippingTotalTaxed.Value);
}
#endregion
return shippingTotalTaxed;
}