Exemplo n.º 1
0
        private void LoadOrder()
        {
            o = MTApp.OrderServices.Orders.FindForCurrentStore(Request.QueryString["id"]);
            if (o != null)
            {
                this.lblOrderNumber.Text = "Order " + o.OrderNumber + " ";
                this.ShippingAddressField.Text = o.ShippingAddress.ToHtmlString();
                this.ShippingTotalLabel.Text = o.TotalShippingAfterDiscounts.ToString("c");

                this.ItemsGridView.DataSource = o.Items;
                this.ItemsGridView.DataBind();

                this.PackagesGridView.DataSource = o.FindShippedPackages();
                this.PackagesGridView.DataBind();

                //this.SuggestedPackagesGridView.DataSource = o.FindSuggestedPackages();
                //this.SuggestedPackagesGridView.DataBind();

                this.UserSelectedShippingMethod.Text = "User Selected Shipping Method: <b>" + o.ShippingMethodDisplayName + "</b>";

                //if (this.lstShippingProvider.Items.FindByValue(o.ShippingProviderId) != null) {
                //    this.lstShippingProvider.ClearSelection();
                //    this.lstShippingProvider.Items.FindByValue(o.ShippingProviderId).Selected = true;
                //    LoadServiceCodes();
                //    this.lstServiceCode.SelectedValue = o.ShippingProviderServiceCode;
                //}
            }
        }
Exemplo n.º 2
0
        public void CanAddItemToOrderAndCalculate()
        {
            
            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 1;

            Order target = new Order();
            LineItem li = new LineItem() { BasePricePerItem = 19.99m, 
                                           ProductName = "Sample Product", 
                                           ProductSku = "ABC123", 
                                           Quantity = 2 };
            target.Items.Add(li);
            app.CalculateOrder(target);
            Assert.AreEqual(39.98m, target.TotalOrderBeforeDiscounts, "SubTotal was Incorrect");
            Assert.AreEqual(39.98m, target.TotalGrand, "Grand Total was incorrect");
            
            bool upsertResult = app.OrderServices.Orders.Upsert(target);
            Assert.IsTrue(upsertResult, "Order Upsert Failed");

            Assert.AreEqual(c.CurrentStore.Id, target.StoreId, "Order store ID was not set correctly");
            Assert.AreNotEqual(string.Empty, target.bvin, "Order failed to get a bvin");
            Assert.AreEqual(1, target.Items.Count, "Item count should be one");
            Assert.AreEqual(target.bvin, target.Items[0].OrderBvin, "Line item didn't receive order bvin");
            Assert.AreEqual(target.StoreId, target.Items[0].StoreId, "Line item didn't recieve storeid");
        }
Exemplo n.º 3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Tag an id to the querystring to support back button
            if (Request.QueryString["id"] != null)
            {
                this.BvinField.Value = Request.QueryString["id"];
            }
            else
            {
                o = new Order();
                MTApp.OrderServices.Orders.Create(o);
                Response.Redirect("CreateOrder.aspx?id=" + o.bvin);
            }

            if (this.BvinField.Value.Trim() != string.Empty)
            {
                o = MTApp.OrderServices.Orders.FindForCurrentStore(this.BvinField.Value);
            }
            if (!Page.IsPostBack)
            {
                LoadOrder();
                LoadPaymentMethods();
                LoadCurrentUser();
            }

            //Me.UserPicker1.MessageBox = MessageBox1
            //AddHandler Me.UserPicker1.UserSelected, AddressOf Me.UserSelected

            //If Me.NewSkuField.Text <> String.Empty Then
            //VariantsDisplay1.Initialize(False)
            //End If

        }
Exemplo n.º 4
0
        public OrderPaymentManager(Order ord, MerchantTribeApplication app)
        {
            o = ord;
            this.MTApp = app;
            svc = MTApp.OrderServices;
            this.contacts = this.MTApp.ContactServices;
            this.content = this.MTApp.ContentServices;

            Accounts.Store CurrentStore = app.CurrentRequestContext.CurrentStore;

            pointsManager = CustomerPointsManager.InstantiateForDatabase(CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent,
                                                        CurrentStore.Settings.RewardsPointsNeededPerDollarCredit,
                                                       app.CurrentRequestContext.CurrentStore.Id);
        }
