Exemple #1
0
        private void BindData()
        {
            if (!OrderManager.RewardPointsEnabled)
            {
                this.Visible = false;
                return;
            }
            int     rewardPointsBalance    = NopContext.Current.User.RewardPointsBalance;
            decimal rewardPointsAmountBase = OrderManager.ConvertRewardPointsToAmount(rewardPointsBalance);
            decimal rewardPointsAmount     = CurrencyManager.ConvertCurrency(rewardPointsAmountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

            lblBalance.Text = GetLocaleResourceString("Customer.RewardPoints.CurrentBalance", rewardPointsBalance, PriceHelper.FormatPrice(rewardPointsAmount, true, false));
            //lblRate.Text = GetLocaleResourceString("Customer.RewardPoints.CurrentRate", PriceHelper.FormatPrice(CurrencyManager.ConvertCurrency(OrderManager.RewardPointsForPurchases_Amount, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency), true, false), OrderManager.RewardPointsForPurchases_Points);
            lblRate.Visible = false;

            var rphc = NopContext.Current.User.RewardPointsHistory;

            if (rphc.Count > 0)
            {
                gvRewardPoints.Visible    = true;
                lblHistoryMessage.Visible = false;
                gvRewardPoints.DataSource = rphc;
                gvRewardPoints.DataBind();
            }
            else
            {
                gvRewardPoints.Visible    = false;
                lblHistoryMessage.Visible = true;
                lblHistoryMessage.Text    = GetLocaleResourceString("Customer.RewardPoints.NoHistory");
            }
        }
Exemple #2
0
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            var     sb = new StringBuilder();
            decimal shoppingCartItemSubTotalWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, true));
            decimal shoppingCartItemSubTotalWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string  subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

            sb.Append("<span class=\"productPrice\">");
            sb.Append(subTotalString);
            sb.Append("</span>");

            decimal shoppingCartItemDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetDiscountAmount(shoppingCartItem));

            if (shoppingCartItemDiscountBase > decimal.Zero)
            {
                decimal shoppingCartItemDiscount = CurrencyManager.ConvertCurrency(shoppingCartItemDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                sb.Append("<br />");
                sb.Append(GetLocaleResourceString("Wishlist.ItemYouSave"));
                sb.Append("&nbsp;&nbsp;");
                sb.Append(discountString);
            }
            return(sb.ToString());
        }
Exemple #3
0
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            StringBuilder sb      = new StringBuilder();
            decimal       taxRate = decimal.Zero;
            decimal       shoppingCartItemSubTotalWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), customer, out taxRate);
            decimal       shoppingCartItemSubTotalWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string        subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

            sb.Append(subTotalString);

            decimal shoppingCartItemDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetDiscountAmount(shoppingCartItem, customer), customer, out taxRate);

            if (shoppingCartItemDiscountBase > decimal.Zero)
            {
                decimal shoppingCartItemDiscount = CurrencyManager.ConvertCurrency(shoppingCartItemDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                sb.Append("<br />");
                //sb.Append(GetLocaleResourceString("ShoppingCart.ItemYouSave"));
                sb.Append("Saved:");
                sb.Append("&nbsp;&nbsp;");
                sb.Append(discountString);
            }
            return(sb.ToString());
        }
Exemple #4
0
        protected void ddlVariantPrice_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var productVariant  = e.Item.DataItem as ProductVariant;
                var lblPriceDisplay = e.Item.FindControl("lblPriceDisplay") as Label;
                var lblPrice        = e.Item.FindControl("lblPrice") as Label;
                var imgBuyNow       = e.Item.FindControl("imgBuyNow") as ImageButton;

                if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    if (productVariant.CustomerEntersPrice)
                    {
                        int minimumCustomerEnteredPrice = Convert.ToInt32(Math.Ceiling(CurrencyManager.ConvertCurrency(productVariant.MinimumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                        lblPrice.Text        = minimumCustomerEnteredPrice.ToString();
                        lblPriceDisplay.Text = PriceHelper.FormatPrice(minimumCustomerEnteredPrice);
                    }
                    else
                    {
                        decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                        decimal fromPrice     = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                        lblPrice.Text        = fromPrice.ToString();
                        lblPriceDisplay.Text = PriceHelper.FormatPrice(fromPrice);
                    }
                }
                else
                {
                    lblPriceDisplay.Visible = false;
                    btnAddToCart.Visible    = false;
                }
            }
        }
Exemple #5
0
        protected string FormatShippingOption(ShippingOption shippingOption)
        {
            decimal rateBase = TaxManager.GetShippingPrice(shippingOption.Rate, NopContext.Current.User);
            decimal rate     = CurrencyManager.ConvertCurrency(rateBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string  rateStr  = PriceHelper.FormatShippingPrice(rate, true);

            return(string.Format("({0})", rateStr));
        }
        public string GetShoppingCartItemUnitPriceString(ShoppingCartItem shoppingCartItem)
        {
            StringBuilder sb = new StringBuilder();
            decimal       shoppingCartUnitPriceWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetUnitPrice(shoppingCartItem, customer, true), customer);
            decimal       shoppingCartUnitPriceWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartUnitPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string        unitPriceString = PriceHelper.FormatPrice(shoppingCartUnitPriceWithDiscount);

            sb.Append(unitPriceString);
            return(sb.ToString());
        }
