Ejemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"></see> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            // First time the field is loaded in Sitecore shell
            string      xml             = this.Value;
            PriceMatrix priceMatrixItem = PriceMatrix.Load(xml);
            Item        item            = Sitecore.Context.ContentDatabase.SelectSingleItem(PriceMatrixPath);

            this.priceMatrixConfigurationLevel = item.Axes.Level;

            if (!Sitecore.Context.ClientPage.IsEvent)
            {
                var panel = new System.Web.UI.WebControls.Panel();
                panel.Attributes.Add("style", string.Format("padding: 4px, 10px, 10px, 10px; border: 1px solid #CECFCE; background-color: white;"));

                this.Controls.Add(panel);

                if (priceMatrixItem != null)
                {
                    this.IterateRecursiveToLoad(priceMatrixItem.MainCategory, panel, item);
                }
                else
                {
                    this.IterateRecursiveToLoad(null, panel, item);
                }
            }

            base.OnLoad(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Formats the product prices.
        /// </summary>
        /// <param name="fieldIDs">The field Ids.</param>
        protected virtual void FormatProductPrices([NotNull] System.Collections.Generic.IEnumerable <string> fieldIDs)
        {
            Assert.ArgumentNotNull(fieldIDs, "fieldIDs");

            using (new SecurityDisabler())
            {
                Item contentItem = Database.GetDatabase("master").GetItem(ItemIDs.ContentRoot);
                Assert.IsNotNull(contentItem, "Cannot get content root item");

                Item[] productItems = contentItem.Axes.SelectItems(".//*");
                foreach (Item productItem in productItems)
                {
                    productItem.Fields.ReadAll();
                    foreach (string fieldId in fieldIDs)
                    {
                        PriceField priceField;
                        if (productItem.Fields.Contains(ID.Parse(fieldId)))
                        {
                            priceField = productItem.Fields[ID.Parse(fieldId)];

                            PriceMatrix matrix = new PriceMatrix(priceField.PriceMatrix.MainCategory);

                            this.UpdatePriceMatrix(matrix.MainCategory, productItem, priceField.InnerField.Name);

                            using (new EditContext(productItem, false, true))
                            {
                                productItem[ID.Parse(fieldId)] = SavePriceMatrix(matrix);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates the XML.
        /// </summary>
        /// <param name="pmroot">The pmroot.</param>
        /// <returns></returns>
        private string GenerateXml(Item pmroot)
        {
            string      xml         = this.Value;
            PriceMatrix priceMatrix = null;

            // PriceMatrix priceMatrix = PriceMatrixXmlParser.ReadXml(xml);
            if (priceMatrix == null)
            {
                priceMatrix = new PriceMatrix();
            }

            IterateRecursiveToSave(null, priceMatrix.MainCategory, pmroot, this.Controls);

            if (this.ValidateNumbers(priceMatrix.MainCategory))
            {
                var x        = new XmlSerializer(priceMatrix.GetType());
                var sb       = new StringBuilder();
                var settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true; // Remove the <?xml version="1.0" encoding="utf-8"?>
                XmlWriter xw = XmlWriter.Create(sb, settings);
                var       ns = new XmlSerializerNamespaces();
                ns.Add(string.Empty, string.Empty);
                x.Serialize(xw, priceMatrix, ns);
                return(sb.ToString());
            }

            return(string.Empty);
        }
Ejemplo n.º 4
0
        protected override void SalePriceCheck(PricingServiceParameter pricingServiceParameter, PriceAndPriceBreaks priceAndBreaks, IList <PriceMatrix> priceMatrixList)
        {
            PriceMatrix selectedPriceMatrix = GetMatchedPriceMatrix(priceMatrixList);

            if (selectedPriceMatrix != null)
            {
                List <ProductPrice> list         = this.GetProductPrice(priceMatrixList, pricingServiceParameter, selectedPriceMatrix, false).ToList <ProductPrice>();
                ProductPrice        productPrice = null;
                if (this.OrderLine != null && !string.IsNullOrEmpty(this.OrderLine.SmartPart))
                {
                    if (Convert.ToDecimal(this.OrderLine.SmartPart) > 0)
                    {
                        productPrice = list.OrderByDescending <ProductPrice, Decimal>((Func <ProductPrice, Decimal>)(pb => pb.BreakQty)).FirstOrDefault <ProductPrice>((Func <ProductPrice, bool>)(b => b.BreakQty <= Convert.ToDecimal(this.OrderLine.SmartPart)));
                    }
                }
                else
                {
                    productPrice = list.OrderByDescending <ProductPrice, Decimal>((Func <ProductPrice, Decimal>)(pb => pb.BreakQty)).FirstOrDefault <ProductPrice>((Func <ProductPrice, bool>)(b => b.BreakQty <= pricingServiceParameter.QtyOrdered));
                }
                if (productPrice != null && productPrice.Price < priceAndBreaks.Price)
                {
                    priceAndBreaks.SetPrice(productPrice.Price, pricingServiceParameter.CurrencyCode);
                    priceAndBreaks.IsSalePrice = true;
                }
                priceAndBreaks.PriceBreaks = this.MergePriceBreaks(priceAndBreaks.PriceBreaks, list);
            }
            else
            {
                DateTimeOffset pricingDate1 = pricingServiceParameter.PricingDate;
                DateTimeOffset?nullable     = this.Product.BasicSaleStartDate;
                if ((nullable.HasValue ? (pricingDate1 > nullable.GetValueOrDefault() ? 1 : 0) : 0) == 0)
                {
                    return;
                }
                nullable = this.Product.BasicSaleEndDate;
                if (nullable.HasValue)
                {
                    DateTimeOffset pricingDate2 = pricingServiceParameter.PricingDate;
                    nullable = this.Product.BasicSaleEndDate;
                    if ((nullable.HasValue ? (pricingDate2 < nullable.GetValueOrDefault() ? 1 : 0) : 0) == 0)
                    {
                        return;
                    }
                }
                if (!(priceAndBreaks.Price == Decimal.Zero) && (!(priceAndBreaks.Price > Decimal.Zero) || !(priceAndBreaks.Price > this.Product.BasicSalePrice)) || !(pricingServiceParameter.UnitOfMeasure == this.Product.UnitOfMeasure))
                {
                    return;
                }
                priceAndBreaks.SetPrice(this.Product.BasicSalePrice, this.BaseCurrency.CurrencyCode);
                priceAndBreaks.IsSalePrice = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initalizes the price matrix.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <returns></returns>
        public static PriceMatrix InitalizePriceMatrix(string xml)
        {
            Item        item        = Sitecore.Context.ContentDatabase.SelectSingleItem(PriceMatrixPath);
            PriceMatrix priceMatrix = PriceMatrix.Load(xml);

            if (priceMatrix == null)
            {
                priceMatrix = new PriceMatrix();
            }

            IterateRecursiveToSave(null, priceMatrix.MainCategory, item, null);
            return(priceMatrix);
        }
Ejemplo n.º 6
0
        private static string SavePriceMatrix([NotNull] PriceMatrix priceMatrix)
        {
            Assert.ArgumentNotNull(priceMatrix, "priceMatrix");

            var x        = new XmlSerializer(priceMatrix.GetType());
            var sb       = new StringBuilder();
            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true
            };
            XmlWriter xw = XmlWriter.Create(sb, settings);
            var       ns = new XmlSerializerNamespaces();

            ns.Add(string.Empty, string.Empty);
            x.Serialize(xw, priceMatrix, ns);

            return(sb.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the price matrix price.
        /// </summary>
        /// <typeparam name="TProduct">The type of the product.</typeparam>
        /// <param name="product">The product.</param>
        /// <param name="priceMatrixName">Name of the price matrix.</param>
        /// <returns>The price.</returns>
        protected override decimal GetPriceMatrixPrice <TProduct>(TProduct product, string priceMatrixName)
        {
            PriceMatrix pm = PriceMatrix.Load(this.priceMatrix);

            string           query           = string.Format("./Shop/{0}", priceMatrixName);
            IPriceMatrixItem priceMatrixItem = pm.SelectSingleItem(query);
            CategoryItem     categoryItem    = priceMatrixItem as CategoryItem;

            if (categoryItem == null)
            {
                return(decimal.Zero);
            }

            string price = categoryItem.Amount;

            decimal priceValue;

            return(!decimal.TryParse(price, out priceValue) ? 0 : priceValue);
        }
Ejemplo n.º 8
0
        public PriceMatrix GetMatchedPriceMatrix(IList <PriceMatrix> priceMatrixList)
        {
            PriceMatrix priceMatrix = null;

            //Commented for BUSA-431 : if ship to price code is null, then consider bill to price code.
            //string currentCustomerId = this.ShipTo != null ? this.ShipTo.Id.ToString() : string.Empty;
            //string currentCustomerPriceCode = this.ShipTo != null ? this.ShipTo.PriceCode : string.Empty;

            //BUSA-42 : Duplicate Customers on Production Starts
            string currentCustomerId = string.Empty;
            var    siteContextShipTo = SiteContext.Current.ShipTo;

            if (siteContextShipTo != null && siteContextShipTo.Id != null)
            {
                if (this.ShipTo.CustomerSequence.ToUpper().Contains("ISC"))
                {
                    currentCustomerId = siteContextShipTo.Id.ToString();
                }
                else
                {
                    currentCustomerId = this.ShipTo != null?this.ShipTo.Id.ToString() : this.BillTo != null?this.BillTo.Id.ToString() : string.Empty;
                }
            }
            else
            {
                currentCustomerId = this.ShipTo != null?this.ShipTo.Id.ToString() : this.BillTo != null?this.BillTo.Id.ToString() : string.Empty;
            }
            //BUSA-42 : Duplicate Customers on Production Ends.

            string currentCustomerPriceCode = this.ShipTo != null ? !string.IsNullOrEmpty(this.ShipTo.PriceCode) ? this.ShipTo.PriceCode : !string.IsNullOrEmpty(this.BillTo.PriceCode) ? this.BillTo.PriceCode : string.Empty : string.Empty;

            //BUSA-431 changes end

            string currentProductId        = this.Product.Id.ToString();
            string currentProductPriceCode = this.Product.ProductCode;
            var    productContractCode     = this.Product.CustomProperties.Where(c => c.Name.EqualsIgnoreCase("ProductContractCode")).FirstOrDefault() != null?this.Product.CustomProperties.Where(c => c.Name.EqualsIgnoreCase("ProductContractCode")).FirstOrDefault().Value : string.Empty;

            IEnumerable <PriceMatrix> availablePriceMatrices;

            if (priceMatrixList != null && priceMatrixList.Count > 0)
            {
                if (!string.IsNullOrEmpty(currentCustomerId) && priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerId)).FirstOrDefault() != null)
                {
                    //Added if condition to exclude to exclude priceMatrix records having deactivation date in the past
                    if (priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerId)).FirstOrDefault().DeactivateOn == null || priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerId)).FirstOrDefault().DeactivateOn >= DateTime.Now)
                    {
                        availablePriceMatrices = priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerId));
                        //Customer / Item
                        if (availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer/Product")).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer/Product")).FirstOrDefault());
                        }
                        //Customer / Item Contract Code
                        else if (!string.IsNullOrEmpty(productContractCode) && availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(productContractCode)).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(productContractCode)).FirstOrDefault());
                        }
                        //Customer / Item Class
                        else if (!string.IsNullOrEmpty(currentProductPriceCode) && availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault());
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(currentCustomerPriceCode) && priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerPriceCode)).FirstOrDefault() != null)
                {
                    //Added if condition to exclude priceMatrix records having deactivation date in the past
                    if (priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerPriceCode)).FirstOrDefault().DeactivateOn >= DateTime.Now || (priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerPriceCode)).FirstOrDefault().DeactivateOn) == null)
                    {
                        availablePriceMatrices = priceMatrixList.Where(p => p.CustomerKeyPart.EqualsIgnoreCase(currentCustomerPriceCode));
                        // BUSA-555 : Pricing issue for Customer 1061091 TLC FOR SMILES Starts
                        if (availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer Price Code/Product Price Code")).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer Price Code/Product Price Code")).FirstOrDefault());
                        }
                        // BUSA-555 : Pricing issue for Customer 1061091 TLC FOR SMILES Ends
                        //Customer Contract Code / Item
                        if (availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer Price Code/Product")).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.RecordType.EqualsIgnoreCase("Customer Price Code/Product")).FirstOrDefault());
                        }
                        //Customer Contract Code / Item Contract Code
                        else if (!string.IsNullOrEmpty(productContractCode) && availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(productContractCode)).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(productContractCode)).FirstOrDefault());
                        }
                        //Customer Contract Code / Item Class
                        else if (!string.IsNullOrEmpty(currentProductPriceCode) && availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault() != null)
                        {
                            return(availablePriceMatrices.Where(p => p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault());
                        }
                    }
                }
                else if (priceMatrixList.Count == 1 && priceMatrixList.FirstOrDefault().CustomerKeyPart == "1")
                {
                    availablePriceMatrices = priceMatrixList;
                    return(availablePriceMatrices.FirstOrDefault());
                }
                else
                {
                    availablePriceMatrices = priceMatrixList.Where(p => p.RecordType.EqualsIgnoreCase("Product"));
                    //Any Customer / Item
                    if (availablePriceMatrices.FirstOrDefault() != null)
                    {
                        return(availablePriceMatrices.FirstOrDefault());
                    }
                    //Any Customer / Item Class
                    else if (!string.IsNullOrEmpty(currentProductPriceCode) && priceMatrixList.Where(p => p.RecordType.EqualsIgnoreCase("Product Price Code") && p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault() != null)
                    {
                        return(priceMatrixList.Where(p => p.RecordType.EqualsIgnoreCase("Product Price Code") && p.ProductKeyPart.EqualsIgnoreCase(currentProductPriceCode)).FirstOrDefault());
                    }
                }
            }
            return(priceMatrix);
        }
