示例#1
0
        public virtual void MigrateCustomerProductVariantQuotes(Customer fromCustomer, Customer toCustomer)
        {
            if (fromCustomer == null)
            {
                throw new ArgumentNullException("fromCustomer");
            }
            if (toCustomer == null)
            {
                throw new ArgumentNullException("toCustomer");
            }

            if (fromCustomer.Id == toCustomer.Id)
            {
                return; //the same customer
            }
            foreach (var customerProductVariantQuote in fromCustomer.CustomerProductVariantQuotes)
            {
                if (customerProductVariantQuote.ProductVariant.CallforPriceRequested(toCustomer))
                {
                    continue;
                }
                var quote = new CustomerProductVariantQuote()
                {
                    CustomerId       = toCustomer.Id,
                    ProductVariantId = customerProductVariantQuote.ProductVariant.Id
                };
                this.InsertCustomerProductVariantQuote(quote);
            }
        }
示例#2
0
 public virtual void UpdateCustomerProductVariantQuote(CustomerProductVariantQuote customerProductVariantQuote)
 {
     if (customerProductVariantQuote == null)
     {
         throw new ArgumentNullException("customerProductVariantQuote");
     }
     _customerProductVariantQuoteRepository.Update(customerProductVariantQuote);
 }
示例#3
0
        private ProductVariantQuoteModel PrepareProductVariantQuoteModelForList(CustomerProductVariantQuote customerProductVariantQuote)
        {
            #region Product variant price
            var productVariant = _productService.GetProductVariantById(customerProductVariantQuote.ProductVariantId);
            if (productVariant == null || productVariant.Id == 0)
            {
                return(null);
            }
            string   productName = productVariant.FullProductName;
            Currency currency    = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);
            if (productVariant != null && productVariant.CurrencyId.HasValue && (productVariant.CurrencyId.Value != _currencySettings.PrimaryStoreCurrencyId))
            {
                currency = _currencyService.GetCurrencyById(productVariant.CurrencyId.Value);
            }

            StatefulStorage.PerSession.Add <bool?>("SkipQuoteDiscountActivationCheck", () => (bool?)true);
            decimal taxRate      = decimal.Zero;
            var     customer     = _customerService.GetCustomerById(customerProductVariantQuote.CustomerId);
            decimal oldPriceBase = _taxService.GetProductPrice(productVariant, productVariant.OldPrice, out taxRate);
            decimal finalPriceWithoutDiscountBase = _taxService.GetProductPrice(productVariant, _priceCalculationService.GetFinalPrice(productVariant, customer, false, false), out taxRate);
            decimal finalPriceWithDiscountBase    = _taxService.GetProductPrice(productVariant, _priceCalculationService.GetFinalPrice(productVariant, customer, true, false), out taxRate);

            decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, currency);
            decimal finalPriceWithoutDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithoutDiscountBase, currency);
            decimal finalPriceWithDiscount    = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithDiscountBase, currency);

            string productVariantPriceOldPrice = String.Empty;
            if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
            {
                productVariantPriceOldPrice = _priceFormatter.FormatPrice(oldPrice, false, false);
            }
            string  productVariantPrice = _priceFormatter.FormatPrice(finalPriceWithoutDiscount, false, currency);
            string  productVariantPricePriceWithDiscount = "", productVariantPriceDiscountPrice = "", productVariantDiscountPercentage = "", productVariantPriceCurrency = "";
            decimal productVariantPricediscountValueBase = 0, productVariantPriceDiscountValue = 0, productVariantPriceValue = 0, productVariantPricePriceWithDiscountValue = 0;

            if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
            {
                IList <Discount> discounts = null;
                productVariantPricePriceWithDiscount = _priceFormatter.FormatPrice(finalPriceWithDiscount, false, currency);
                productVariantPricediscountValueBase = _priceCalculationService.GetDiscountAmount(productVariant, customer, 0, out discounts, false);
                productVariantPriceDiscountValue     = _currencyService.ConvertFromPrimaryStoreCurrency(productVariantPricediscountValueBase, _workContext.WorkingCurrency);
                productVariantPriceDiscountPrice     = _priceFormatter.FormatPrice(productVariantPricediscountValueBase, true, false);

                if (_workContext.WorkingLanguage.DisplayOrder == 2)
                {
                    productVariantDiscountPercentage = String.Format("({0}%)", ((int)discounts.First().DiscountPercentage).ToString());
                }
                else
                {
                    productVariantDiscountPercentage = String.Format("(%{0})", ((int)discounts.First().DiscountPercentage).ToString());
                }
            }
            productVariantPriceValue = finalPriceWithoutDiscount;
            productVariantPricePriceWithDiscountValue = finalPriceWithDiscount;
            productVariantPriceCurrency = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
            //////

            StatefulStorage.PerSession.Remove <bool?>("SkipQuoteDiscountActivationCheck");

            var pvpModel = new ProductVariantQuoteModel.ProductVariantPriceModel()
            {
                Price                  = productVariantPrice,
                PriceWithDiscount      = productVariantPricePriceWithDiscount,
                DiscountValue          = productVariantPriceDiscountValue,
                DiscountPrice          = productVariantPriceDiscountPrice,
                DiscountPercentage     = productVariantDiscountPercentage,
                PriceValue             = productVariantPriceValue,
                PriceWithDiscountValue = productVariantPricePriceWithDiscountValue,
                Currency               = productVariantPriceCurrency,
                OldPrice               = productVariantPriceOldPrice,
            };


            #endregion

            string name  = customerProductVariantQuote.Name;
            string phoneNumber = customerProductVariantQuote.PhoneNumber;
            try
            {
                Customer cust = _customerService.GetCustomerById(customerProductVariantQuote.CustomerId);
                if (cust != null)
                {
                    if (!cust.IsGuest())
                    {
                        name = cust.GetFullName();
                        if (cust.Addresses.Count() > 0)
                        {
                            phoneNumber = cust.Addresses.FirstOrDefault().PhoneNumber;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(new ProductVariantQuoteModel()
            {
                Id = customerProductVariantQuote.Id,
                ProductVariantId = customerProductVariantQuote.ProductVariantId,
                Email = customerProductVariantQuote.Email,
                PhoneNumber = phoneNumber,
                Enquiry = customerProductVariantQuote.Enquiry,
                Name = name,
                ManufacturerName = _productService.GetProductById(customerProductVariantQuote.ProductVariant.ProductId).GetDefaultManufacturer().Name,
                ProductName = productName,
                Sku = productVariant.Sku,
                ProductVariantPrice = pvpModel,
                Description = customerProductVariantQuote.Description,
                RequestDate = _dateTimeHelper.ConvertToUserTime(customerProductVariantQuote.RequestDate, DateTimeKind.Utc),
                PriceWithDiscount = customerProductVariantQuote.PriceWithDiscount,
                PriceWithoutDiscount = customerProductVariantQuote.PriceWithoutDiscount,
                DiscountPercentage = customerProductVariantQuote.DiscountPercentage,
                ActivateDate = customerProductVariantQuote.ActivateDate,
            });
        }
示例#4
0
 public static ProductVariantQuoteModel ToModel(this CustomerProductVariantQuote entity)
 {
     return(Mapper.Map <CustomerProductVariantQuote, ProductVariantQuoteModel>(entity));
 }