Пример #1
0
        protected void gvTierPrices_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateTierPrice")
            {
                int         index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row   = gvTierPrices.Rows[index];

                HiddenField    hfTierPriceID = row.FindControl("hfTierPriceID") as HiddenField;
                NumericTextBox txtQuantity   = row.FindControl("txtQuantity") as NumericTextBox;
                DecimalTextBox txtPrice      = row.FindControl("txtPrice") as DecimalTextBox;

                int     tierPriceID = int.Parse(hfTierPriceID.Value);
                decimal price       = txtPrice.Value;
                int     quantity    = txtQuantity.Value;

                TierPrice tierPrice = ProductManager.GetTierPriceByID(tierPriceID);

                if (tierPrice != null)
                {
                    ProductManager.UpdateTierPrice(tierPrice.TierPriceID,
                                                   tierPrice.ProductVariantID, quantity, price);
                }

                BindData();
            }
        }
Пример #2
0
        public void Can_save_and_load_tierPriceWithCustomerRole()
        {
            var tierPrice = new TierPrice
            {
                Quantity       = 1,
                Price          = 2,
                ProductVariant = GetTestProductVariant(),
                CustomerRole   = new CustomerRole()
                {
                    Name         = "Administrators",
                    FreeShipping = true,
                    TaxExempt    = true,
                    Active       = true,
                    IsSystemRole = true,
                    SystemName   = "Administrators"
                }
            };

            var fromDb = SaveAndLoadEntity(tierPrice);

            fromDb.ShouldNotBeNull();

            fromDb.CustomerRole.ShouldNotBeNull();
            fromDb.CustomerRole.Name.ShouldEqual("Administrators");
        }
        protected void gvTierPrices_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateTierPrice")
            {
                int         index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row   = gvTierPrices.Rows[index];

                HiddenField    hfTierPriceId = row.FindControl("hfTierPriceId") as HiddenField;
                NumericTextBox txtQuantity   = row.FindControl("txtQuantity") as NumericTextBox;
                DecimalTextBox txtPrice      = row.FindControl("txtPrice") as DecimalTextBox;

                int     tierPriceId = int.Parse(hfTierPriceId.Value);
                decimal price       = txtPrice.Value;
                int     quantity    = txtQuantity.Value;

                TierPrice tierPrice = this.ProductService.GetTierPriceById(tierPriceId);

                if (tierPrice != null)
                {
                    tierPrice.Quantity = quantity;
                    tierPrice.Price    = price;
                    this.ProductService.UpdateTierPrice(tierPrice);
                }

                BindData();
            }
        }
        /// <summary>
        /// Prepare tier price model
        /// </summary>
        /// <param name="model">Tier price model</param>
        /// <param name="product">Product</param>
        /// <param name="tierPrice">Tier price</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Tier price model</returns>
        public virtual TierPriceModel PrepareTierPriceModel(TierPriceModel model,
                                                            Category category, TierPrice tierPrice, bool excludeProperties = false)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (tierPrice != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = tierPrice.ToModel <TierPriceModel>();
                }
            }

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(model.AvailableStores);

            //prepare available customer roles
            _baseAdminModelFactory.PrepareCustomerRoles(model.AvailableCustomerRoles);

            return(model);
        }
        protected void btnNewTierPrice_Click(object sender, EventArgs e)
        {
            try
            {
                ProductVariant productVariant = this.ProductService.GetProductVariantById(this.ProductVariantId);
                if (productVariant != null)
                {
                    decimal price     = txtNewPrice.Value;
                    int     quantity  = txtNewQuantity.Value;
                    var     tierPrice = new TierPrice()
                    {
                        ProductVariantId = productVariant.ProductVariantId,
                        Quantity         = quantity,
                        Price            = price
                    };
                    this.ProductService.InsertTierPrice(tierPrice);

                    BindData();
                }
            }
            catch (Exception exc)
            {
                processAjaxError(exc);
            }
        }
        public override TierPriceModel PrepareTierPriceModel(TierPriceModel model,
                                                             Product product, TierPrice tierPrice, bool excludeProperties = false)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            if (tierPrice != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = tierPrice.ToModel <TierPriceModel>();
                }
            }

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(model.AvailableStores);

            //prepare available customer roles
            IEnumerable <CustomerRole> availableCustomerRoles = _customerService.GetAllCustomerRoles()
                                                                .Where(x => x.SystemName.Contains(B2BRole.RoleSuffix));

            foreach (var customerRole in availableCustomerRoles)
            {
                model.AvailableCustomerRoles.Add(new SelectListItem {
                    Value = customerRole.Id.ToString(), Text = customerRole.Name
                });
            }

            return(model);
        }