Exemplo n.º 5
0
 private void ReloadOrder(OrderShippingStatus previousShippingStatus)
 {
     o = MTApp.OrderServices.Orders.FindForCurrentStore(Request.QueryString["id"]);
     o.EvaluateCurrentShippingStatus();
     MTApp.OrderServices.Orders.Update(o);
     MerchantTribe.Commerce.BusinessRules.OrderTaskContext context 
         = new MerchantTribe.Commerce.BusinessRules.OrderTaskContext(MTApp);
     context.Order = o;
     context.UserId = o.UserID;
     context.Inputs.Add("bvsoftware", "PreviousShippingStatus", previousShippingStatus.ToString());
     MerchantTribe.Commerce.BusinessRules.Workflow.RunByName(context, MerchantTribe.Commerce.BusinessRules.WorkflowNames.ShippingChanged);
     LoadOrder();
     this.OrderStatusDisplay1.LoadStatusForOrder(o);
 }
Exemplo n.º 6
0
        public bool Calculate(Order o)
        {
            // reset values
            o.TotalShippingBeforeDiscounts = 0;            
            o.TotalTax = 0;
            o.TotalTax2 = 0;
            o.TotalHandling = 0;

            o.ClearDiscounts();

            if (!SkipRepricing)
            {
                // Price items for current user
                RepriceItemsForUser(o);
            }
    
            // Discount prices for volume ordered
            ApplyVolumeDiscounts(o);            
                    
            //Apply Offers to Line Items and Sub Total
            ApplyOffersToOrder(o, PromotionActionMode.ForLineItems);
            ApplyOffersToOrder(o, PromotionActionMode.ForSubTotal);                

            // Calculate Handling, Merge with Shipping For Display
            o.TotalHandling = CalculateHandlingAmount(o);

            OrdersCalculateShipping(o);            
            
            // Calculate Per Item shipping and handling portion
            //CalculateShippingPortion(o);

            // Apply shipping offers
            ApplyOffersToOrder(o, PromotionActionMode.ForShipping);
            
            // Calcaulte Taxes
            o.ClearTaxes();
            List<Taxes.ITaxSchedule> schedules = _app.OrderServices.TaxSchedules.FindAllAndCreateDefaultAsInterface(o.StoreId);
            Contacts.Address destination = o.ShippingAddress;            
            ApplyTaxes(schedules, o.ItemsAsITaxable(), destination, o);

            // Calculate Sub Total of Items
            foreach (LineItem li in o.Items)
            {
                o.TotalTax += li.TaxPortion;
            }

                                                            
            return true;
        }
Exemplo n.º 7
0
 public CartViewModel()
 {
     CurrentOrder = new Order();
     this.AddCouponButtonUrl = string.Empty;
     this.DeleteButtonUrl = string.Empty;
     this.KeepShoppingButtonUrl = string.Empty;
     this.KeepShoppingUrl = string.Empty;
     this.CheckoutButtonUrl = string.Empty;
     this.EstimateShippingButtonUrl = string.Empty;
     this.DisplayTitle = "Shopping Cart";
     this.DisplaySubTitle = string.Empty;
     this.ItemListTitle = string.Empty;
     this.CartEmpty = false;
     this.LineItems = new List<CartLineItemViewModel>();
     this.PayPalExpressAvailable = false;
 }
        public void LoadStatusForOrder(Order o)
        {

            if (o != null)
            {

                this.litPay.Text = EnumToString.OrderPaymentStatus(o.PaymentStatus);
                this.litShip.Text = EnumToString.OrderShippingStatus(o.ShippingStatus);

                if (lstStatus.Items.FindByValue(o.StatusCode) != null)
                {
                    lstStatus.ClearSelection();
                    lstStatus.Items.FindByValue(o.StatusCode).Selected = true;
                }
            }
        }
