private static decimal GetLowestPriceBasePercentBasedPromotion(decimal actualPrice, decimal retailPrice, decimal?amount)
        {
            decimal lowestPrice;
            Decimal percent = amount.Value / new Decimal(100);

            lowestPrice = actualPrice;
            Decimal discountedRetailPrice = NumberHelper.ApplyDiscount(retailPrice, percent);

            Decimal[] lowestAmount = new[] { lowestPrice, discountedRetailPrice };
            lowestPrice = lowestAmount.Min();
            return(lowestPrice);
        }
        public override GetProductCollectionResult Execute(IUnitOfWork unitOfWork, GetProductCollectionParameter parameter, GetProductCollectionResult result)
        {
            customSettings = new CustomSettings();
            string showDisProAttr = customSettings.Brasseler_DiscontinuedAttributeValueId;
            bool   addShowDiscontinuedProducts = true;

            if (result.AttributeTypeDtos != null)
            {
                foreach (var item in result.AttributeTypeDtos)
                {
                    for (int i = 0; i < item.AttributeValueFacets.Count; i++)
                    {
                        if (item.AttributeValueFacets[i].AttributeValueId == new Guid(showDisProAttr))
                        {
                            addShowDiscontinuedProducts = false;
                        }
                    }
                }
                if (addShowDiscontinuedProducts)
                {
                    AttributeValueFacetDto aVFD = new AttributeValueFacetDto();

                    aVFD.AttributeValueId = new Guid(showDisProAttr);
                    aVFD.Value            = "Show Discontinued Products";
                    aVFD.ValueDisplay     = "Show Discontinued Products";

                    if (result.AttributeTypeDtos.Count >= 1)
                    {
                        foreach (var item in result.AttributeTypeDtos)
                        {
                            if (item.Name == "Discontinued Products")
                            {
                                item.AttributeValueFacets.Add(aVFD);
                            }
                        }
                    }
                }
            }
            //BUSA-328 Compare screen does not update price if logging directly into page start
            var currentUser = SiteContext.Current.ShipTo;

            foreach (var product in result.ProductDtos)
            {
                //BUSA-771 : If signed in Add to cart button should get hidden if product is suspended, discontinued and inventory is not available.If not then Add to cart button should be visible except if it is discontiued.
                //    product.CanAddToCart = !product.IsDiscontinued;
                if (SiteContext.Current.UserProfileDto == null && !product.IsDiscontinued)
                {
                    product.CanAddToCart = true;
                }
                else if (product.IsDiscontinued)
                {
                    product.CanAddToCart = false;
                }
                //BUSA-771 : If signed in Add to cart button should get hidden if product is suspended, discontinued and inventory is not available.If not then Add to cart button should be visible except if it is discontiued.
                if (currentUser != null)
                {
                    product.CanShowPrice = true;
                }
                else
                {
                    product.CanShowPrice = false;
                }

                // BUSA-463 : Subscription Starts
                if (currentUser != null)
                {
                    var isSubscriptionEligibleCount = currentUser.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("IsCustomerEligibleSubscription")).Count();
                    if (isSubscriptionEligibleCount > 0)
                    {
                        var IsCustomerEligibleSubscription = currentUser.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("IsCustomerEligibleSubscription")).FirstOrDefault().Value;
                        if (!string.IsNullOrEmpty(IsCustomerEligibleSubscription))
                        {
                            if (product.IsSubscription)
                            {
                                if (IsCustomerEligibleSubscription.EqualsIgnoreCase("True") && currentUser.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Count() > 0)
                                {
                                    var SubscriptionDiscount = currentUser.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Value;

                                    // Null check to view the Subcriptio order in Order History.
                                    if (!string.IsNullOrEmpty(SubscriptionDiscount) && product.Pricing != null)
                                    {
                                        var     regularPrice       = product.Pricing.UnitNetPrice;
                                        Decimal percent            = decimal.Parse(SubscriptionDiscount) / new Decimal(100);
                                        var     SubscriptionAmount = NumberHelper.ApplyDiscount(regularPrice, percent);

                                        this.AddOrUpdateProperty(product, "SubscriptionDiscount", SubscriptionDiscount);
                                        // display SubscriptionAmount in desired Format.
                                        this.AddOrUpdateProperty(product, "SubscriptionAmount", String.Format("{0:n}", SubscriptionAmount));
                                        this.AddOrUpdateProperty(product, "IsCustomerEligibleSubscription", IsCustomerEligibleSubscription);
                                    }
                                }
                            }
                        }
                    }
                }
                // BUSA-463 : Subscription Ends
            }
            //BUSA-328 Compare screen does not update price if logging directly into page end
            //BUSA-636 : Pricing 2018. Switch on/off PLP volume group messages.
            var useVolumeGroupPricing = customSettings.UseVolumeGroupPricing;

            result.Properties.Add("useVolumeGroupPricing", useVolumeGroupPricing);
            return(NextHandler.Execute(unitOfWork, parameter, result));
        }