Ejemplo n.º 9
0
        protected override IEnumerable <ProductPrice> GetProductPrice(IList <PriceMatrix> priceMatrixList, PricingServiceParameter pricingServiceParameter, PriceMatrix selectedPriceMatrix, bool regularPrice)
        {
            List <ProductPrice> productPriceList = new List <ProductPrice>();
            List <PriceBracket> matrixBrackets   = this.GetMatrixBrackets(selectedPriceMatrix);
            CurrencyDto         currency         = this.GetCurrency(selectedPriceMatrix.CurrencyCode);
            Decimal             basePrice        = this.GetBasePrice(pricingServiceParameter);

            foreach (PriceBracket priceBracket1 in matrixBrackets)
            {
                PriceData priceData1 = new PriceData();
                priceData1.PricingServiceParameter = pricingServiceParameter;
                Product product = this.Product;
                priceData1.Product = product;
                Customer billTo = this.BillTo;
                priceData1.BillTo = billTo;
                Customer shipTo = GetSiteContextShipTo();//BUSA-42 : Duplicate Customers on Production.
                priceData1.ShipTo = shipTo;
                List <PriceBracket> priceBracketList = matrixBrackets;
                priceData1.MatrixBrackets = priceBracketList;
                PriceBracket priceBracket2 = priceBracket1;
                priceData1.PriceBracket = priceBracket2;
                if (selectedPriceMatrix.RecordType.EqualsIgnoreCase("Product"))
                {
                    var priceBracket = GetAllCustomerItemPriceBracket();
                    if (priceBracket != null)
                    {
                        priceData1.PriceBracket.AdjustmentType = priceBracket.AdjustmentType;
                        priceData1.PriceBracket.PriceBasis     = priceBracket.PriceBasis;
                        priceData1.PriceBracket.Amount         = priceBracket.Amount;
                        priceData1.PriceBracket.AltAmount      = priceBracket.AltAmount;
                    }
                }
                Decimal num = basePrice;
                priceData1.BasePrice = num;
                string calculationFlags = selectedPriceMatrix.CalculationFlags;
                priceData1.CalculationFlags = calculationFlags;
                if (selectedPriceMatrix.RecordType.EqualsIgnoreCase("Product"))
                {
                    priceData1.TempBasis = priceData1.PriceBracket.AltAmount;
                }
                else
                {
                    priceData1.TempBasis = this.GetTempBasisValue(priceBracket1.PriceBasis, priceMatrixList, pricingServiceParameter, regularPrice);
                }
                PriceData         priceData        = priceData1;
                IPriceCalculation priceCalculation = this.PriceCalculations.FirstOrDefault <IPriceCalculation>((Func <IPriceCalculation, bool>)(r => r.IsMatch(priceData)));
                if (priceCalculation != null)
                {
                    ProductPrice productPrice = new ProductPrice();
                    productPrice.BreakQty = priceData.PriceBracket.BreakQty;
                    if (regularPrice)
                    {
                        //Start:Revert BUSA 682 :The Base price of the product in ERP and the base price of the same product on the PDP are different.Revert BUSA: 696 Acct #78803:1076826 - Product (5011768U0) price differs in ERP and on the PDP.
                        var price = GetPriceListAmount("P2");
                        productPrice.Price = !string.IsNullOrEmpty(price) ? Convert.ToDecimal(price) : this.GetBasePrice(pricingServiceParameter);
                        //productPrice.Price = !string.IsNullOrEmpty(price) ? Convert.ToDecimal(price) : this.Product.BasicListPrice;

                        //End:Revert BUSA 682 :The Base price of the product in ERP and the base price of the same product on the PDP are different.Revert BUSA: 696 Acct #78803:1076826 - Product (5011768U0) price differs in ERP and on the PDP.
                    }
                    else
                    {
                        productPrice.Price = priceCalculation.CalculatePrice(priceData);
                    }

                    productPrice.Price        = this.ApplyProductMultiplier(pricingServiceParameter, productPrice.Price);
                    productPrice.Price        = selectedPriceMatrix.UnitOfMeasure == pricingServiceParameter.UnitOfMeasure || selectedPriceMatrix.UnitOfMeasure.IsBlank() && pricingServiceParameter.UnitOfMeasure == this.Product.UnitOfMeasure || priceBracket1.PriceBasis.Equals("CLM", StringComparison.OrdinalIgnoreCase) ? productPrice.Price : this.AdjustForUnitOfMeasure(pricingServiceParameter, productPrice.Price);
                    productPrice.PriceDisplay = this.CurrencyFormatProvider.GetString(productPrice.Price, currency);
                    productPriceList.Add(productPrice);
                }
            }
            return(productPriceList);
        }