Exemplo n.º 9
0
 private void RepriceItemsForUser(Order o)
 {
     foreach (LineItem li in o.Items)
     {                
         Catalog.UserSpecificPrice price = _app.PriceProduct(li.ProductId, o.UserID, li.SelectionData);
         // Null check because if the item isn't in the catalog
         // we will get back a null user specific price. 
         //
         // In the future it may be a good idea to add an option
         // allowing merchant to select if they would like to allow
         // items not in the catalog to exist in carts or if we should
         // just remove items from the cart with a warning here.
         if (price != null)
         {
             li.BasePricePerItem = price.BasePrice;
             foreach (Marketing.DiscountDetail discount in price.DiscountDetails)
             {
                 li.DiscountDetails.Add(new Marketing.DiscountDetail() { Amount = discount.Amount * li.Quantity, Description = discount.Description });
             }
         }
     }
 }      
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            orderId = Request.QueryString["id"];
            o = MyPage.MTApp.OrderServices.Orders.FindForCurrentStore(orderId);
            payManager = new OrderPaymentManager(o, MyPage.MTApp);

            if (!Page.IsPostBack)
            {
                this.mvPayments.SetActiveView(this.viewCreditCards);
                LoadCreditCardLists();

                if (MyPage.MTApp.CurrentStore.PlanId < 2)
                {
                    //this.lnkCash.Visible = false;
                    this.lnkCheck.Visible = false;
                    this.lnkPO.Visible = false;
                }
            }


        }
Exemplo n.º 11
0
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            //string bvin = FirstParameter(parameters);
            ApiResponse<OrderDTO> response = new ApiResponse<OrderDTO>();

            OrderDTO postedItem = null;
            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson<OrderDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return MerchantTribe.Web.Json.ObjectToJson(response);
            }

            Order item = new Order();            
            item.FromDTO(postedItem);

            Order existing = MTApp.OrderServices.Orders.FindForCurrentStore(item.bvin);
            if (existing == null || existing.bvin == string.Empty)
            {
                item.StoreId = MTApp.CurrentStore.Id;
                MTApp.OrderServices.Orders.Create(item);
            }            
            else
            {
                MTApp.OrderServices.Orders.Update(item);
            }
            Order resultItem = MTApp.OrderServices.Orders.FindForCurrentStore(item.bvin);
            if (resultItem != null) response.Content = resultItem.ToDto();

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return data;
        }
Exemplo n.º 12
0
        private decimal CalculateHandlingAmount(Order o)
        {
            Accounts.Store currentStore = _app.CurrentStore;
            if (currentStore == null) return 0;

            if (currentStore.Settings.HandlingType == (int)HandlingMode.PerItem)
            {
                decimal amount = 0;
                foreach (Orders.LineItem item in o.Items)
                {
                    if (item.ShippingSchedule == -1)
                    {
                        if (currentStore.Settings.HandlingNonShipping)
                        {
                            amount += item.Quantity;
                        }
                    }
                    else
                    {
                        amount += item.Quantity;
                    }
                }
                return (currentStore.Settings.HandlingAmount * amount);
            }
            else if (currentStore.Settings.HandlingType == (int)HandlingMode.PerOrder)
            {
                //charge handling if there aren't non shipping items
                if (currentStore.Settings.HandlingNonShipping)
                {
                    foreach (Orders.LineItem item in o.Items)
                    {
                        return currentStore.Settings.HandlingAmount;
                    }
                }
                else
                {
                    foreach (Orders.LineItem item in o.Items)
                    {
                        if (item.ShippingSchedule != -1)
                        {
                            return currentStore.Settings.HandlingAmount;
                        }
                    }
                }
            }

            return 0;
        }