Example #3
0
        public override Decimal ProductDiscount(CustomerOrderPromotion customerOrderPromotion)
        {
            //return customerOrderPromotion.CustomerOrder.OrderLines.Where<OrderLine>((Func<OrderLine, bool>)(o =>
            //{
            //    if (o.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Count() > 0)
            //    {
            //        var IsSubscriptionOpted = o.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Value;

            //        if (!string.IsNullOrEmpty(o.CostCode))
            //        {
            //            return true;
            //        }
            //    }
            //    return false;
            //})).Sum(orderLine =>
            //{
            //    //BUSA-463 Subscription: Get previous ActualPrice to calculate discount for this promotion
            //    if (!string.IsNullOrEmpty(orderLine.CostCode))
            //    {
            //        Decimal actualPrice = decimal.Parse(orderLine.CostCode, CultureInfo.InvariantCulture);

            //        Decimal qtyOrdered = orderLine.QtyOrdered;
            //        HelperUtility helperUtility = new HelperUtility();
            //        var currentCustomer = helperUtility.GetCurrentCustomerFlow(customerOrderPromotion.CustomerOrder);
            //        string amount = string.Empty;
            //        if (currentCustomer == null)
            //        {
            //            currentCustomer = customerOrderPromotion.CustomerOrder.Customer;
            //        }
            //        if (currentCustomer.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Count() > 0)
            //        {
            //            amount = currentCustomer.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Value;
            //        }

            //        if (string.IsNullOrEmpty(amount))
            //        {
            //            return 0;
            //        }
            //        Decimal? subscriptionDiscount = Decimal.Parse(amount, CultureInfo.InvariantCulture);

            //        Decimal percent = subscriptionDiscount.Value / new Decimal(100);

            //        Decimal Act = NumberHelper.ApplyDiscount(actualPrice, percent);

            //        Decimal num = actualPrice - Act;

            //        return NumberHelper.RoundCurrency(qtyOrdered * num);
            //    }
            //    else
            //        return 0;
            //});


            if (customerOrderPromotion.OrderLine != null)
            {
                if (customerOrderPromotion.OrderLine.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Count() > 0)
                {
                    var IsSubscriptionOpted = customerOrderPromotion.OrderLine.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("IsSubscriptionOpted")).Value;

                    if (!string.IsNullOrEmpty(customerOrderPromotion.OrderLine.CostCode))
                    {
                        Decimal actualPrice = decimal.Parse(customerOrderPromotion.OrderLine.CostCode, CultureInfo.InvariantCulture);

                        Decimal       qtyOrdered      = customerOrderPromotion.OrderLine.QtyOrdered;
                        HelperUtility helperUtility   = new HelperUtility();
                        var           currentCustomer = helperUtility.GetCurrentCustomerFlow(customerOrderPromotion.CustomerOrder);
                        string        amount          = string.Empty;
                        if (currentCustomer == null)
                        {
                            currentCustomer = customerOrderPromotion.CustomerOrder.Customer;
                        }
                        if (currentCustomer.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Count() > 0)
                        {
                            amount = currentCustomer.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Value;
                        }

                        if (string.IsNullOrEmpty(amount))
                        {
                            return(0);
                        }
                        Decimal?subscriptionDiscount = Decimal.Parse(amount, CultureInfo.InvariantCulture);

                        Decimal percent = subscriptionDiscount.Value / new Decimal(100);

                        Decimal Act = NumberHelper.ApplyDiscount(actualPrice, percent);

                        Decimal num = actualPrice - Act;

                        return(NumberHelper.RoundCurrency(qtyOrdered * num));
                    }
                }
            }
            return(0);
            //*********************************************************
            //ProductPromotionHelper_Brasseler helper = new ProductPromotionHelper_Brasseler(this.PricingPipeline, this.PromotionProvider);
            //return helper.GetPercentOrAmountProductDiscount(this.PromotionResult, customerOrderPromotion);
        }