Exemple #7
0
        private void BindData()
        {
            ProductVariant productVariant = ProductManager.GetProductVariantByID(this.ProductVariantID);

            if (productVariant != null)
            {
                decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice);
                decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                decimal finalPriceWithDiscountBase    = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true));

                decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                decimal finalPriceWithDiscount    = CurrencyManager.ConvertCurrency(finalPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                {
                    lblOldPrice.Text   = PriceHelper.FormatPrice(oldPrice);
                    lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                    phOldPrice.Visible = true;
                }
                else
                {
                    lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                    phOldPrice.Visible = false;
                }

                if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                {
                    lblFinalPriceWithDiscount.Text = PriceHelper.FormatPrice(finalPriceWithDiscount);
                    phDiscount.Visible             = true;
                }
                else
                {
                    phDiscount.Visible = false;
                }

                if (phDiscount.Visible)
                {
                    lblPriceValue.CssClass = string.Empty;
                }
                else
                {
                    lblPriceValue.CssClass = "productPrice";
                }

                if (phDiscount.Visible || phOldPrice.Visible)
                {
                    lblPrice.Text = GetLocaleResourceString("Products.FinalPriceWithoutDiscount");
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Exemple #8
0
        protected void rptrTaxRates_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var item = (KeyValuePair <decimal, decimal>)e.Item.DataItem;

                var lTaxRateTitle = e.Item.FindControl("lTaxRateTitle") as Literal;
                lTaxRateTitle.Text = String.Format(GetLocaleResourceString("ShoppingCart.Totals.TaxRate"), TaxManager.FormatTaxRate(item.Key));

                var     lTaxRateValue = e.Item.FindControl("lTaxRateValue") as Literal;
                decimal taxValue      = CurrencyManager.ConvertCurrency(item.Value, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                lTaxRateValue.Text = PriceHelper.FormatPrice(taxValue, true, false);
            }
        }
        /// <summary>
        /// Formats attributes
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="Attributes">Attributes</param>
        /// <param name="customer">Customer</param>
        /// <param name="Serapator">Serapator</param>
        /// <param name="HTMLEncode">A value indicating whether to encode (HTML) values</param>
        /// <returns>Attributes</returns>
        public static string FormatAttributes(ProductVariant productVariant, string Attributes,
                                              Customer customer, string Serapator, bool HTMLEncode)
        {
            StringBuilder result = new StringBuilder();

            ProductVariantAttributeCollection pvaCollection = ParseProductVariantAttributes(Attributes);

            foreach (ProductVariantAttribute pva in pvaCollection)
            {
                List <string> valuesStr = ParseValues(Attributes, pva.ProductVariantAttributeID);
                foreach (string valueStr in valuesStr)
                {
                    string pvaAttribute = string.Empty;
                    if (!pva.ShouldHaveValues)
                    {
                        pvaAttribute = string.Format("{0}: {1}", pva.ProductAttribute.Name, valueStr);
                    }
                    else
                    {
                        ProductVariantAttributeValue pvaValue = ProductAttributeManager.GetProductVariantAttributeValueByID(Convert.ToInt32(valueStr));
                        if (pvaValue != null)
                        {
                            pvaAttribute = string.Format("{0}: {1}", pva.ProductAttribute.Name, pvaValue.Name);
                            decimal priceAdjustmentBase = TaxManager.GetPrice(productVariant, pvaValue.PriceAdjustment, customer);
                            decimal priceAdjustment     = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            if (priceAdjustmentBase > 0)
                            {
                                string priceAdjustmentStr = PriceHelper.FormatPrice(priceAdjustment, false, false);
                                pvaAttribute += string.Format(" [+{0}]", priceAdjustmentStr);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(pvaAttribute))
                    {
                        result.Append(Serapator);
                        if (HTMLEncode)
                        {
                            result.Append(HttpUtility.HtmlEncode(pvaAttribute));
                        }
                        else
                        {
                            result.Append(pvaAttribute);
                        }
                    }
                }
            }
            return(result.ToString());
        }
Exemple #10
0
        protected string GetOrderSubtotal(ShoppingCart shoppingCart)
        {
            decimal subtotalBase  = decimal.Zero;
            string  SubTotalError = ShoppingCartManager.GetShoppingCartSubTotal(shoppingCart,
                                                                                NopContext.Current.User, out subtotalBase);

            if (String.IsNullOrEmpty(SubTotalError))
            {
                decimal subTotal = CurrencyManager.ConvertCurrency(subtotalBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                return(PriceHelper.FormatPrice(subTotal));
            }
            else
            {
                return(GetLocaleResourceString("MiniShoppingCartBox.OrderSubtotal.CalculatedDuringCheckout"));
            }
        }
Exemple #11
0
        protected string FormatPaymentMethodInfo(PaymentMethod paymentMethod)
        {
            decimal paymentMethodAdditionalFee = PaymentManager.GetAdditionalHandlingFee(paymentMethod.PaymentMethodID);
            decimal rateBase = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, NopContext.Current.User);
            decimal rate     = CurrencyManager.ConvertCurrency(rateBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

            if (rate > decimal.Zero)
            {
                string rateStr = PriceHelper.FormatPaymentMethodAdditionalFee(rate, true);
                return(string.Format("({0})", rateStr));
            }
            else
            {
                return(string.Empty);
            }
        }
        protected string FormatShippingOption(ShippingOption shippingOption)
        {
            //calculate discounted and taxed rate
            Discount appliedDiscount = null;
            decimal shippingTotalWithoutDiscount = shippingOption.Rate;
            decimal discountAmount = ShippingManager.GetShippingDiscount(NopContext.Current.User, 
                shippingTotalWithoutDiscount, out appliedDiscount);
            decimal shippingTotalWithDiscount = shippingTotalWithoutDiscount - discountAmount;
            if (shippingTotalWithDiscount < decimal.Zero)
                shippingTotalWithDiscount = decimal.Zero;
            shippingTotalWithDiscount = Math.Round(shippingTotalWithDiscount, 2);

            decimal rateBase = TaxManager.GetShippingPrice(shippingTotalWithDiscount, NopContext.Current.User);
            decimal rate = CurrencyManager.ConvertCurrency(rateBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string rateStr = PriceHelper.FormatShippingPrice(rate, true);
            return string.Format("({0})", rateStr);
        }
Exemple #13
0
        public string GetShoppingCartItemUnitPriceString(ShoppingCartItem shoppingCartItem)
        {
            StringBuilder sb = new StringBuilder();
            decimal       shoppingCartUnitPriceWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetUnitPrice(shoppingCartItem, true));
            decimal       shoppingCartUnitPriceWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartUnitPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

            string unitPriceString = PriceHelper.FormatPrice(shoppingCartUnitPriceWithDiscount);

            if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
            {
                unitPriceString += "$";
            }

            sb.Append("<span class=\"productPrice\">");
            sb.Append(unitPriceString);
            sb.Append("</span>");
            return(sb.ToString());
        }
Exemple #14
0
        protected void lvTierPrices_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem currentItem    = (ListViewDataItem)e.Item;
                TierPrice        tierPrice      = currentItem.DataItem as TierPrice;
                ProductVariant   productVariant = tierPrice.ProductVariant;

                Label lblQuantity = (Label)currentItem.FindControl("lblQuantity");
                Label lblPrice    = (Label)currentItem.FindControl("lblPrice");

                decimal priceBase = TaxManager.GetPrice(productVariant, tierPrice.Price);
                decimal price     = CurrencyManager.ConvertCurrency(priceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                string priceStr = PriceHelper.FormatPrice(price, false, false);
                lblQuantity.Text = string.Format(GetLocaleResourceString("Products.TierPricesQuantityFormat"), tierPrice.Quantity);
                lblPrice.Text    = priceStr;
            }
        }
Exemple #15
0
        public void BindData()
        {
            //min order amount validation
            int paymentMethodId = 0;

            if (NopContext.Current.User != null)
            {
                paymentMethodId = NopContext.Current.User.LastPaymentMethodId;
            }

            decimal  discountAmountBase             = decimal.Zero;
            Discount appliedDiscount                = null;
            List <AppliedGiftCard> appliedGiftCards = null;
            int     redeemedRewardPoints            = 0;
            decimal redeemedRewardPointsAmount      = decimal.Zero;
            bool    useRewardPoints = false;

            if (NopContext.Current.User != null)
            {
                useRewardPoints = NopContext.Current.User.UseRewardPointsDuringCheckout;
            }
            decimal?shoppingCartTotalBase = ShoppingCartManager.GetShoppingCartTotal(this.Cart,
                                                                                     paymentMethodId, NopContext.Current.User,
                                                                                     out discountAmountBase, out appliedDiscount,
                                                                                     out appliedGiftCards, useRewardPoints,
                                                                                     out redeemedRewardPoints, out redeemedRewardPointsAmount);

            if (shoppingCartTotalBase.HasValue)
            {
                if (shoppingCartTotalBase.Value < OrderManager.MinOrderAmount)
                {
                    decimal minOrderAmount = CurrencyManager.ConvertCurrency(OrderManager.MinOrderAmount, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    lMinOrderAmount.Text    = string.Format(GetLocaleResourceString("Checkout.MinOrderAmount"), PriceHelper.FormatPrice(minOrderAmount, true, false));
                    lMinOrderAmount.Visible = true;
                    btnNextStep.Visible     = false;
                }
                else
                {
                    lMinOrderAmount.Visible = false;
                    btnNextStep.Visible     = true;
                }
            }
        }
Exemple #16
0
        public string GetShoppingCartItemUnitPriceString(ShoppingCartItem shoppingCartItem)
        {
            var sb = new StringBuilder();

            if (shoppingCartItem.ProductVariant.CallForPrice)
            {
                sb.Append("<span class=\"productPrice\">");
                sb.Append(GetLocaleResourceString("Products.CallForPrice"));
                sb.Append("</span>");
            }
            else
            {
                decimal taxRate = decimal.Zero;
                decimal shoppingCartUnitPriceWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetUnitPrice(shoppingCartItem, true), out taxRate);
                decimal shoppingCartUnitPriceWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartUnitPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  unitPriceString = PriceHelper.FormatPrice(shoppingCartUnitPriceWithDiscount);
                sb.Append("<span class=\"productPrice\">");
                sb.Append(unitPriceString);
                sb.Append("</span>");
            }
            return(sb.ToString());
        }
Exemple #17
0
        protected void rptrGiftCards_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var appliedGiftCard = e.Item.DataItem as AppliedGiftCard;

                var lGiftCard = e.Item.FindControl("lGiftCard") as Literal;
                lGiftCard.Text = String.Format(GetLocaleResourceString("ShoppingCart.Totals.GiftCardInfo"), Server.HtmlEncode(appliedGiftCard.GiftCard.GiftCardCouponCode));

                var     lblGiftCardAmount = e.Item.FindControl("lblGiftCardAmount") as Label;
                decimal amountCanBeUsed   = CurrencyManager.ConvertCurrency(appliedGiftCard.AmountCanBeUsed, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                lblGiftCardAmount.Text = PriceHelper.FormatPrice(-amountCanBeUsed, true, false);

                var     lGiftCardRemaining  = e.Item.FindControl("lGiftCardRemaining") as Literal;
                decimal remainingAmountBase = GiftCardHelper.GetGiftCardRemainingAmount(appliedGiftCard.GiftCard) - appliedGiftCard.AmountCanBeUsed;
                decimal remainingAmount     = CurrencyManager.ConvertCurrency(remainingAmountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                lGiftCardRemaining.Text = string.Format(GetLocaleResourceString("ShoppingCart.Totals.GiftCardInfo.Remaining"), PriceHelper.FormatPrice(remainingAmount, true, false));

                var btnRemoveGC = e.Item.FindControl("btnRemoveGC") as LinkButton;
                btnRemoveGC.Visible = this.IsShoppingCart;
            }
        }
Exemple #18
0
        protected override void OnPreRender(EventArgs e)
        {
            if (SettingManager.GetSettingValueBoolean("ProductAttribute.EnableDynamicPriceUpdate"))
            {
                var productVariant = ProductManager.GetProductVariantById(this.ProductVariantId);
                if (productVariant != null)
                {
                    decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                    decimal finalPriceWithoutDiscount     = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    decimal finalPriceWithDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true));
                    decimal finalPriceWithDiscount     = CurrencyManager.ConvertCurrency(finalPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    float  val    = (float)(finalPriceWithoutDiscountBase != finalPriceWithDiscountBase ? finalPriceWithDiscount : finalPriceWithoutDiscount);
                    string key    = String.Format("PriceValForDynUpd_{0}", productVariant.ProductVariantId);
                    string script = String.Format(CultureInfo.InvariantCulture, "var priceValForDynUpd_{0} = {1};", productVariant.ProductVariantId, val);

                    Page.ClientScript.RegisterClientScriptBlock(GetType(), key, script, true);
                }
            }
            base.OnPreRender(e);
        }
        protected string GetShoppingCartSum()
        {
            ShoppingCart cart                   = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
            bool         isUsd                  = Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD";
            decimal      indOrderTotal          = 0;
            IndividualOrderCollection indOrders = new IndividualOrderCollection();

            if (NopContext.Current.Session != null)
            {
                Guid customerSessionGuid = NopContext.Current.Session.CustomerSessionGUID;
                indOrders     = IndividualOrderManager.GetIndividualOrderByCurrentUserSessionGuid(customerSessionGuid);
                indOrderTotal = IndividualOrderManager.GetTotalPriceIndOrders(indOrders);
                if (isUsd)
                {
                    indOrderTotal = Math.Round(PriceConverter.ToUsd(indOrderTotal));
                }
            }

            if (cart.Count > 0 || indOrders.Count > 0)
            {
                //subtotal
                string  subTotalError = string.Empty;
                decimal shoppingCartSubTotalDiscountBase;
                decimal shoppingCartSubTotalBase = ShoppingCartManager.GetShoppingCartSubTotal(cart, NopContext.Current.User,
                                                                                               out shoppingCartSubTotalDiscountBase,
                                                                                               ref subTotalError);
                if (String.IsNullOrEmpty(subTotalError))
                {
                    decimal shoppingCartSubTotal = CurrencyManager.ConvertCurrency(shoppingCartSubTotalBase,
                                                                                   CurrencyManager.PrimaryStoreCurrency,
                                                                                   NopContext.Current.WorkingCurrency);
                    shoppingCartSubTotal += indOrderTotal;
                    return(AddCurrency(PriceHelper.FormatPrice(shoppingCartSubTotal), isUsd));
                }
            }

            return(AddCurrency("0", isUsd));
        }
Exemple #20
0
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            var sb = new StringBuilder();

            if (shoppingCartItem.ProductVariant.CallForPrice)
            {
                sb.Append("<span class=\"productPrice\">");
                sb.Append(GetLocaleResourceString("Products.CallForPrice"));
                sb.Append("</span>");
            }
            else
            {
                //sub total
                decimal taxRate = decimal.Zero;
                decimal shoppingCartItemSubTotalWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, true), out taxRate);
                decimal shoppingCartItemSubTotalWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

                sb.Append("<span class=\"productPrice\">");
                sb.Append(subTotalString);
                sb.Append("</span>");

                //display an applied discount amount
                decimal shoppingCartItemSubTotalWithoutDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, false), out taxRate);
                decimal shoppingCartItemDiscountBase = shoppingCartItemSubTotalWithoutDiscountBase - shoppingCartItemSubTotalWithDiscountBase;
                if (shoppingCartItemDiscountBase > decimal.Zero)
                {
                    decimal shoppingCartItemDiscount = CurrencyManager.ConvertCurrency(shoppingCartItemDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                    sb.Append("<br />");
                    sb.Append(GetLocaleResourceString("ShoppingCart.ItemYouSave"));
                    sb.Append("&nbsp;&nbsp;");
                    sb.Append(discountString);
                }
            }
            return(sb.ToString());
        }