Exemplo n.º 13
0
        private void OrdersCalculateShipping(Order o)
        {
            o.TotalShippingBeforeDiscounts = 0;
            if (o.ShippingMethodId != string.Empty)
            {
                Shipping.ShippingRateDisplay r = _app.OrderServices.OrdersFindShippingRateByUniqueKey(o.ShippingMethodUniqueKey, o, _app.CurrentStore);
                if (r != null)
                {
                    o.ShippingMethodDisplayName = r.DisplayName;
                    o.ShippingProviderId = r.ProviderId;
                    o.ShippingProviderServiceCode = r.ProviderServiceCode;
                    o.TotalShippingBeforeDiscounts = Math.Round(r.Rate, 2);
                    //this.AddPackages(r.SuggestedPackages);
                }
            }

            if (o.TotalShippingBeforeDiscountsOverride >= 0)
            {
                o.TotalShippingBeforeDiscounts = o.TotalShippingBeforeDiscountsOverride;
            }
        }
 public bool CalculateOrderWithoutRepricing(Order o)
 {
     Orders.OrderCalculator calc = new OrderCalculator(this);
     calc.SkipRepricing = true;
     return calc.Calculate(o);
 }
Exemplo n.º 15
0
        private void ApplyVolumeDiscounts(Order o)
        {
            // Count up how many of each item in order
            List<string> products = new List<string>();
            Dictionary<string, int> quantities = new Dictionary<string, int>();
            foreach (LineItem item in o.Items)
            {
                if (!products.Contains(item.ProductId))
                {
                    products.Add(item.ProductId);
                }
                if (quantities.ContainsKey(item.ProductId))
                {
                    quantities[item.ProductId] += (int)item.Quantity;
                }
                else
                {
                    quantities.Add(item.ProductId, (int)item.Quantity);
                }

            }

            // Check for discounts on each item
            foreach (string id in products)
            {
                List<MerchantTribe.Commerce.Catalog.ProductVolumeDiscount> volumeDiscounts = _app.CatalogServices.VolumeDiscounts.FindByProductId(id);
                int quantity = quantities[id];
                MerchantTribe.Commerce.Catalog.ProductVolumeDiscount volumeDiscountToApply = null;
                if (volumeDiscounts.Count > 0)
                {
                    // Locate the correct discount in the chart of discounts
                    foreach (MerchantTribe.Commerce.Catalog.ProductVolumeDiscount volumeDiscount in volumeDiscounts)
                    {
                        if (quantity >= volumeDiscount.Qty)
                        {
                            volumeDiscountToApply = volumeDiscount;
                        }
                    }
                    //now we have to go through the entire order and discount all items
                    //that are this id
                    if (volumeDiscountToApply != null)
                    {
                        foreach (LineItem item in o.Items)
                        {
                            if (item.ProductId == id)
                            {
                                Catalog.Product p = _app.CatalogServices.Products.Find(item.ProductId);
                                if (p != null)
                                {
                                    bool alreadyDiscounted = (p.SitePrice > item.AdjustedPricePerItem);
                                    if (!alreadyDiscounted)
                                    {
                                        // item isn't discounted yet so apply the exact price the merchant set
                                        decimal toDiscount = -1 * (item.AdjustedPricePerItem - volumeDiscountToApply.Amount);
                                        toDiscount = toDiscount * item.Quantity;
                                        item.DiscountDetails.Add(new Marketing.DiscountDetail() { Amount = toDiscount, Description = "Volume Discount" });
                                    }
                                    else
                                    {
                                        // item is already discounted (probably by user group) so figure out
                                        // the percentage of volume discount instead
                                        decimal originalPriceChange = p.SitePrice - volumeDiscountToApply.Amount;
                                        decimal percentChange = originalPriceChange / p.SitePrice;
                                        decimal newDiscount = -1 * (percentChange * item.AdjustedPricePerItem);
                                        newDiscount = newDiscount * item.Quantity;
                                        item.DiscountDetails.Add(new Marketing.DiscountDetail() { Amount = newDiscount, Description = percentChange.ToString("p0") + " Volume Discount" });
                                    }

                                }

                            }
                        }
                    }
                }
            }
        }
        public SystemOperationResult CheckForStockOnItems(Order o)
        {

            // Build a list of product quantities to check
            Dictionary<string, ProductIdCombo> products = new Dictionary<string, ProductIdCombo>();
            foreach (Orders.LineItem item in o.Items)
            {
                ProductIdCombo combo = new ProductIdCombo() { Bvin = item.ProductId, VariantId = item.VariantId, Quantity = item.Quantity };

                if (products.ContainsKey(combo.Key()))
                {
                    products[combo.Key()].Quantity += combo.Quantity;
                }
                else
                {
                    products.Add(combo.Key(), combo);
                }
            }

            // Now check each quantity for the order
            foreach (string key in products.Keys)
            {
                Catalog.Product prod = null;
                Orders.LineItem lineItem = null;
                foreach (LineItem item in o.Items)
                {
                    if (item.ProductId + item.VariantId == key)
                    {
                        //we just need this to get the product 
                        //name if the product is not found
                        lineItem = item;
                        prod = item.GetAssociatedProduct(this);
                        break;
                    }
                }

                if (prod != null)
                {
                    if (prod.Status == Catalog.ProductStatus.Disabled)
                    {
                        return new SystemOperationResult(false, Content.SiteTerms.ReplaceTermVariable(Content.SiteTerms.GetTerm(Content.SiteTermIds.ProductNotAvailable), "productName", prod.ProductName));
                    }

                    ProductIdCombo checkcombo = products[key];

                    Catalog.InventoryCheckData data = CatalogServices.InventoryCheck(prod, checkcombo.VariantId);

                    if (data.IsAvailableForSale)
                    {
                        if (data.IsInStock)
                        {
                            if (data.Qty < checkcombo.Quantity)
                            {
                                string message = Content.SiteTerms.GetTerm(Content.SiteTermIds.CartNotEnoughQuantity);
                                message = Content.SiteTerms.ReplaceTermVariable(message, "ProductName", prod.ProductName);
                                message = Content.SiteTerms.ReplaceTermVariable(message, "Quantity", data.Qty.ToString());
                                return new SystemOperationResult(false, message);
                            }
                        }
                    }
                    else
                    {
                        return new SystemOperationResult(false, Content.SiteTerms.ReplaceTermVariable(Content.SiteTerms.GetTerm(Content.SiteTermIds.CartOutOfStock), "productName", prod.ProductName));
                    }
                }
                else
                {
                    return new SystemOperationResult(false, Content.SiteTerms.ReplaceTermVariable("{productname} is not availble at the moment.", "productName", lineItem.ProductName));
                }
            }

            return new SystemOperationResult(true, string.Empty);
        }