Example #4
0
        protected virtual void ApplyDiscountToOrderLines(PromotionResult promotionResult, OrderLine orderLine, CustomerOrder customerOrder)
        {
            CustomerOrderPromotion appliedPromotion = customerOrder.CustomerOrderPromotions.FirstOrDefault <CustomerOrderPromotion>((Func <CustomerOrderPromotion, bool>)(p => p.PromotionId == promotionResult.PromotionId));
            List <OrderLine>       list             = new List <OrderLine>();

            list.Add(orderLine);
            if (SiteContext.Current != null && SiteContext.Current.ShipTo != null)
            {
                if (string.IsNullOrEmpty(orderLine.CostCode))
                {
                    //orderLine.PromotionResult = promotionResult;
                    ProductPromotionHelper_Brasseler    helper = new ProductPromotionHelper_Brasseler(this.pricingPipeline, this.promotionAmountProvider);
                    IDictionary <Guid, ProductPriceDto> pricingServiceResult = helper.GetPricingServiceResult((IEnumerable <OrderLine>)list);
                    ProductPriceDto productPriceDto = pricingServiceResult.First(o => o.Key == orderLine.Id).Value;
                    Decimal         UnitNetPrice    = orderLine.UnitNetPrice;

                    // Check current flow of Customer.
                    HelperUtility helperUtility   = new HelperUtility();
                    var           currentCustomer = helperUtility.GetCurrentCustomerFlow(customerOrder);

                    if (currentCustomer.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Count() > 0)
                    {
                        var amount = currentCustomer.CustomProperties.FirstOrDefault(x => x.Name.EqualsIgnoreCase("SubscriptionDiscount")).Value;

                        if (string.IsNullOrEmpty(amount))
                        {
                            return;
                        }
                        Decimal?subscriptionDiscount = Decimal.Parse(amount, CultureInfo.InvariantCulture);
                        //return if subscription discount is zero
                        if (subscriptionDiscount < 1)
                        {
                            return;
                        }
                        Decimal percent = subscriptionDiscount.Value / new Decimal(100);
                        //BUSA-463 Subscription: Hold previous ActualPrice to calculate discount for this promotion
                        orderLine.CostCode = orderLine.UnitNetPrice.ToString(CultureInfo.InvariantCulture);

                        var num1 = NumberHelper.ApplyDiscount(UnitNetPrice, percent);
                        //if (orderLine.PromotionResult != null)
                        //{
                        //    if (!(orderLine.UnitNetPrice < num1))
                        //    {
                        //        CustomerOrderPromotion deleted = customerOrder.CustomerOrderPromotions.FirstOrDefault<CustomerOrderPromotion>((Func<CustomerOrderPromotion, bool>)(p =>
                        //        {
                        //            Guid? orderLineId = p.OrderLineId;
                        //            Guid id = orderLine.Id;
                        //            if (!orderLineId.HasValue)
                        //                return false;
                        //            if (!orderLineId.HasValue)
                        //                return true;
                        //            return orderLineId.GetValueOrDefault() == id;
                        //        }));
                        //        if (deleted != null)
                        //        {
                        //            customerOrder.CustomerOrderPromotions.Remove(deleted);
                        //            this.UnitOfWork.GetRepository<CustomerOrderPromotion>().Delete(deleted);
                        //        }
                        //    }
                        //    else
                        //        return;
                        //}
                        //orderLine.PromotionResult = promotionResult;
                        orderLine.UnitListPrice     = productPriceDto.UnitListPrice;
                        orderLine.UnitRegularPrice  = productPriceDto.UnitRegularPrice;
                        orderLine.UnitNetPrice      = num1;
                        orderLine.UnitNetPrice      = orderLine.UnitNetPrice < Decimal.Zero ? Decimal.Zero : orderLine.UnitNetPrice;
                        orderLine.TotalRegularPrice = NumberHelper.RoundCurrency(orderLine.UnitListPrice * orderLine.QtyOrdered);
                        orderLine.TotalNetPrice     = NumberHelper.RoundCurrency(orderLine.UnitNetPrice * orderLine.QtyOrdered);
                        this.AddOrUpdateCustomerOrderPromotion(customerOrder, appliedPromotion, orderLine, promotionResult);
                    }
                }
            }
        }