public override LSDecimal Calculate(CommerceBuilder.Orders.Basket basket) { if (basket.Items.Count == 0) { return(0); } Dictionary <string, string> existingTransactions = ClearExistingTaxes(basket); switch (this.Nexus) { case Nexus.PointOfBilling: return(Calculate_PointOfBilling(basket, existingTransactions)); case Nexus.PointOfDelivery: return(Calculate_PointOfDelivery(basket, existingTransactions)); case Nexus.PointOfSale: return(Calculate_PointOfSale(basket, existingTransactions)); case Nexus.PointOfShipping: return(Calculate_PointOfShipping(basket, existingTransactions)); default: throw new ApplicationException("Unrecognized Nexus: " + this.Nexus.ToString()); } }
public override void Cancel(CommerceBuilder.Orders.Basket basket) { WebTrace.Write("Cancel Existing Taxes"); List <string> uniqueTransactionIds = new List <string>(); Dictionary <string, string> existingTransactions = ClearExistingTaxes(basket); CertiTAX.CertiCalc comm = new CertiTAX.CertiCalc(); foreach (string transactionId in existingTransactions.Values) { if (uniqueTransactionIds.IndexOf(transactionId) < 0) { uniqueTransactionIds.Add(transactionId); comm.Cancel(transactionId, CT_SERIAL_NUMBER, this.ReferredID); } } }
/// <summary> /// Converts basket items that represent gift certificate payments into basket payment objects. /// </summary> /// <param name="basket">The basket to convert</param> /// <returns>A list of BasketPaymentItems generated from the gift certificate basket items.</returns> /// <remarks>This step is taken just prior to conversion of basket to order. The basket is modified by removing the /// gift certificate basket items and converting them to payment placeholders.</remarks> internal static List <BasketPaymentItem> ConvertGiftCertificateItemsToPayments(Basket basket) { List <BasketPaymentItem> giftCertificatePayments = new List <BasketPaymentItem>(); for (int i = basket.Items.Count - 1; i >= 0; i--) { BasketItem item = basket.Items[i]; if (item.OrderItemType == OrderItemType.GiftCertificatePayment) { BasketPaymentItem payItem = new BasketPaymentItem(); payItem.OrderItemType = OrderItemType.GiftCertificatePayment; payItem.Name = item.Name; payItem.AccountData = item.Sku; payItem.Amount = -item.ExtendedPrice; giftCertificatePayments.Add(payItem); basket.Items.DeleteAt(i); } } return(giftCertificatePayments); }
/// <summary> /// Converts kit product assoications into order line items for a basket that is /// being finalized. /// </summary> /// <param name="basket">The basket checking out</param> /// <param name="order">The order being created</param> /// <param name="idLookup">A translation table to map basket ids to order ids</param> internal static void GenerateKitProducts(Basket basket, Order order, Dictionary <string, int> idLookup) { foreach (BasketItem basketItem in basket.Items) { if (basketItem.OrderItemType == OrderItemType.Product) { int[] kitProductIds = AlwaysConvert.ToIntArray(basketItem.KitList); if (kitProductIds != null && kitProductIds.Length > 0) { //keep track of the price/weight of the master line item //decrement these values for each line item registered LSDecimal masterPrice = basketItem.Price; LSDecimal masterWeight = basketItem.Weight; foreach (int kitProductId in kitProductIds) { // WE ONLY NEED TO GENERATE RECORDS FOR THE HIDDEN ITEMS // VISIBLE KIT MBMER PRODUCTS ARE GENERATED DURING THE BASKET RECALCULATION KitProduct kp = KitProductDataSource.Load(kitProductId); if (kp.KitComponent.InputType == KitInputType.IncludedHidden) { Product p = kp.Product; ProductVariant pv = kp.ProductVariant; OrderItem item = new OrderItem(); item.OrderId = order.OrderId; // SET THE PARENT ITEM ID FOR THIS ITEM if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { item.ParentItemId = idLookup["I" + basketItem.BasketItemId]; } item.OrderItemType = OrderItemType.Product; if (idLookup.ContainsKey("S" + basketItem.BasketShipmentId)) { item.OrderShipmentId = idLookup["S" + basketItem.BasketShipmentId]; } if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { item.ParentItemId = idLookup["I" + basketItem.BasketItemId]; } item.ProductId = kp.ProductId; item.Name = kp.DisplayName; item.OptionList = kp.OptionList; if (pv != null) { item.VariantName = pv.VariantName; item.Sku = pv.Sku; } else { item.Sku = p.Sku; } item.Quantity = (short)(kp.Quantity * basketItem.Quantity); item.TaxCodeId = p.TaxCodeId; //THE CALCULATED PRICE IS FOR ALL ITEMS (EXT PRICE) //TO GET A LINE ITEM PRICE WE MUST DIVIDE BY QUANTITY item.Price = kp.CalculatedPrice / kp.Quantity; item.Weight = kp.CalculatedWeight / kp.Quantity; item.CostOfGoods = p.CostOfGoods; item.WishlistItemId = basketItem.WishlistItemId; item.WrapStyleId = basketItem.WrapStyleId; item.IsHidden = (kp.KitComponent.InputType == KitInputType.IncludedHidden); //USE PARENT SHIPPABLE STATUS FOR HIDDEN KITTED PRODUCTS item.Shippable = basketItem.Shippable; item.Save(); order.Items.Add(item); masterPrice -= kp.CalculatedPrice; masterWeight -= kp.CalculatedWeight; } } //UPDATE THE PRICE OF THE KIT LINE ITEM (BASE PRICE OF PRODUCT LESS KIT PARTS) if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { int index = order.Items.IndexOf(idLookup["I" + basketItem.BasketItemId]); if (index > -1) { order.Items[index].Price = masterPrice; order.Items[index].Weight = masterWeight; order.Items[index].Save(); } } } } } }
/// <summary> /// Generates order items from the basket data /// </summary> /// <param name="basket">The basket checking out</param> /// <param name="order">The order being created</param> /// <param name="idLookup">A translation table to map basket ids to order ids</param> /// <remarks>This method does not modify the basket object</remarks> internal static void GenerateOrderItemObjects(Basket basket, Order order, Dictionary <string, int> idLookup) { //MAKE SURE ITEMS ARE SORTED SO THAT THE IDLOOKUP IS VALID //(WE NEED TO PROCESS PARENT ITEMS BEFORE CHILD ITEMS) basket.Items.Sort(new BasketItemComparer()); foreach (BasketItem bi in basket.Items) { OrderItem oi = new OrderItem(); if (idLookup.ContainsKey("I" + bi.ParentItemId)) { oi.ParentItemId = idLookup["I" + bi.ParentItemId]; } oi.OrderId = order.OrderId; if (idLookup.ContainsKey("S" + bi.BasketShipmentId)) { oi.OrderShipmentId = idLookup["S" + bi.BasketShipmentId]; } oi.ProductId = bi.ProductId; oi.OptionList = bi.OptionList; if (bi.ProductVariant != null) { oi.VariantName = bi.ProductVariant.VariantName; if (bi.ProductVariant.CostOfGoods > 0) { oi.CostOfGoods = bi.ProductVariant.CostOfGoods; } } oi.TaxCodeId = bi.TaxCodeId; oi.ShippableId = bi.ShippableId; oi.Name = bi.Name; oi.Sku = bi.Sku; oi.Price = bi.Price; oi.Weight = bi.Weight; if (bi.Product != null && oi.CostOfGoods == 0) { oi.CostOfGoods = bi.Product.CostOfGoods; } oi.Quantity = bi.Quantity; oi.LineMessage = bi.LineMessage; oi.OrderItemTypeId = bi.OrderItemTypeId; oi.OrderBy = bi.OrderBy; oi.WrapStyleId = bi.WrapStyleId; oi.GiftMessage = bi.GiftMessage; oi.WishlistItemId = bi.WishlistItemId; oi.InventoryStatus = InventoryStatus.None; oi.TaxRate = bi.TaxRate; oi.TaxAmount = bi.TaxAmount; oi.KitList = bi.KitList; if (oi.Product != null && oi.Product.Kit.ItemizeDisplay) { oi.ItemizeChildProducts = true; } order.Items.Add(oi); // COPY THE CUSTOM FIELDS foreach (KeyValuePair <string, string> customField in bi.CustomFields) { oi.CustomFields.Add(customField.Key, customField.Value); } oi.Save(); idLookup.Add("I" + bi.BasketItemId, oi.OrderItemId); //COPY ANY ITEM INPUTS foreach (BasketItemInput bii in bi.Inputs) { InputField inputField = bii.InputField; if (inputField != null) { OrderItemInput oii = new OrderItemInput(); oii.OrderItemId = oi.OrderItemId; oii.IsMerchantField = inputField.IsMerchantField; oii.Name = inputField.Name; oii.InputValue = bii.InputValue; oi.Inputs.Add(oii); oii.Save(); // SAVE THE ASSOCIATION AS WELL oi.Inputs.Save(); } } } }