Exemple #21
0
        protected void dlRelatedProducts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                RelatedProduct relatedProduct = e.Item.DataItem as RelatedProduct;
                Product        product        = relatedProduct.Product2;

                if (relatedProduct != null && product != null)
                {
                    string productURL = SEOHelper.GetProductURL(product);

                    Label lblPrice = e.Item.FindControl("lblPrice") as Label;

                    if (product.ProductVariants.Count > 0)
                    {
                        if (!product.HasMultipleVariants)
                        {
                            ProductVariant productVariant = product.ProductVariants[0];

                            decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice);
                            decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));

                            decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                            lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscountBase);
                        }
                        else
                        {
                            ProductVariant productVariant = product.MinimalPriceProductVariant;
                            if (productVariant != null)
                            {
                                decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                decimal fromPrice     = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                            }
                        }
                    }
                    Image hlImageLink = e.Item.FindControl("hlImageLink") as Image;
                    if (hlImageLink != null)
                    {
                        ProductPictureCollection productPictures = product.ProductPictures;
                        if (productPictures.Count > 0)
                        {
                            hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 84), true);
                        }
                        else
                        {
                            hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 84));
                        }
                        //hlImageLink.NavigateUrl = productURL;
                        //hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                        //hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    }

                    HyperLink hlProduct = e.Item.FindControl("hlProduct") as HyperLink;
                    if (hlProduct != null)
                    {
                        hlProduct.NavigateUrl = productURL;
                        //hlProduct.Text = product.Name;
                    }
                }
            }
        }
        protected void BindData()
        {
            var category = CategoryManager.GetCategoryById(this.CategoryId);

            //breadcrumb
            rptrCategoryBreadcrumb.DataSource = CategoryManager.GetBreadCrumb(this.CategoryId);
            rptrCategoryBreadcrumb.DataBind();

            lDescription.Text = category.Description;

            //subcategories
            var subCategoryCollection = CategoryManager.GetAllCategories(this.CategoryId);

            if (subCategoryCollection.Count > 0)
            {
                rptrSubCategories.DataSource = subCategoryCollection;
                rptrSubCategories.DataBind();
            }
            else
            {
                rptrSubCategories.Visible = false;
            }

            //featured products
            var featuredProducts = category.FeaturedProducts;

            if (featuredProducts.Count > 0)
            {
                dlFeaturedProducts.DataSource = featuredProducts;
                dlFeaturedProducts.DataBind();
            }
            else
            {
                pnlFeaturedProducts.Visible = false;
            }

            //price ranges
            this.ctrlPriceRangeFilter.PriceRanges = category.PriceRanges;

            //page size
            int totalRecords = 0;
            int pageSize     = 10;

            if (category.PageSize > 0)
            {
                pageSize = category.PageSize;
            }

            //price ranges
            decimal?minPrice          = null;
            decimal?maxPrice          = null;
            decimal?minPriceConverted = null;
            decimal?maxPriceConverted = null;

            if (ctrlPriceRangeFilter.SelectedPriceRange != null)
            {
                minPrice = ctrlPriceRangeFilter.SelectedPriceRange.From;
                if (minPrice.HasValue)
                {
                    minPriceConverted = CurrencyManager.ConvertCurrency(minPrice.Value, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                }

                maxPrice = ctrlPriceRangeFilter.SelectedPriceRange.To;
                if (maxPrice.HasValue)
                {
                    maxPriceConverted = CurrencyManager.ConvertCurrency(maxPrice.Value, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                }
            }

            //specification filter
            var psoFilterOption = ctrlProductSpecificationFilter.GetAlreadyFilteredSpecOptionIds();

            //sorting
            ProductSortingEnum orderBy = ProductSortingEnum.Position;

            if (SettingManager.GetSettingValueBoolean("Common.AllowProductSorting"))
            {
                CommonHelper.SelectListItem(this.ddlSorting, CommonHelper.QueryStringInt("orderby"));
                orderBy = (ProductSortingEnum)Enum.ToObject(typeof(ProductSortingEnum), int.Parse(ddlSorting.SelectedItem.Value));
            }

            var productCollection = ProductManager.GetAllProducts(this.CategoryId,
                                                                  0, 0, false, minPriceConverted, maxPriceConverted,
                                                                  string.Empty, false, pageSize, this.CurrentPageIndex,
                                                                  psoFilterOption, orderBy, out totalRecords);

            if (productCollection.Count > 0)
            {
                this.catalogPager.PageSize     = pageSize;
                this.catalogPager.TotalRecords = totalRecords;
                this.catalogPager.PageIndex    = this.CurrentPageIndex;

                this.lvCatalog.DataSource = productCollection;
                this.lvCatalog.DataBind();
            }
            else
            {
                this.lvCatalog.Visible  = false;
                this.pnlSorting.Visible = false;
            }
        }
Exemple #23
0
        protected void rptVariants_OnItemCommand(Object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart" || e.CommandName == "AddToWishlist")
            {
                var txtQuantity             = e.Item.FindControl("txtQuantity") as NumericTextBox;
                var txtCustomerEnteredPrice = e.Item.FindControl("txtCustomerEnteredPrice") as NumericTextBox;
                var productVariantId        = e.Item.FindControl("ProductVariantId") as Label;
                var ctrlProductAttributes   = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
                var txtRecipientName        = e.Item.FindControl("txtRecipientName") as TextBox;
                var txtRecipientEmail       = e.Item.FindControl("txtRecipientEmail") as TextBox;
                var txtSenderName           = e.Item.FindControl("txtSenderName") as TextBox;
                var txtSenderEmail          = e.Item.FindControl("txtSenderEmail") as TextBox;
                var txtGiftCardMessage      = e.Item.FindControl("txtGiftCardMessage") as TextBox;
                var lblError = e.Item.FindControl("lblError") as Label;

                var pv = ProductManager.GetProductVariantById(Convert.ToInt32(productVariantId.Text));
                if (pv == null)
                {
                    return;
                }

                string  attributes                    = ctrlProductAttributes.SelectedAttributes;
                decimal customerEnteredPrice          = txtCustomerEnteredPrice.Value;
                decimal customerEnteredPriceConverted = CurrencyManager.ConvertCurrency(customerEnteredPrice, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                int     quantity = txtQuantity.Value;

                //gift cards
                if (pv.IsGiftCard)
                {
                    string recipientName   = txtRecipientName.Text;
                    string recipientEmail  = txtRecipientEmail.Text;
                    string senderName      = txtSenderName.Text;
                    string senderEmail     = txtSenderEmail.Text;
                    string giftCardMessage = txtGiftCardMessage.Text;

                    attributes = ProductAttributeHelper.AddGiftCardAttribute(attributes,
                                                                             recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
                }

                try
                {
                    if (e.CommandName == "AddToCart")
                    {
                        string        sep = "<br />";
                        List <string> addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.ShoppingCart,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/shoppingcart.aspx");
                        }
                        else
                        {
                            StringBuilder addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }

                    if (e.CommandName == "AddToWishlist")
                    {
                        string sep = "<br />";
                        var    addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.Wishlist,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect("~/wishlist.aspx");
                        }
                        else
                        {
                            var addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.CustomerError, exc.Message, exc);
                    lblError.Text = Server.HtmlEncode(exc.Message);
                }
            }
        }
Exemple #24
0
        protected void rptVariants_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var productVariant          = e.Item.DataItem as ProductVariant;
                var pnlDownloadSample       = e.Item.FindControl("pnlDownloadSample") as Panel;
                var hlDownloadSample        = e.Item.FindControl("hlDownloadSample") as HyperLink;
                var iProductVariantPicture  = e.Item.FindControl("iProductVariantPicture") as Image;
                var pnlStockAvailablity     = e.Item.FindControl("pnlStockAvailablity") as Panel;
                var lblStockAvailablity     = e.Item.FindControl("lblStockAvailablity") as Label;
                var pnlGiftCardInfo         = e.Item.FindControl("pnlGiftCardInfo") as Panel;
                var txtSenderName           = e.Item.FindControl("txtSenderName") as TextBox;
                var txtSenderEmail          = e.Item.FindControl("txtSenderEmail") as TextBox;
                var txtCustomerEnteredPrice = e.Item.FindControl("txtCustomerEnteredPrice") as NumericTextBox;
                var txtQuantity             = e.Item.FindControl("txtQuantity") as NumericTextBox;
                var btnAddToCart            = e.Item.FindControl("btnAddToCart") as Button;
                var btnAddToWishlist        = e.Item.FindControl("btnAddToWishlist") as Button;

                if (iProductVariantPicture != null)
                {
                    var    productVariantPicture = productVariant.Picture;
                    string pictureUrl            = PictureManager.GetPictureUrl(productVariantPicture, SettingManager.GetSettingValueInteger("Media.Product.VariantImageSize", 125), false);
                    if (String.IsNullOrEmpty(pictureUrl))
                    {
                        iProductVariantPicture.Visible = false;
                    }
                    else
                    {
                        iProductVariantPicture.ImageUrl = pictureUrl;
                    }
                    iProductVariantPicture.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), productVariant.Name);
                    iProductVariantPicture.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), productVariant.Name);
                }

                btnAddToWishlist.Visible = SettingManager.GetSettingValueBoolean("Common.EnableWishlist");

                //stock
                if (pnlStockAvailablity != null && lblStockAvailablity != null)
                {
                    if (productVariant.ManageInventory == (int)ManageInventoryMethodEnum.ManageStock &&
                        productVariant.DisplayStockAvailability)
                    {
                        if (productVariant.StockQuantity > 0 || productVariant.AllowOutOfStockOrders)
                        {
                            lblStockAvailablity.Text = string.Format(GetLocaleResourceString("Products.Availability"), GetLocaleResourceString("Products.InStock"));
                        }
                        else
                        {
                            lblStockAvailablity.Text = string.Format(GetLocaleResourceString("Products.Availability"), GetLocaleResourceString("Products.OutOfStock"));
                        }
                    }
                    else
                    {
                        pnlStockAvailablity.Visible = false;
                    }
                }

                //gift cards
                if (pnlGiftCardInfo != null)
                {
                    if (productVariant.IsGiftCard)
                    {
                        pnlGiftCardInfo.Visible = true;
                        if (NopContext.Current.User != null && !NopContext.Current.User.IsGuest)
                        {
                            txtSenderName.Text  = NopContext.Current.User.FullName;
                            txtSenderEmail.Text = NopContext.Current.User.Email;
                        }
                    }
                    else
                    {
                        pnlGiftCardInfo.Visible = false;
                    }
                }

                //price entered by a customer
                if (productVariant.CustomerEntersPrice)
                {
                    int minimumCustomerEnteredPrice = Convert.ToInt32(Math.Ceiling(CurrencyManager.ConvertCurrency(productVariant.MinimumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                    int maximumCustomerEnteredPrice = Convert.ToInt32(Math.Truncate(CurrencyManager.ConvertCurrency(productVariant.MaximumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                    txtCustomerEnteredPrice.Visible           = true;
                    txtCustomerEnteredPrice.ValidationGroup   = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    txtCustomerEnteredPrice.Value             = minimumCustomerEnteredPrice;
                    txtCustomerEnteredPrice.MinimumValue      = minimumCustomerEnteredPrice.ToString();
                    txtCustomerEnteredPrice.MaximumValue      = maximumCustomerEnteredPrice.ToString();
                    txtCustomerEnteredPrice.RangeErrorMessage = string.Format(GetLocaleResourceString("Products.CustomerEnteredPrice.Range"), minimumCustomerEnteredPrice, maximumCustomerEnteredPrice);
                }
                else
                {
                    txtCustomerEnteredPrice.Visible = false;
                }

                //buttons
                if (!productVariant.DisableBuyButton)
                {
                    txtQuantity.ValidationGroup      = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    btnAddToCart.ValidationGroup     = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    btnAddToWishlist.ValidationGroup = string.Format("ProductVariant{0}", productVariant.ProductVariantId);

                    txtQuantity.Value = productVariant.OrderMinimumQuantity;
                }
                else
                {
                    txtQuantity.Visible      = false;
                    btnAddToCart.Visible     = false;
                    btnAddToWishlist.Visible = false;
                }

                //sample downloads
                if (pnlDownloadSample != null && hlDownloadSample != null)
                {
                    if (productVariant.IsDownload && productVariant.HasSampleDownload)
                    {
                        pnlDownloadSample.Visible    = true;
                        hlDownloadSample.NavigateUrl = DownloadManager.GetSampleDownloadUrl(productVariant);
                    }
                    else
                    {
                        pnlDownloadSample.Visible = false;
                    }
                }

                //final check - hide prices for non-registered customers
                if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    //
                }
                else
                {
                    txtCustomerEnteredPrice.Visible = false;
                    txtQuantity.Visible             = false;
                    btnAddToCart.Visible            = false;
                    btnAddToWishlist.Visible        = false;
                }
            }
        }
        /// <summary>
        /// Formats attributes
        /// </summary>
        /// <param name="attributes">Attributes</param>
        /// <param name="customer">Customer</param>
        /// <param name="serapator">Serapator</param>
        /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param>
        /// <param name="renderPrices">A value indicating whether to render prices</param>
        /// <returns>Attributes</returns>
        public static string FormatAttributes(string attributes,
                                              Customer customer, string serapator, bool htmlEncode, bool renderPrices)
        {
            var result = new StringBuilder();

            var caCollection = ParseCheckoutAttributes(attributes);

            for (int i = 0; i < caCollection.Count; i++)
            {
                var ca        = caCollection[i];
                var valuesStr = ParseValues(attributes, ca.CheckoutAttributeId);
                for (int j = 0; j < valuesStr.Count; j++)
                {
                    string valueStr    = valuesStr[j];
                    string caAttribute = string.Empty;
                    if (!ca.ShouldHaveValues)
                    {
                        if (ca.AttributeControlType == AttributeControlTypeEnum.MultilineTextbox)
                        {
                            caAttribute = string.Format("{0}: {1}", ca.LocalizedName, HtmlHelper.FormatText(valueStr, false, true, true, false, false, false));
                        }
                        else
                        {
                            caAttribute = string.Format("{0}: {1}", ca.LocalizedName, valueStr);
                        }
                    }
                    else
                    {
                        var caValue = CheckoutAttributeManager.GetCheckoutAttributeValueById(Convert.ToInt32(valueStr));
                        if (caValue != null)
                        {
                            caAttribute = string.Format("{0}: {1}", ca.LocalizedName, caValue.LocalizedName);
                            if (renderPrices)
                            {
                                decimal priceAdjustmentBase = TaxManager.GetCheckoutAttributePrice(caValue, customer);
                                decimal priceAdjustment     = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                if (priceAdjustmentBase > 0)
                                {
                                    string priceAdjustmentStr = PriceHelper.FormatPrice(priceAdjustment);
                                    caAttribute += string.Format(" [+{0}]", priceAdjustmentStr);
                                }
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(caAttribute))
                    {
                        if (i != 0 || j != 0)
                        {
                            result.Append(serapator);
                        }

                        //we don't encode multiline textbox input
                        if (htmlEncode &&
                            ca.AttributeControlType != AttributeControlTypeEnum.MultilineTextbox)
                        {
                            result.Append(HttpUtility.HtmlEncode(caAttribute));
                        }
                        else
                        {
                            result.Append(caAttribute);
                        }
                    }
                }
            }

            return(result.ToString());
        }
Exemple #26
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product);

                hlProduct.NavigateUrl = productURL;
                hlProduct.Text        = Server.HtmlEncode(product.Name);

                ProductPicture productPicture = product.DefaultProductPicture;
                if (productPicture != null)
                {
                    hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPicture.Picture, this.ProductImageSize, true);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                else
                {
                    hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(this.ProductImageSize);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                hlImageLink.NavigateUrl = productURL;

                lShortDescription.Text = product.ShortDescription;

                var productVariantCollection = product.ProductVariants;
                if (productVariantCollection.Count > 0)
                {
                    if (!product.HasMultipleVariants)
                    {
                        var productVariant = productVariantCollection[0];
                        btnAddToCart.Visible = (!productVariant.DisableBuyButton);

                        if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                            (NopContext.Current.User != null &&
                             !NopContext.Current.User.IsGuest))
                        {
                            if (productVariant.CustomerEntersPrice)
                            {
                                lblOldPrice.Visible = false;
                                lblPrice.Visible    = false;
                            }
                            else
                            {
                                decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice);
                                decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));

                                decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase != decimal.Zero)
                                {
                                    lblOldPrice.Text = PriceHelper.FormatPrice(oldPrice);
                                    lblPrice.Text    = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                }
                                else
                                {
                                    lblOldPrice.Visible = false;
                                    lblPrice.Text       = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                }
                            }
                        }
                        else
                        {
                            lblOldPrice.Visible  = false;
                            lblPrice.Visible     = false;
                            btnAddToCart.Visible = false;
                        }
                    }
                    else
                    {
                        var productVariant = product.MinimalPriceProductVariant;
                        if (productVariant != null)
                        {
                            if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                                (NopContext.Current.User != null &&
                                 !NopContext.Current.User.IsGuest))
                            {
                                if (productVariant.CustomerEntersPrice)
                                {
                                    lblOldPrice.Visible = false;
                                    lblPrice.Visible    = false;
                                }
                                else
                                {
                                    decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                    decimal fromPrice     = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                    lblOldPrice.Visible = false;
                                    lblPrice.Text       = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                                }
                            }
                            else
                            {
                                lblOldPrice.Visible  = false;
                                lblPrice.Visible     = false;
                                btnAddToCart.Visible = false;
                            }
                        }

                        btnAddToCart.Visible = false;
                    }
                }
                else
                {
                    lblOldPrice.Visible  = false;
                    lblPrice.Visible     = false;
                    btnAddToCart.Visible = false;
                }
            }
        }