Пример #7
0
        public static TierPrice ToWebModel(this QuoteModule.Client.Model.TierPrice serviceModel, Currency currency)
        {
            var webModel = new TierPrice(currency);

            webModel.InjectFrom <NullableAndEnumValueInjecter>(serviceModel);
            webModel.Price = new Money(serviceModel.Price ?? 0, currency);
            return(webModel);
        }
Пример #8
0
        public static QuoteModule.Client.Model.TierPrice ToQuoteServiceModel(this TierPrice webModel)
        {
            var serviceModel = new QuoteModule.Client.Model.TierPrice();

            serviceModel.InjectFrom <NullableAndEnumValueInjecter>(webModel);
            serviceModel.Price = (double)webModel.Price.Amount;
            return(serviceModel);
        }
        public virtual TierPrice ToLiquidTierPrice(Storefront.Model.TierPrice tierPrice)
        {
            var result = new TierPrice();

            result.Price    = tierPrice.Price.Amount * 100;
            result.Quantity = tierPrice.Quantity;
            return(result);
        }
        public static ProductModel.TierPriceModel ToModel(this TierPrice entity, IDateTimeHelper dateTimeHelper)
        {
            var tierprice = entity.MapTo <TierPrice, ProductModel.TierPriceModel>();

            tierprice.StartDateTime = entity.StartDateTimeUtc.ConvertToUserTime(dateTimeHelper);
            tierprice.EndDateTime   = entity.EndDateTimeUtc.ConvertToUserTime(dateTimeHelper);
            return(tierprice);
        }
        public static TierPrice ToEntity(this ProductModel.TierPriceModel model, TierPrice destination, IDateTimeHelper dateTimeHelper)
        {
            var tierprice = model.MapTo(destination);

            tierprice.StartDateTimeUtc = model.StartDateTime.ConvertToUtcTime(dateTimeHelper);
            tierprice.EndDateTimeUtc   = model.EndDateTime.ConvertToUtcTime(dateTimeHelper);
            return(tierprice);
        }
Пример #12
0
        public virtual quoteDto.TierPrice ToQuoteTierPriceDto(TierPrice webModel)
        {
            var serviceModel = new quoteDto.TierPrice();

            serviceModel.InjectFrom <NullableAndEnumValueInjecter>(webModel);
            serviceModel.Price = (double)webModel.Price.Amount;
            return(serviceModel);
        }
Пример #13
0
        public virtual TierPrice ToTierPrice(quoteDto.TierPrice tierPriceDto, Currency currency)
        {
            var result = new TierPrice(currency);

            result.InjectFrom <NullableAndEnumValueInjecter>(tierPriceDto);
            result.Price = new Money(tierPriceDto.Price ?? 0, currency);
            return(result);
        }
Пример #14
0
        public static TierPrice ToShopifyModel(this Storefront.Model.TierPrice storefrontModel)
        {
            var shopifyModel = new TierPrice();

            shopifyModel.Price    = storefrontModel.ListPrice.Amount * 100;
            shopifyModel.Quantity = storefrontModel.Quantity;

            return(shopifyModel);
        }
        public void ByProduct_Should_Throw_ArgumentException_If_ProductId_Is_Empty()
        {
            IQueryable <TierPrice> tierPrices = new TierPrice[0].AsQueryable();
            Guid productId = Guid.Empty;

            var ex = Assert.Throws <ArgumentException>(() => TierPriceExtensions.ByProduct(tierPrices, productId));

            Assert.Equal(nameof(productId), ex.ParamName);
        }
Пример #16
0
        public virtual void UpdateTierPrice(TierPrice tierPrice)
        {
            Guard.NotNull(tierPrice, nameof(tierPrice));

            _tierPriceRepository.Update(tierPrice);

            //event notification
            _services.EventPublisher.EntityUpdated(tierPrice);
        }
Пример #17
0
        public static TierPrice ToWebModel(this VirtoCommerceQuoteModuleWebModelTierPrice serviceModel, Currency currency)
        {
            var webModel = new TierPrice();

            webModel.InjectFrom <NullableAndEnumValueInjecter>(serviceModel);

            webModel.ListPrice = new Money(serviceModel.Price ?? 0, currency);

            return(webModel);
        }
Пример #18
0
        public virtual TierPrice ToTierPrice(quoteDto.TierPrice tierPriceDto, Currency currency)
        {
            var result = new TierPrice(currency)
            {
                Quantity = tierPriceDto.Quantity ?? 1,
                Price    = new Money(tierPriceDto.Price ?? 0, currency)
            };

            return(result);
        }
        public static TierPrice ToWebModel(this VirtoCommerceQuoteModuleWebModelTierPrice serviceModel, Currency currency)
        {
            var webModel = new TierPrice(currency);

            webModel.InjectFrom<NullableAndEnumValueInjecter>(serviceModel);

            webModel.Price = new Money(serviceModel.Price ?? 0, currency);

            return webModel;
        }
