コード例 #1
0
ファイル: StepConfirm.ascx.cs プロジェクト: gkovalev/nastia
    private void UpdateBasket()
    {
        try
        {
            var shpCart = ShoppingCartService.CurrentShoppingCart;

            if (shpCart.Count > 0)
            {
                lvOrderList.DataSource = shpCart;
                lvOrderList.DataBind();
                lvOrderList.Visible = true;
                pnlSummary.Visible  = true;
            }
            else
            {
                lvOrderList.Visible = false;
                pnlSummary.Visible  = false;
            }

            decimal totalPrice           = shpCart.TotalPrice;
            decimal discountOnTotalPrice = shpCart.DiscountPercentOnTotalPrice;
            decimal totalDiscount        = shpCart.TotalDiscount;
            decimal shippingPrice        = PageData.SelectShippingRate;


            lblTotalOrderPrice.Text = CatalogService.GetStringPrice(shpCart.TotalPrice);

            if (discountOnTotalPrice > 0)
            {
                discountRow.Visible   = true;
                lblOrderDiscount.Text = string.Format(
                    "<span class=\"per\">-{0}%</span><span class=\"price\">{1}</span>", discountOnTotalPrice,
                    CatalogService.GetStringPrice(totalPrice * discountOnTotalPrice / 100));
            }
            else
            {
                discountRow.Visible = false;
            }

            if (shpCart.Certificate != null)
            {
                certificateRow.Visible   = true;
                lblCertificatePrice.Text = String.Format("-{0}",
                                                         CatalogService.GetStringPrice(shpCart.Certificate.Sum, 1,
                                                                                       shpCart.Certificate.CurrencyCode,
                                                                                       shpCart.Certificate.CurrencyValue));
            }

            if (shpCart.Coupon != null)
            {
                couponRow.Visible = true;
                if (shpCart.TotalPrice < shpCart.Coupon.MinimalOrderPrice)
                {
                    lblCouponPrice.Text = String.Format(Resource.Client_OrderConfirmation_CouponMessage,
                                                        CatalogService.GetStringPrice(shpCart.Coupon.MinimalOrderPrice));
                }
                else
                {
                    if (totalDiscount == 0)
                    {
                        lblCouponPrice.Text = String.Format("-{0} ({1})", CatalogService.GetStringPrice(0), shpCart.Coupon.Code);
                    }
                    else
                    {
                        switch (shpCart.Coupon.Type)
                        {
                        case CouponType.Fixed:
                            lblCouponPrice.Text = String.Format("-{0} ({1})", CatalogService.GetStringPrice(totalDiscount), shpCart.Coupon.Code);
                            break;

                        case CouponType.Percent:
                            lblCouponPrice.Text = String.Format("-{0} ({1}%) ({2})", CatalogService.GetStringPrice(totalDiscount),
                                                                CatalogService.FormatPriceInvariant(shpCart.Coupon.Value), shpCart.Coupon.Code);
                            break;
                        }
                    }
                }
            }

            if (PageData.SelectedPaymentType == PaymentType.CashOnDelivery && PageData.ShippingOptionEx != null)
            {
                shippingPrice = PageData.ShippingOptionEx.PriceCash;
            }

            var     billingContact  = PageData.BillingContact;
            var     shippingContact = PageData.ShippingContact;
            decimal taxesTotal      = shpCart.Sum(item => TaxServices.CalculateTaxesTotal(item, shippingContact, billingContact));
            var     taxesItems      = GetTaxItems(shpCart, shippingContact, billingContact);

            decimal dblTotalPrice = (totalPrice + shippingPrice + taxesTotal - totalDiscount);

            lblTotalOrderPrice.Text = CatalogService.GetStringPrice(totalPrice);
            lblShippingPrice.Text   = @"+" + CatalogService.GetStringPrice(shippingPrice);
            if (taxesItems.Count > 0)
            {
                literalTaxCost.Text = BuildTaxTable(taxesItems, CurrencyService.CurrentCurrency.Value, CurrencyService.CurrentCurrency.Iso3, Resource.Admin_ViewOrder_Taxes);
            }
            lblTotalPrice.Text = CatalogService.GetStringPrice(dblTotalPrice > 0 ? dblTotalPrice : 0);
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
            Message = ex.Message + " at UpdateBasket";
        }
    }