Exemplo n.º 17
0
        private void RenderAnalytics(Order o)
        {
            // Reset Analytics for receipt page
            this.ViewData["PassedAnalyticsTop"] = string.Empty;

            // Add Tracker and Maybe Ecommerce Tracker to Top
            if (MTApp.CurrentStore.Settings.Analytics.UseGoogleTracker)
            {
                if (MTApp.CurrentStore.Settings.Analytics.UseGoogleEcommerce)
                {
                    // Ecommerce + Page Tracker
                    this.ViewData["PassedAnalyticsTop"] = MerchantTribe.Commerce.Metrics.GoogleAnalytics.RenderLatestTrackerAndTransaction(
                        MTApp.CurrentStore.Settings.Analytics.GoogleTrackerId,
                        o,
                        MTApp.CurrentStore.Settings.Analytics.GoogleEcommerceStoreName,
                        MTApp.CurrentStore.Settings.Analytics.GoogleEcommerceCategory);
                }
                else
                {
                    // Page Tracker Only
                    this.ViewData["PassedAnalyticsTop"] = MerchantTribe.Commerce.Metrics.GoogleAnalytics.RenderLatestTracker(MTApp.CurrentStore.Settings.Analytics.GoogleTrackerId);
                }
            }

            // Adwords Tracker at bottom if needed
            if (MTApp.CurrentStore.Settings.Analytics.UseGoogleAdWords)
            {
                this.ViewData["PassedAnalyticsBottom"] += MerchantTribe.Commerce.Metrics.GoogleAnalytics.RenderGoogleAdwordTracker(
                                                        o.TotalGrand,
                                                        MTApp.CurrentStore.Settings.Analytics.GoogleAdWordsId,
                                                        MTApp.CurrentStore.Settings.Analytics.GoogleAdWordsLabel,
                                                        MTApp.CurrentStore.Settings.Analytics.GoogleAdWordsBgColor,
                                                        Request.IsSecureConnection);
            }

            // Add Yahoo Tracker to Bottom if Needed
            if (MTApp.CurrentStore.Settings.Analytics.UseYahooTracker)
            {
                this.ViewData["PassedAnalyticsBottom"] += MerchantTribe.Commerce.Metrics.YahooAnalytics.RenderYahooTracker(
                    o, MTApp.CurrentStore.Settings.Analytics.YahooAccountId);
            }

            //if (ViewBag.HideAnalytics != null)
            //{
            //    if (!(bool)ViewBag.HideAnalytics)
            //    {
            //        System.Text.StringBuilder sbA = new System.Text.StringBuilder();
            //        sbA.Append("<script type=\"text/javascript\">");
            //        sbA.Append("MerchantTribeAnalytics.EventCode = '2';");
            //        sbA.Append("MerchantTribeAnalytics.EventAmount = '@Grand';");
            //        sbA.Append("MerchantTribeAnalytics.EventDescription = '@o.OrderNumber';");
            //        sbA.Append("</script>");
            //        this.ViewData["PassedAnalyticsBottom"] += sbA.ToString();
            //    }
            //}
        }
