private void BuildTaxOrderItems(CertiTAX.Order taxOrder, Basket basket, int shipmentId) { if (this.UseLineItems) { WebTrace.Write("Process Tax Items -- Line Items Mode"); LSDecimal productTotal = 0; List <CertiTAX.OrderLineItem> taxLineItems = new List <CertiTAX.OrderLineItem>(); foreach (BasketItem item in basket.Items) { if (item.OrderItemType == OrderItemType.Product) { CertiTAX.OrderLineItem taxLineItem = new CertiTAX.OrderLineItem(); taxLineItem.ItemId = item.ProductId.ToString(); taxLineItem.StockingUnit = item.Sku; taxLineItem.Quantity = item.Quantity; taxLineItem.ExtendedPrice = (Decimal)item.ExtendedPrice; productTotal += item.ExtendedPrice; taxLineItems.Add(taxLineItem); } } taxOrder.LineItems = taxLineItems.ToArray(); taxOrder.Total = (Decimal)productTotal; } else { WebTrace.Write("Process Tax Items -- Order Total Mode"); OrderItemType[] productTypes = { OrderItemType.Product, OrderItemType.Coupon, OrderItemType.Discount }; if (shipmentId == 0) { //SET TOTAL FOR THE BASKET taxOrder.Total = (Decimal)basket.Items.TotalPrice(productTypes); } else { //SET TOTAL FOR THE SHIPMENT BasketShipment shipment = this.GetShipment(basket, shipmentId); if (shipment != null) { taxOrder.Total = (Decimal)shipment.GetItems().TotalPrice(productTypes); } else { taxOrder.Total = 0; } } } }
/// <summary> /// Determines if a coupon applies to a shipment /// </summary> /// <param name="basket">The basket</param> /// <param name="shipment">The basket shipment</param> /// <returns>True if the coupon is valid for the shipment; false otherwise.</returns> public bool AppliesToShipment(Basket basket, BasketShipment shipment) { // DO SOME VALIDATION ON THE INPUT PARAMETERS if (this.CouponType != CouponType.Shipping) { throw new InvalidOperationException("This method is only applicable for shipping coupons."); } if (basket == null) { throw new ArgumentNullException("basket"); } if (shipment == null) { throw new ArgumentNullException("shipment"); } if (basket.BasketId != shipment.BasketId) { throw new ArgumentException("The shipment is not part of the basket."); } // MAKE SURE THE SHIPPING METHOD APPLIES if (!this.AppliesToShipMethod(shipment.ShipMethodId)) { return(false); } // DO WE NEED TO VALIDATE MINIMUM PURCHASE? if (this.MinPurchase > 0) { // GET THE TOTAL PRODUCT PRICE OF THE SHIPMENT BasketItemCollection shipmentItems = shipment.GetItems(basket); LSDecimal totalProductPrice = shipmentItems.TotalProductPrice(); // IF THRESHOLD IS NOT MET, THE COUPON DOES NOT APPLY if (totalProductPrice < this.MinPurchase) { return(false); } } // NOT OTHERWISE INVALID, THE COUPON APPLIES TO SHIPMENT return(true); }