Пример #20
0
        public static VirtoCommerceQuoteModuleWebModelTierPrice ToQuoteServiceModel(this TierPrice webModel)
        {
            var serviceModel = new VirtoCommerceQuoteModuleWebModelTierPrice();

            serviceModel.InjectFrom <NullableAndEnumValueInjecter>(webModel);

            serviceModel.Price = (double)webModel.Price.Amount;

            return(serviceModel);
        }
Пример #21
0
        public virtual quoteDto.TierPrice ToQuoteTierPriceDto(TierPrice webModel)
        {
            var result = new quoteDto.TierPrice
            {
                Quantity = webModel.Quantity,
                Price    = (double)webModel.Price.Amount
            };

            return(result);
        }
        /// <summary>
        /// Inserts a tier price
        /// </summary>
        /// <param name="tierPrice">Tier price</param>
        public virtual void InsertTierPrice(TierPrice tierPrice)
        {
            if (tierPrice == null)
            {
                throw new ArgumentNullException(nameof(tierPrice));
            }

            _tierPriceRepository.Insert(tierPrice);

            //event notification
            _eventPublisher.EntityInserted(tierPrice);
        }
Пример #23
0
        public TierPriceEntity FromModel(TierPrice item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            Price    = item.Price;
            Quantity = item.Quantity;

            return(this);
        }
Пример #24
0
        public virtual void DeleteTierPrice(TierPrice tierPrice)
        {
            if (tierPrice == null)
            {
                throw new ArgumentNullException("tierPrice");
            }

            _tierPriceRepository.Delete(tierPrice);

            //event notification
            _services.EventPublisher.EntityDeleted(tierPrice);
        }
Пример #25
0
        protected void gvTierPrices_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TierPrice tierPrice = (TierPrice)e.Row.DataItem;

                Button btnUpdate = e.Row.FindControl("btnUpdate") as Button;
                if (btnUpdate != null)
                {
                    btnUpdate.CommandArgument = e.Row.RowIndex.ToString();
                }
            }
        }
Пример #26
0
        public TierPrice ToModel(TierPrice item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            //item.Id = Id;

            item.Price    = Price;
            item.Quantity = Quantity;

            return(item);
        }
Пример #27
0
        public void Can_save_and_load_tierPrice()
        {
            var tierPrice = new TierPrice
            {
                Quantity       = 1,
                Price          = 2.1M,
                ProductVariant = GetTestProductVariant(),
            };

            var fromDb = SaveAndLoadEntity(tierPrice);

            fromDb.ShouldNotBeNull();
            fromDb.Quantity.ShouldEqual(1);
            fromDb.Price.ShouldEqual(2.1M);

            fromDb.ProductVariant.ShouldNotBeNull();
            fromDb.ProductVariant.Name.ShouldEqual("Product variant name 1");
        }
Пример #28
0
        protected void btnNewTierPrice_Click(object sender, EventArgs e)
        {
            try
            {
                ProductVariant productVariant = ProductManager.GetProductVariantByID(this.ProductVariantID);
                if (productVariant != null)
                {
                    decimal   price     = txtNewPrice.Value;
                    int       quantity  = txtNewQuantity.Value;
                    TierPrice tierPrice = ProductManager.InsertTierPrice(productVariant.ProductVariantID, quantity, price);

                    BindData();
                }
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }
Пример #29
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;
            }
        }
Пример #30
0
        public void Can_save_and_load_tierPrice()
        {
            var tierPrice = new TierPrice
            {
                StoreId  = 7,
                Quantity = 1,
                Price    = 2.1M,
                Product  = GetTestProduct()
            };

            var fromDb = SaveAndLoadEntity(tierPrice);

            fromDb.ShouldNotBeNull();
            fromDb.StoreId.ShouldEqual(7);
            fromDb.Quantity.ShouldEqual(1);
            fromDb.Price.ShouldEqual(2.1M);

            fromDb.Product.ShouldNotBeNull();
        }
Пример #31
0
        public void Can_save_and_load_tierPrice()
        {
            var tierPrice = new TierPrice
            {
                StoreId          = 7,
                Quantity         = 1,
                Price            = 2.1M,
                StartDateTimeUtc = new DateTime(2010, 01, 03),
                Product          = GetTestProduct(),
            };

            var fromDb = SaveAndLoadEntity(tierPrice);

            fromDb.ShouldNotBeNull();
            fromDb.StoreId.ShouldEqual(7);
            fromDb.Quantity.ShouldEqual(1);
            fromDb.Price.ShouldEqual(2.1M);
            fromDb.StartDateTimeUtc.ShouldEqual(new DateTime(2010, 01, 03));
            fromDb.Product.ShouldNotBeNull();
        }