Exemplo n.º 18
0
        private void PopulateFromOrder(Order o)
        {
            // Header
            this.OrderNumberField.Text = o.OrderNumber;
            this.TimeOfOrderField.Text = TimeZoneInfo.ConvertTimeFromUtc(o.TimeOfOrderUtc, MTApp.CurrentStore.Settings.TimeZone).ToString();

            // Fraud Score Display
            if (o.FraudScore < 0) this.lblFraudScore.Text = "No Fraud Score Data";
            if (o.FraudScore >= 0 && o.FraudScore < 3) this.lblFraudScore.Text = o.FraudScore.ToString() + "<span class=\"fraud-low\"><b>low risk</b></span>";
            if (o.FraudScore >= 3 && o.FraudScore <= 5) this.lblFraudScore.Text = "<span class=\"fraud-medium\"><b>medium risk</b></span>";
            if (o.FraudScore > 5) this.lblFraudScore.Text = "<span class=\"fraud-high\"><b>high risk</b></span>";

            // Billing
            this.BillingAddressField.Text = o.BillingAddress.ToHtmlString();

            //Email
            this.EmailAddressField.Text = MerchantTribe.Commerce.Utilities.MailServices.MailToLink(o.UserEmail, "Order " + o.OrderNumber, o.BillingAddress.FirstName + ",");

            // Shipping (hide if the same as billing address)
            this.pnlShipTo.Visible = true;
            this.ShippingAddressField.Text = o.ShippingAddress.ToHtmlString();

            // Payment
            OrderPaymentSummary paySummary = MTApp.OrderServices.PaymentSummary(o);
            this.lblPaymentSummary.Text = paySummary.PaymentsSummary;
            this.PaymentAuthorizedField.Text = string.Format("{0:C}", paySummary.AmountAuthorized);
            this.PaymentChargedField.Text = string.Format("{0:C}", paySummary.AmountCharged);
            this.PaymentDueField.Text = string.Format("{0:C}", paySummary.AmountDue);
            this.PaymentRefundedField.Text = string.Format("{0:C}", paySummary.AmountRefunded);

            //Items
            this.ItemsGridView.DataSource = o.Items;
            this.ItemsGridView.DataBind();

            // Instructions
            if (o.Instructions.Trim().Length > 0)
            {
                this.pnlInstructions.Visible = true;
                this.InstructionsField.Text = o.Instructions.Replace("\r\n", "<br />").Replace("\r", "<br />").Replace("\n", "<br />");
            }

            // Totals
            this.litTotals.Text = o.TotalsAsTable();

            // Coupons
            this.CouponField.Text = string.Empty;
            for (int i = 0; i <= o.Coupons.Count - 1; i++)
            {
                this.CouponField.Text += o.Coupons[i].CouponCode.Trim().ToUpper() + "<br />";
            }

            // Notes
            Collection<OrderNote> publicNotes = new Collection<OrderNote>();
            Collection<OrderNote> privateNotes = new Collection<OrderNote>();
            for (int i = 0; i <= o.Notes.Count - 1; i++)
            {
                if (o.Notes[i].IsPublic)
                {
                    publicNotes.Add(o.Notes[i]);
                }
                else
                {
                    privateNotes.Add(o.Notes[i]);
                }
            }
            this.PublicNotesField.DataSource = publicNotes;
            this.PublicNotesField.DataBind();
            this.PrivateNotesField.DataSource = privateNotes;
            this.PrivateNotesField.DataBind();
        }
 public bool CalculateOrder(Order o)
 {
     Orders.OrderCalculator calc = new OrderCalculator(this);
     return calc.Calculate(o);
 }
        private bool OrdersUnshipItems(OrderPackage p, Order o)
        {
            bool result = true;

            if (p.Items.Count > 0)
            {
                if (o != null)
                {
                    if (o.bvin != string.Empty)
                    {
                        foreach (OrderPackageItem pi in p.Items)
                        {
                            if (pi.LineItemId > 0)
                            {
                                Orders.LineItem li = o.GetLineItem(pi.LineItemId);
                                if (li != null)
                                {
                                    int quantityToUnship = 0;
                                    if (li.QuantityShipped < pi.Quantity)
                                    {
                                        quantityToUnship = li.QuantityShipped;
                                    }
                                    else
                                    {
                                        quantityToUnship = pi.Quantity;
                                    }
                                    CatalogServices.InventoryLineItemUnShipQuantity(li, quantityToUnship);
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
        public decimal OrderPackagesFindDeclaredValue(OrderPackage p, Order o)
        {
            decimal result = 0m;
            if (o != null)
            {
                foreach (OrderPackageItem pi in p.Items)
                {
                    foreach (Orders.LineItem li in o.Items)
                    {
                        if (li.Id == pi.LineItemId)
                        {
                            decimal lineValue = 0m;
                            lineValue = li.AdjustedPricePerItem * pi.Quantity;
                            result += lineValue;
                            break;
                        }
                    }
                }
            }

            return result;
        }
 public bool CalculateOrderAndSaveWithoutRepricing(Order o)
 {
     if (!CalculateOrderWithoutRepricing(o)) return false;
     return OrderServices.Orders.Upsert(o);
 }
 public bool OrdersShipPackage(OrderPackage p, Order o)
 {
     p.HasShipped = true;
     OrdersShipItems(p, o);
     BusinessRules.OrderTaskContext c = new BusinessRules.OrderTaskContext(this);
     c.Order = o;
     c.UserId = this.CurrentCustomerId;
     if (!BusinessRules.Workflow.RunByName(c, BusinessRules.WorkflowNames.PackageShipped))
     {
         EventLog.LogEvent("PackageShippedWorkflow", "Package Shipped Workflow Failed", EventLogSeverity.Debug);
         foreach (BusinessRules.WorkflowMessage item in c.Errors)
         {
             EventLog.LogEvent("PackageShippedWorkflow", item.Description, EventLogSeverity.Debug);
         }
     }
     return true;
 }
 // Order Packages
 public bool OrdersShipAllPackages(Order o)
 {
     foreach (OrderPackage p in o.Packages)
     {
         if (!p.HasShipped)
         {
             OrdersShipPackage(p, o);
         }
     }
     OrderServices.Orders.Update(o);
     return true;
 }
Exemplo n.º 25
0
        private void ApplyOffersToOrder(Order o, PromotionActionMode mode)
        {
            if (o == null) return;
            Membership.CustomerAccount currentUser = null;
            if (o.UserID != string.Empty) currentUser = _app.MembershipServices.Customers.Find(o.UserID);

            List<Marketing.Promotion> offers = _app.MarketingServices.Promotions.FindAllPotentiallyActiveOffers(DateTime.UtcNow);
            foreach (Marketing.Promotion offer in offers)
            {
                offer.ApplyToOrder(_app, o, currentUser, DateTime.UtcNow, mode);
            }
        }
 public bool CalculateOrderAndSave(Order o)
 {
     if (!CalculateOrder(o)) return false;
     return OrderServices.Orders.Upsert(o);
 }
Exemplo n.º 27
0
        private OrderPackage ShipItems(Order o, string trackingNumber, string serviceProvider, string serviceCode, bool dontShip)
        {
            OrderPackage p = new OrderPackage();

            p.ShipDateUtc = DateTime.UtcNow;
            p.TrackingNumber = trackingNumber;
            p.ShippingProviderId = serviceProvider;
            p.ShippingProviderServiceCode = serviceCode;
            foreach (GridViewRow gvr in this.ItemsGridView.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    LineItem li = o.GetLineItem((long)this.ItemsGridView.DataKeys[gvr.RowIndex].Value);
                    if (li != null)
                    {

                        int qty = 0;
                        TextBox QtyToShip = (TextBox)gvr.FindControl("QtyToShip");
                        if (QtyToShip != null)
                        {
                            if (!int.TryParse(QtyToShip.Text, out qty))
                            {
                                qty = 0;
                            }
                        }
                        p.Items.Add(new OrderPackageItem(li.ProductId, li.Id, qty));
                        p.Weight += (li.ProductShippingWeight * qty);
                    }
                }
            }
            p.WeightUnits = WebAppSettings.ApplicationWeightUnits;

            o.Packages.Add(p);            
            if (!dontShip)
            {
                MTApp.OrdersShipPackage(p, o);
            }
            MTApp.OrderServices.Orders.Update(o);

            return p;
        }
        private void LoadShippingMethodsForOrder(Order o)
        {
            SortableCollection<ShippingRateDisplay> rates = MTApp.OrderServices.FindAvailableShippingRates(o);

            string rateKey = o.ShippingMethodUniqueKey;
            bool rateIsAvailable = false;

            // See if rate is available
            if ((rateKey.Length > 0))
            {
                foreach (MerchantTribe.Commerce.Shipping.ShippingRateDisplay r in rates)
                {
                    if ((r.UniqueKey == rateKey))
                    {
                        rateIsAvailable = true;
                        MTApp.OrderServices.OrdersRequestShippingMethod(r, o);
                    }
                }
            }

            // if it's not availabe, pick the first one or default
            if ((rateIsAvailable == false))
            {
                if ((rates.Count > 0))
                {
                    MTApp.OrderServices.OrdersRequestShippingMethod(rates[0], o);
                    rateKey = rates[0].UniqueKey;
                }
                else
                {
                    o.ClearShippingPricesAndMethod();
                }
            }

            ViewBag.ShippingRates = HtmlRendering.ShippingRatesToRadioButtons(rates, 300, o.ShippingMethodUniqueKey);
        }
        private bool OrdersShipItems(OrderPackage p, Order o)
        {
            bool result = true;

            if (p.Items.Count > 0)
            {
                if (o != null)
                {
                    if (o.bvin != string.Empty)
                    {
                        foreach (OrderPackageItem pi in p.Items)
                        {
                            if (pi.LineItemId > 0)
                            {
                                Orders.LineItem li = o.GetLineItem(pi.LineItemId);
                                if (li != null)
                                {
                                    if (pi.Quantity > (li.Quantity - li.QuantityShipped))
                                    {
                                        pi.Quantity = li.Quantity - li.QuantityShipped;
                                    }

                                    if (pi.Quantity <= 0)
                                    {
                                        pi.Quantity = 0;
                                    }
                                    else
                                    {
                                        CatalogServices.InventoryLineItemShipQuantity(li, pi.Quantity);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
 public bool AddToOrderWithCalculateAndSave(Order o, LineItem li)
 {
     o.Items.Add(li);
     CalculateOrder(o);
     return OrderServices.Orders.Upsert(o);
 }