public static OrderAddress FindAddressById(OrderGroup group, string addressId)
		{
			return String.IsNullOrEmpty(addressId)
				       ? null
				       : @group.OrderAddresses.FirstOrDefault(
					       address => address.OrderAddressId.Equals(addressId, StringComparison.OrdinalIgnoreCase));
		}
		/// <summary>
		///     Finds the name of the address by.
		/// </summary>
		/// <param name="group"></param>
		/// <param name="name">The name.</param>
		/// <returns></returns>
		public static OrderAddress FindAddressByName(OrderGroup group, string name)
		{
			return string.IsNullOrEmpty(name)
				       ? null
				       : @group.OrderAddresses.FirstOrDefault(
					       address => address.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
		}
		private TestOrderBuilder(OrderGroup order)
		{
			_order = order;

			var orderForm = new OrderForm { Name = "default", OrderGroupId = _order.OrderGroupId, OrderGroup = _order };
			_order.OrderForms.Add(orderForm);
		}
		private void CalculateTotals(OrderGroup orderGroup)
		{
			decimal subTotal = 0;
			decimal shippingTotal = 0;
			decimal handlingTotal = 0;
			decimal taxTotal = 0;
			decimal total = 0;

			// Calculate totals for OrderForms
			foreach (var form in orderGroup.OrderForms)
			{
				// Calculate totals for order form
				CalculateTotalsOrderForms(form);

				subTotal += form.Subtotal;
				shippingTotal += form.ShippingTotal;
				handlingTotal += form.HandlingTotal;
				taxTotal += form.TaxTotal;
				total += form.Total;
			}

			// calculate OrderGroup totals
			orderGroup.Subtotal = subTotal;
			orderGroup.ShippingTotal = shippingTotal;
			orderGroup.TaxTotal = taxTotal;
			orderGroup.Total = total;
			orderGroup.HandlingTotal = handlingTotal;
		}
		public static bool IsModifyable(this Shipment item, OrderGroup order)
		{
			var shipmentStatus = item.GetCurrentStatus(order);
			var orderStatus = order.GetCurrentStatus();
			var retVal = orderStatus == (orderStatus & ((int)OrderStatus.AwaitingExchange | (int)OrderStatus.InProgress | (int)OrderStatus.PartiallyShipped | (int)OrderStatus.Pending))
						&& (shipmentStatus == ShipmentStatus.AwaitingInventory.ToString() || shipmentStatus == ShipmentStatus.InventoryAssigned.ToString());
			return retVal;
		}
		public static string GetCurrentStatus(this Shipment item, OrderGroup order)
		{
			// shipment inherits onHold status from the order
			if (order.GetCurrentStatus() == (int)OrderStatus.OnHold)
			{
				return ShipmentStatus.OnHold.ToString();
			}

		    return string.IsNullOrEmpty(item.Status) ? ShipmentStatus.InventoryAssigned.ToString() : item.Status;
		}
		public OrderWorkflowResult ExecuteWorkflow(string workflowName, OrderGroup orderGroup)
		{
			var parameters = new Dictionary<string, object>();
			parameters["OrderGroupArgument"] = orderGroup;

			var results = _workflowService.RunWorkflow(workflowName, parameters, new object[] { ServiceLocator.Current });

			var r = new OrderWorkflowResult(results) { OrderGroup = orderGroup };
			return r;
		}
		private void CalculateTotals(OrderGroup orderGroup)
		{
			decimal subTotal = 0;
			decimal shippingTotal = 0;
			decimal handlingTotal = 0;
			decimal taxTotal = 0;
			decimal total = 0;
		    decimal shipmenDiscountTotal = 0;
		    decimal lineItemDiscountTotal = 0;
		    decimal formDiscountTotal = 0;

			// Calculate totals for OrderForms
			foreach (var form in orderGroup.OrderForms)
			{
				// Calculate totals for order form
				CalculateTotalsOrderForms(form);

				subTotal += form.Subtotal;
				shippingTotal += form.ShippingTotal;
				handlingTotal += form.HandlingTotal;
				taxTotal += form.TaxTotal;
				total += form.Total;
			    shipmenDiscountTotal += form.ShipmentDiscountAmount;
			    lineItemDiscountTotal += form.LineItemDiscountAmount;
			    formDiscountTotal += form.DiscountAmount;
			}

			// calculate OrderGroup totals
			orderGroup.Subtotal = subTotal;
			orderGroup.ShippingTotal = shippingTotal;
			orderGroup.TaxTotal = taxTotal;
			orderGroup.Total = total;
			orderGroup.HandlingTotal = handlingTotal;
		    orderGroup.ShipmentDiscountTotal = shipmenDiscountTotal;
		    orderGroup.LineItemDiscountTotal = lineItemDiscountTotal;
		    orderGroup.FormDiscountTotal = formDiscountTotal;
		    orderGroup.DiscountTotal = shipmenDiscountTotal + lineItemDiscountTotal + formDiscountTotal;
		}
        /// <summary>
        /// Runs the workflow.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="orderGroup"></param>
        /// <returns>OrderWorkflowResult.</returns>
        public virtual OrderWorkflowResult RunWorkflow(string name, OrderGroup orderGroup = null)
        {
            orderGroup = orderGroup ?? Cart;
            var result = new OrderService(OrderRepository, SearchService, WorkflowService, null, null).ExecuteWorkflow(name, orderGroup);

            if (result.OrderGroup is ShoppingCart)
            {
                Cart = result.OrderGroup as ShoppingCart;
            }
            return result;
        }
Exemple #10
0
 public OrderBuilder(OrderGroup order)
 {
     _order = order;
 }
        public virtual void ToCart(OrderGroup order)
        {
            if (order == null)
            {
                throw new ArgumentException("order is required","order");
            }

            //Convert order forms to shopping cart
            order.OrderForms.ForEach(f => f.Name = CartName);

            Add(order);

            if (String.IsNullOrEmpty(Cart.BillingCurrency))
            {
                Cart.BillingCurrency = CustomerSession.Currency;
            }

            //Reset();

            // run workflows
            RunWorkflow("ShoppingCartPrepareWorkflow");
            SaveChanges();
        }
		private void CalculateTaxes(OrderGroup order)
		{
			var catalogHelper = new CatalogClient(CatalogRepository, null, null, CacheRepository, null);

			foreach (var form in order.OrderForms)
			{
				decimal totalTaxes = 0;

			    foreach (var shipment in form.Shipments)
				{
					decimal itemTax = 0;
					decimal shippingTax = 0;
					foreach (var shipItem in shipment.ShipmentItems)
					{
						if (shipItem.LineItem == null)
						{
							continue;
						}

						decimal lineItemTaxTotal = 0m;

						// Try getting an address
						var address = GetAddressByName(form, shipment.ShippingAddressId);
						if (address != null) // no taxes if there is no address
						{
							// Try getting an item
							var item = catalogHelper.GetItem(shipItem.LineItem.CatalogItemId);
							if (item != null) // no entry, no tax category, no tax
							{
								var taxCategory = item.TaxCategory;
								// calls the method that returns all the tax values
								var taxes = GetTaxes(taxCategory, Thread.CurrentThread.CurrentCulture.Name, address.CountryCode, address.StateProvince, address.PostalCode, address.RegionName, string.Empty, string.Empty, address.City);

								if (taxes != null && taxes.Any())
								{
									foreach (var tax in taxes)
									{
										if (tax != null)
										{
                                            var taxAmount = Math.Round(shipItem.LineItem.ExtendedPrice * (tax.Percentage / 100), 2);
											if (tax.Tax.TaxType == (int) TaxTypes.SalesTax)
											{
												itemTax += taxAmount;
												lineItemTaxTotal += taxAmount;
												totalTaxes += taxAmount;
											}
											else if (tax.Tax.TaxType == (int) TaxTypes.ShippingTax)
											{
                                                shippingTax += Math.Round(shipment.ShippingCost * (tax.Percentage / 100), 2);
												totalTaxes += shippingTax;
											}
										}
									}
								}
							}
						}
						shipItem.LineItem.TaxTotal = lineItemTaxTotal;
					}

					//TODO Round taxes to money
					shipment.ItemTaxTotal = itemTax;
					shipment.ShippingTaxTotal = shippingTax;
				}
				form.TaxTotal = totalTaxes;
			}
			order.TaxTotal = order.OrderForms.Sum(x=>x.TaxTotal);
		}
Exemple #13
0
 public OrderBuilder()
 {
     _order = new Order();
 }
		private OrderAddress GetAddressByName(OrderGroup orderGroup, string shipmentAddressId)
		{
            return orderGroup.OrderAddresses
				.SingleOrDefault(a => a.OrderAddressId == shipmentAddressId);
		}
 public OrderSearchResults(ISearchCriteria criteria, OrderGroup[] orders, SearchResults results)
 {
     _OrderGroups = orders;
     _TotalCount = results.TotalCount;
     _Count = results.DocCount;
     _FacetGroups = results.FacetGroups;
     _SearchCriteria = criteria;
 }
		protected OrderWorkflowResult InvokeActivity(Activity activity, OrderGroup orderGroup)
		{
			var parameters = new Dictionary<string, object>();
			parameters["OrderGroupArgument"] = orderGroup;

			var retVal = new WorkflowResult();
			parameters["ResultArgument"] = retVal;

			var invoker = new WorkflowInvoker(activity);
			invoker.Extensions.Add(Locator);
			//invoker.Extensions.Add(OrderRepository);
			invoker.Invoke(parameters);

			var r = new OrderWorkflowResult(retVal) { OrderGroup = orderGroup };

			return r;
		}
 /// <summary>
 /// Adds the specified order group to the existing cart.
 /// </summary>
 /// <param name="orderGroup">The order group.</param>
 public virtual void Add(OrderGroup orderGroup)
 {
     Add(orderGroup, false);
 }
		public SaveOrderGroupChangesMessage(OrderGroup order)
		{
			OrderGroup = order;
		}
        /// <summary>
        /// Adds the specified order group to the existing cart.
        /// </summary>
        /// <param name="orderGroup">The order group.</param>
        /// <param name="lineItemRollup">if set to <c>true</c> [line item rollup].</param>
        /// <exception cref="System.ArgumentNullException">orderGroup</exception>
        public virtual void Add(OrderGroup orderGroup, bool lineItemRollup)
        {
            if (orderGroup == null)
            {
                throw new ArgumentNullException("orderGroup");
            }

            if ((orderGroup.OrderForms != null) && (orderGroup.OrderForms.Count != 0))
            {
                // need to set meta data context before cloning
                foreach (var form in orderGroup.OrderForms)
                {
                    var orderForm = Cart.OrderForms.FirstOrDefault(f => f.Name.Equals(form.Name, StringComparison.OrdinalIgnoreCase));
                    if (orderForm == null)
                    {
                        orderForm = new OrderForm { Name = form.Name };
                        Cart.OrderForms.Add(orderForm);
                    }

                    orderForm.OrderGroupId = Cart.OrderGroupId;
                    orderForm.OrderGroup = Cart;

                    var count = form.LineItems.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var newLineItem = new LineItem();

                        // preserve the new id
                        var id = newLineItem.LineItemId;
                        newLineItem.InjectFrom(form.LineItems[i]);
                        newLineItem.LineItemId = id;

                        Add(orderForm, newLineItem, lineItemRollup);
                    }
                }
            }
        }
		protected OrderGroup RunWorkflow(string name, OrderGroup cart)
		{
			var service = Locator.GetInstance<IOrderService>();
			var result = service.ExecuteWorkflow(name, cart);
			//List<string> warnings = result.WorkflowResult.Warnings;
			//if (warnings != null)
			{
				//foreach (string warning in warnings)
				{
					//TODO: generate error message
					//ErrorManager.GenerateError(warning);
				}
			}
			return result.OrderGroup;
		}