Exemple #27
0
        private void BindData()
        {
            var productVariant = ProductManager.GetProductVariantById(this.ProductVariantId);

            if (productVariant != null)
            {
                if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    if (productVariant.CustomerEntersPrice)
                    {
                        phOldPrice.Visible    = false;
                        lblPrice.Visible      = false;
                        lblPriceValue.Visible = false;
                        phDiscount.Visible    = false;

                        lblCustomerEnterPrice.Visible = true;
                        lblCustomerEnterPrice.Text    = GetLocaleResourceString("Products.EnterProductPrice");
                    }
                    else
                    {
                        if (productVariant.CallForPrice)
                        {
                            lblPriceValue.Text = GetLocaleResourceString("Products.CallForPrice");
                            phOldPrice.Visible = false;
                            phDiscount.Visible = false;
                        }
                        else
                        {
                            decimal taxRate      = decimal.Zero;
                            decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice, out taxRate);
                            decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                            decimal finalPriceWithDiscountBase    = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true), out taxRate);

                            decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            decimal finalPriceWithDiscount    = CurrencyManager.ConvertCurrency(finalPriceWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                            if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                            {
                                lblOldPrice.Text   = PriceHelper.FormatPrice(oldPrice);
                                lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                phOldPrice.Visible = true;
                            }
                            else
                            {
                                lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                phOldPrice.Visible = false;
                            }

                            if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                            {
                                lblFinalPriceWithDiscount.Text = PriceHelper.FormatPrice(finalPriceWithDiscount);
                                phDiscount.Visible             = true;
                            }
                            else
                            {
                                phDiscount.Visible = false;
                            }

                            if (phDiscount.Visible)
                            {
                                lblPriceValue.CssClass = string.Empty;
                            }
                            else
                            {
                                lblPriceValue.CssClass = "productPrice";
                            }

                            if (phDiscount.Visible || phOldPrice.Visible)
                            {
                                lblPrice.Text = GetLocaleResourceString("Products.FinalPriceWithoutDiscount");
                            }
                            if (SettingManager.GetSettingValueBoolean("ProductAttribute.EnableDynamicPriceUpdate"))
                            {
                                string pattern     = SettingManager.GetSettingValue("ProductAttribute.PricePattern", "(?<val>(\\d+[\\s\\,\\.]?)+)");
                                string replacement = String.Format("<span class=\"price-val-for-dyn-upd-{0}\">${{val}}</span> ", productVariant.ProductVariantId);

                                if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                                {
                                    lblFinalPriceWithDiscount.Text = Regex.Replace(lblFinalPriceWithDiscount.Text, pattern, replacement);
                                }
                                else
                                {
                                    lblPriceValue.Text = Regex.Replace(lblPriceValue.Text, pattern, replacement);
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Exemple #28
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductURL(product);

                hlProduct.Text = Server.HtmlEncode(product.Name);

                ProductPictureCollection productPictures = product.ProductPictures;
                if (productPictures.Count > 0)
                {
                    hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, ProductImageSize, true);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                else
                {
                    hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(this.ProductImageSize);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                hlImageLink.NavigateUrl = productURL;

                lShortDescription.Text = product.ShortDescription;

                ProductVariantCollection productVariantCollection = product.ProductVariants;

                if (productVariantCollection.Count > 0)
                {
                    if (!product.HasMultipleVariants)
                    {
                        ProductVariant productVariant = productVariantCollection[0];

                        decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));

                        lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscountBase);
                        if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                        {
                            lblPrice.Text += "$";
                        }
                    }
                    else
                    {
                        ProductVariant productVariant = product.MinimalPriceProductVariant;
                        if (productVariant != null)
                        {
                            decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                            decimal fromPrice     = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                        }
                    }
                }
                else
                {
                    lblPrice.Visible = false;
                }

                #region scjaarge's change
                if (!lblPrice.Visible || lblPrice.Text.Trim() == string.Empty)
                {
                    litOrderOrNa.Text = "Нет в наличии";
                }
                #endregion scjaarge's change
            }
        }
        protected void CreateAttributeControls()
        {
            ProductVariant productVariant = ProductManager.GetProductVariantByID(this.ProductVariantID);

            if (productVariant != null)
            {
                ProductVariantAttributeCollection productVariantAttributes = productVariant.ProductVariantAttributes;
                if (productVariantAttributes.Count > 0)
                {
                    this.Visible = true;
                    foreach (ProductVariantAttribute attribute in productVariantAttributes)
                    {
                        Panel divAttribute   = new Panel();
                        Label attributeTitle = new Label();
                        if (attribute.IsRequired)
                        {
                            attributeTitle.Text = "<span>*</span> ";
                        }

                        //text prompt
                        string textPrompt = string.Empty;
                        if (!string.IsNullOrEmpty(attribute.TextPrompt))
                        {
                            textPrompt = attribute.TextPrompt;
                        }
                        else
                        {
                            textPrompt += attribute.ProductAttribute.Name;
                        }

                        attributeTitle.Text += Server.HtmlEncode(textPrompt);
                        attributeTitle.Style.Add("font-weight", "bold");

                        //description
                        if (!string.IsNullOrEmpty(attribute.ProductAttribute.Description))
                        {
                            attributeTitle.Text += string.Format("<div>{0}</div>",
                                                                 Server.HtmlEncode(
                                                                     attribute.ProductAttribute.Description));
                        }

                        bool addBreak = true;
                        switch (attribute.AttributeControlType)
                        {
                        case AttributeControlTypeEnum.TextBox:
                        {
                            addBreak = false;
                        }
                        break;

                        default:
                            break;
                        }
                        if (addBreak)
                        {
                            attributeTitle.Text += "<br />";
                        }
                        else
                        {
                            attributeTitle.Text += "&nbsp;&nbsp;&nbsp;";
                        }
                        divAttribute.Controls.Add(attributeTitle);

                        switch (attribute.AttributeControlType)
                        {
                        case AttributeControlTypeEnum.DropdownList:
                        {
                            DropDownList ddlAttributes = new DropDownList();
                            ddlAttributes.ID = attribute.ProductAttribute.Name;
                            if (!attribute.IsRequired)
                            {
                                ddlAttributes.Items.Add(new ListItem("---", "0"));
                            }
                            ProductVariantAttributeValueCollection pvaValues = attribute.ProductVariantAttributeValues;
                            foreach (ProductVariantAttributeValue pvaValue in pvaValues)
                            {
                                string  pvaValueName        = pvaValue.Name;
                                decimal priceAdjustmentBase = TaxManager.GetPrice(productVariant, pvaValue.PriceAdjustment);
                                decimal priceAdjustment     = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                if (priceAdjustmentBase > decimal.Zero)
                                {
                                    pvaValueName += string.Format(" [+{0}]", PriceHelper.FormatPrice(priceAdjustment, false, false));
                                }
                                ListItem pvaValueItem = new ListItem(pvaValueName, pvaValue.ProductVariantAttributeValueID.ToString());
                                pvaValueItem.Selected = pvaValue.IsPreSelected;
                                ddlAttributes.Items.Add(pvaValueItem);
                            }
                            divAttribute.Controls.Add(ddlAttributes);
                        }
                        break;

                        case AttributeControlTypeEnum.RadioList:
                        {
                            RadioButtonList rblAttributes = new RadioButtonList();
                            rblAttributes.ID = attribute.ProductAttribute.Name;
                            ProductVariantAttributeValueCollection pvaValues = attribute.ProductVariantAttributeValues;
                            foreach (ProductVariantAttributeValue pvaValue in pvaValues)
                            {
                                string  pvaValueName        = pvaValue.Name;
                                decimal priceAdjustmentBase = TaxManager.GetPrice(productVariant, pvaValue.PriceAdjustment);
                                decimal priceAdjustment     = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                if (priceAdjustmentBase > decimal.Zero)
                                {
                                    pvaValueName += string.Format(" [+{0}]", PriceHelper.FormatPrice(priceAdjustment, false, false));
                                }
                                ListItem pvaValueItem = new ListItem(Server.HtmlEncode(pvaValueName), pvaValue.ProductVariantAttributeValueID.ToString());
                                pvaValueItem.Selected = pvaValue.IsPreSelected;
                                rblAttributes.Items.Add(pvaValueItem);
                            }
                            divAttribute.Controls.Add(rblAttributes);
                        }
                        break;

                        case AttributeControlTypeEnum.Checkboxes:
                        {
                            CheckBoxList cblAttributes = new CheckBoxList();
                            cblAttributes.ID = attribute.ProductAttribute.Name;
                            ProductVariantAttributeValueCollection pvaValues = attribute.ProductVariantAttributeValues;
                            foreach (ProductVariantAttributeValue pvaValue in pvaValues)
                            {
                                string  pvaValueName        = pvaValue.Name;
                                decimal priceAdjustmentBase = TaxManager.GetPrice(productVariant, pvaValue.PriceAdjustment);
                                decimal priceAdjustment     = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                if (priceAdjustmentBase > decimal.Zero)
                                {
                                    pvaValueName += string.Format(" [+{0}]", PriceHelper.FormatPrice(priceAdjustment, false, false));
                                }
                                ListItem pvaValueItem = new ListItem(Server.HtmlEncode(pvaValueName), pvaValue.ProductVariantAttributeValueID.ToString());
                                pvaValueItem.Selected = pvaValue.IsPreSelected;
                                cblAttributes.Items.Add(pvaValueItem);
                            }
                            divAttribute.Controls.Add(cblAttributes);
                        }
                        break;

                        case AttributeControlTypeEnum.TextBox:
                        {
                            TextBox txtAttribute = new TextBox();
                            txtAttribute.ID = attribute.ProductAttribute.Name;
                            divAttribute.Controls.Add(txtAttribute);
                        }
                        break;

                        default:
                            break;
                        }
                        phAttributes.Controls.Add(divAttribute);
                    }
                }
                else
                {
                    this.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Exemple #30
0
        protected void BindData()
        {
            try
            {
                string keywords = txtSearchTerm.Text.Trim();

                if (!String.IsNullOrEmpty(keywords))
                {
                    int searchTermMinimumLength = SettingManager.GetSettingValueInteger("Search.ProductSearchTermMinimumLength", 3);
                    if (keywords.Length < searchTermMinimumLength)
                    {
                        throw new NopException(string.Format(LocalizationManager.GetLocaleResourceString("Search.SearchTermMinimumLengthIsNCharacters"), searchTermMinimumLength));
                    }

                    bool    advSearch                   = cbAdvancedSearch.Checked;
                    int     categoryId                  = 0;
                    int     manufacturerId              = 0;
                    decimal?minPriceConverted           = null;
                    decimal?maxPriceConverted           = null;
                    bool    searchInProductDescriptions = false;
                    if (advSearch)
                    {
                        //categories
                        if (ddlCategories.Items.Count > 0)
                        {
                            categoryId = int.Parse(this.ddlCategories.SelectedItem.Value);
                        }

                        //manufacturers
                        if (ddlManufacturers.Items.Count > 0)
                        {
                            manufacturerId = int.Parse(this.ddlManufacturers.SelectedItem.Value);
                        }

                        //min price
                        decimal?minPrice = null;
                        try
                        {
                            if (!string.IsNullOrEmpty(txtPriceFrom.Text.Trim()))
                            {
                                minPrice = decimal.Parse(txtPriceFrom.Text.Trim());
                                if (minPrice.HasValue)
                                {
                                    minPriceConverted = CurrencyManager.ConvertCurrency(minPrice.Value, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                                }
                            }
                        }
                        catch
                        {
                            txtPriceFrom.Text = string.Empty;
                        }

                        //max price
                        decimal?maxPrice = null;
                        try
                        {
                            if (!string.IsNullOrEmpty(txtPriceTo.Text.Trim()))
                            {
                                maxPrice = decimal.Parse(txtPriceTo.Text.Trim());
                                if (maxPrice.HasValue)
                                {
                                    maxPriceConverted = CurrencyManager.ConvertCurrency(maxPrice.Value, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                                }
                            }
                        }
                        catch
                        {
                            txtPriceTo.Text = string.Empty;
                        }

                        //search in descriptions
                        searchInProductDescriptions = cbSearchInProductDescriptions.Checked;
                    }

                    int totalRecords = 0;
                    var products     = ProductManager.GetAllProducts(categoryId,
                                                                     manufacturerId, 0, null,
                                                                     minPriceConverted, maxPriceConverted,
                                                                     keywords, searchInProductDescriptions,
                                                                     100, 0, new List <int>(), out totalRecords);

                    lvProducts.DataSource = products;
                    lvProducts.DataBind();
                    lvProducts.Visible    = products.Count > 0;
                    pagerProducts.Visible = products.Count > pagerProducts.PageSize;
                    lblNoResults.Visible  = !lvProducts.Visible;

                    int customerId = 0;
                    if (NopContext.Current.User != null)
                    {
                        customerId = NopContext.Current.User.CustomerId;
                    }
                    SearchLogManager.InsertSearchLog(txtSearchTerm.Text, customerId, DateTime.UtcNow);
                }
                else
                {
                    pagerProducts.Visible = false;
                    lvProducts.Visible    = false;
                }
            }
            catch (Exception exc)
            {
                lvProducts.Visible    = false;
                pagerProducts.Visible = false;
                lblError.Text         = Server.HtmlEncode(exc.Message);
            }
        }