Ejemplo n.º 10
0
    /// <summary>
    /// Formats the product prices.
    /// </summary>
    /// <param name="fieldIDs">The field Ids.</param>
    protected virtual void FormatProductPrices([NotNull] System.Collections.Generic.IEnumerable<string> fieldIDs)
    {
      Assert.ArgumentNotNull(fieldIDs, "fieldIDs");

      using (new SecurityDisabler())
      {
        Item contentItem = Database.GetDatabase("master").GetItem(ItemIDs.ContentRoot);
        Assert.IsNotNull(contentItem, "Cannot get content root item");

        Item[] productItems = contentItem.Axes.SelectItems(".//*");
        foreach (Item productItem in productItems)
        {
          productItem.Fields.ReadAll();
          foreach (string fieldId in fieldIDs)
          {
            PriceField priceField;
            if (productItem.Fields.Contains(ID.Parse(fieldId)))
            {
              priceField = productItem.Fields[ID.Parse(fieldId)];

              PriceMatrix matrix = new PriceMatrix(priceField.PriceMatrix.MainCategory);

              this.UpdatePriceMatrix(matrix.MainCategory, productItem, priceField.InnerField.Name);

              using (new EditContext(productItem, false, true))
              {
                productItem[ID.Parse(fieldId)] = SavePriceMatrix(matrix);
              }
            }
          }
        }
      }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Generates the XML.
    /// </summary>
    /// <param name="pmroot">The pmroot.</param>
    /// <returns></returns>
    private string GenerateXml(Item pmroot)
    {
      string xml = this.Value;
      PriceMatrix priceMatrix = null;

      // PriceMatrix priceMatrix = PriceMatrixXmlParser.ReadXml(xml);
      if (priceMatrix == null)
      {
        priceMatrix = new PriceMatrix();
      }

      IterateRecursiveToSave(null, priceMatrix.MainCategory, pmroot, this.Controls);

      if (this.ValidateNumbers(priceMatrix.MainCategory))
      {
        var x = new XmlSerializer(priceMatrix.GetType());
        var sb = new StringBuilder();
        var settings = new XmlWriterSettings();
        settings.OmitXmlDeclaration = true; // Remove the <?xml version="1.0" encoding="utf-8"?>
        XmlWriter xw = XmlWriter.Create(sb, settings);
        var ns = new XmlSerializerNamespaces();
        ns.Add(string.Empty, string.Empty);
        x.Serialize(xw, priceMatrix, ns);
        return sb.ToString();
      }

      return string.Empty;
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Initalizes the price matrix.
    /// </summary>
    /// <param name="xml">The XML.</param>
    /// <returns></returns>
    public static PriceMatrix InitalizePriceMatrix(string xml)
    {
      Item item = Sitecore.Context.ContentDatabase.SelectSingleItem(PriceMatrixPath);
      PriceMatrix priceMatrix = PriceMatrix.Load(xml);
      if (priceMatrix == null)
      {
        priceMatrix = new PriceMatrix();
      }

      IterateRecursiveToSave(null, priceMatrix.MainCategory, item, null);
      return priceMatrix;
    }