protected override void Exporting(ProductPart part, ExportContentContext context)
        {
            var el = context.Element(typeof(ProductPart).Name);

            el
            .With(part)
            .ToAttr(p => p.Sku)
            .ToAttr(p => p.OutOfStockMessage)
            .ToAttr(p => p.AllowBackOrder)
            .ToAttr(p => p.IsDigital)
            .ToAttr(p => p.ConsiderInventory)
            .ToAttr(p => p.Weight)
            .ToAttr(p => p.OverrideTieredPricing)
            .ToAttr(p => p.MinimumOrderQuantity)
            .ToAttr(p => p.AuthenticationRequired);
            el.SetAttributeValue("Inventory", _productInventoryService.GetInventory(part));
            el.SetAttributeValue("Price", part.Price.ToString("C", CultureInfo.InvariantCulture));
            el.SetAttributeValue("DiscountPrice", part.DiscountPrice.ToString("C", CultureInfo.InvariantCulture));
            el.SetAttributeValue("PriceTiers", PriceTier.SerializePriceTiers(part.PriceTiers));
            if (part.ShippingCost != null)
            {
                el.SetAttributeValue(
                    "ShippingCost", ((double)part.ShippingCost).ToString("C", CultureInfo.InvariantCulture));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Upsert(PriceTier priceTier)
        {
            if (ModelState.IsValid)
            {
                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

                int?pgId = (await _unitOfWork.PG.GetAsync(claim.Value, false, false, false))?.Id;
                if (pgId != null)
                {
                    if (priceTier.Id == 0)
                    {
                        priceTier.PGId = (int)pgId;
                        await _unitOfWork.PriceTier.AddAsync(priceTier);
                    }
                    else
                    {
                        await _unitOfWork.PriceTier.UpdateAsync(priceTier);
                    }
                    _unitOfWork.Save();
                }
            }
            else
            {
                return(View(priceTier));
            }

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #3
0
        protected override void Exporting(ProductSettingsPart part, ExportContentContext context)
        {
            var el = context.Element(typeof(ProductSettingsPart).Name);

            el
            .With(part)
            .ToAttr(p => p.DefineSiteDefaults)
            .ToAttr(p => p.AllowProductOverrides);
            el.SetAttributeValue("PriceTiers", PriceTier.SerializePriceTiers(part.PriceTiers));
        }
Beispiel #4
0
        protected override void Importing(ProductSettingsPart part, ImportContentContext context)
        {
            var el = context.Data.Element(typeof(ProductSettingsPart).Name);

            if (el == null)
            {
                return;
            }
            el.With(part)
            .FromAttr(p => p.DefineSiteDefaults)
            .FromAttr(p => p.AllowProductOverrides);
            part.PriceTiers = PriceTier.DeserializePriceTiers(el.Attr("PriceTiers"));
        }
        protected override void Importing(ProductPart part, ImportContentContext context)
        {
            var el = context.Data.Element(typeof(ProductPart).Name);

            if (el == null)
            {
                return;
            }
            el.With(part)
            .FromAttr(p => p.Sku)
            .FromAttr(p => p.Inventory)
            .FromAttr(p => p.OutOfStockMessage)
            .FromAttr(p => p.AllowBackOrder)
            .FromAttr(p => p.IsDigital)
            .FromAttr(p => p.ConsiderInventory)
            .FromAttr(p => p.Weight)
            .FromAttr(p => p.OverrideTieredPricing)
            .FromAttr(p => p.MinimumOrderQuantity)
            .FromAttr(p => p.AuthenticationRequired);
            var     priceAttr = el.Attribute("Price");
            decimal price;

            if (priceAttr != null &&
                decimal.TryParse(priceAttr.Value, NumberStyles.Currency, CultureInfo.InvariantCulture, out price))
            {
                part.Price = price;
            }
            var     discountPriceAttr = el.Attribute("DiscountPrice");
            decimal discountPrice;

            if (discountPriceAttr != null &&
                decimal.TryParse(discountPriceAttr.Value, NumberStyles.Currency, CultureInfo.InvariantCulture, out discountPrice))
            {
                part.DiscountPrice = discountPrice;
            }
            var priceTiersAttr = el.Attribute("PriceTiers");

            if (priceTiersAttr != null)
            {
                part.PriceTiers = PriceTier.DeserializePriceTiers(priceTiersAttr.Value);
            }
            var     shippingCostAttr = el.Attribute("ShippingCost");
            decimal shippingCost;

            if (shippingCostAttr != null &&
                decimal.TryParse(shippingCostAttr.Value, NumberStyles.Currency, CultureInfo.InvariantCulture,
                                 out shippingCost))
            {
                part.ShippingCost = shippingCost;
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Upsert(int id)
        {
            PriceTier priceTier;

            if (id == 0)
            {
                priceTier = new PriceTier();
            }
            else
            {
                priceTier = await _unitOfWork.PriceTier.GetAsync(id);
            }

            return(View(priceTier));
        }
Beispiel #7
0
        private async Task <bool?> CalculateCartLinePrice(
            CartLineComponent arg,
            CommercePipelineExecutionContext context)
        {
            ProductArgument productArgument = ProductArgument.FromItemId(arg.ItemId);
            SellableItem    sellableItem    = null;

            if (productArgument.IsValid())
            {
                sellableItem = context.CommerceContext.GetEntity((Func <SellableItem, bool>)(s => s.ProductId.Equals(productArgument.ProductId, StringComparison.OrdinalIgnoreCase)));

                if (sellableItem == null)
                {
                    string simpleName = productArgument.ProductId.SimplifyEntityName();
                    sellableItem = context.CommerceContext.GetEntity((Func <SellableItem, bool>)(s => s.ProductId.Equals(simpleName, StringComparison.OrdinalIgnoreCase)));

                    if (sellableItem != null)
                    {
                        sellableItem.ProductId = simpleName;
                    }
                }
            }
            if (sellableItem == null)
            {
                CommercePipelineExecutionContext executionContext = context;
                CommerceContext commerceContext = context.CommerceContext;
                string          error           = context.GetPolicy <KnownResultCodes>().Error;
                object[]        args            = new object[] { arg.ItemId };
                string          defaultMessage  = "Item '" + arg.ItemId + "' is not purchasable.";
                executionContext.Abort(await commerceContext.AddMessage(error, "LineIsNotPurchasable", args, defaultMessage), context);
                executionContext = null;
                return(new bool?());
            }

            MessagesComponent messagesComponent = arg.GetComponent <MessagesComponent>();

            messagesComponent.Clear(context.GetPolicy <KnownMessageCodePolicy>().Pricing);

            if (sellableItem.HasComponent <MessagesComponent>())
            {
                List <MessageModel> messages = sellableItem.GetComponent <MessagesComponent>().GetMessages(context.GetPolicy <KnownMessageCodePolicy>().Pricing);
                messagesComponent.AddMessages(messages);
            }
            arg.UnitListPrice = sellableItem.ListPrice;
            string listPriceMessage = "CartItem.ListPrice<=SellableItem.ListPrice: Price=" + arg.UnitListPrice.AsCurrency(false, null);
            string sellPriceMessage = string.Empty;
            PurchaseOptionMoneyPolicy optionMoneyPolicy = new PurchaseOptionMoneyPolicy();

            if (sellableItem.HasPolicy <PurchaseOptionMoneyPolicy>())
            {
                optionMoneyPolicy.SellPrice = sellableItem.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice;
                sellPriceMessage            = "CartItem.SellPrice<=SellableItem.SellPrice: Price=" + optionMoneyPolicy.SellPrice.AsCurrency(false, null);
            }

            PriceSnapshotComponent snapshotComponent;

            if (sellableItem.HasComponent <ItemVariationsComponent>())
            {
                ItemVariationSelectedComponent lineVariant             = arg.ChildComponents.OfType <ItemVariationSelectedComponent>().FirstOrDefault();
                ItemVariationsComponent        itemVariationsComponent = sellableItem.GetComponent <ItemVariationsComponent>();
                ItemVariationComponent         itemVariationComponent;

                if (itemVariationsComponent == null)
                {
                    itemVariationComponent = null;
                }
                else
                {
                    IList <Component> childComponents = itemVariationsComponent.ChildComponents;
                    itemVariationComponent = childComponents?.OfType <ItemVariationComponent>().FirstOrDefault(v =>
                    {
                        return(!string.IsNullOrEmpty(v.Id) ? v.Id.Equals(lineVariant?.VariationId, StringComparison.OrdinalIgnoreCase) : false);
                    });
                }

                if (itemVariationComponent != null)
                {
                    if (itemVariationComponent.HasComponent <MessagesComponent>())
                    {
                        List <MessageModel> messages = itemVariationComponent.GetComponent <MessagesComponent>().GetMessages(context.GetPolicy <KnownMessageCodePolicy>().Pricing);
                        messagesComponent.AddMessages(messages);
                    }

                    arg.UnitListPrice = itemVariationComponent.ListPrice;
                    listPriceMessage  = "CartItem.ListPrice<=SellableItem.Variation.ListPrice: Price=" + arg.UnitListPrice.AsCurrency(false, null);

                    if (itemVariationComponent.HasPolicy <PurchaseOptionMoneyPolicy>())
                    {
                        optionMoneyPolicy.SellPrice = itemVariationComponent.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice;
                        sellPriceMessage            = "CartItem.SellPrice<=SellableItem.Variation.SellPrice: Price=" + optionMoneyPolicy.SellPrice.AsCurrency(false, null);
                    }
                }
                snapshotComponent = itemVariationComponent != null?itemVariationComponent.ChildComponents.OfType <PriceSnapshotComponent>().FirstOrDefault() : null;
            }
            else
            {
                snapshotComponent = sellableItem.Components.OfType <PriceSnapshotComponent>().FirstOrDefault();
            }

            string currentCurrency = context.CommerceContext.CurrentCurrency();

            PriceTier priceTier = snapshotComponent?.Tiers.OrderByDescending(t => t.Quantity).FirstOrDefault(t =>
            {
                return(t.Currency.Equals(currentCurrency, StringComparison.OrdinalIgnoreCase) ? t.Quantity <= arg.Quantity : false);
            });

            Customer customer = await _findEntityPipeline.Run(new FindEntityArgument(typeof(Customer), context.CommerceContext.CurrentCustomerId(), false), context) as Customer;

            bool isMembershipLevelPrice = false;

            if (customer != null && customer.HasComponent <MembershipSubscriptionComponent>())
            {
                var membershipSubscriptionComponent = customer.GetComponent <MembershipSubscriptionComponent>();
                var membershipLevel = membershipSubscriptionComponent.MemerbshipLevelName;

                if (snapshotComponent != null && snapshotComponent.HasComponent <MembershipTiersComponent>())
                {
                    var membershipTiersComponent = snapshotComponent.GetComponent <MembershipTiersComponent>();
                    var membershipPriceTier      = membershipTiersComponent.Tiers.FirstOrDefault(x => x.MembershipLevel == membershipLevel);

                    if (membershipPriceTier != null)
                    {
                        optionMoneyPolicy.SellPrice = new Money(membershipPriceTier.Currency, membershipPriceTier.Price);
                        isMembershipLevelPrice      = true;

                        sellPriceMessage = string.Format("CartItem.SellPrice<=PriceCard.ActiveSnapshot: MembershipLevel={0}|Price={1}|Qty={2}", membershipSubscriptionComponent.MemerbshipLevelName, optionMoneyPolicy.SellPrice.AsCurrency(false, null), membershipPriceTier.Quantity);
                    }
                }
            }

            if (!isMembershipLevelPrice && priceTier != null)
            {
                optionMoneyPolicy.SellPrice = new Money(priceTier.Currency, priceTier.Price);
                sellPriceMessage            = string.Format("CartItem.SellPrice<=PriceCard.ActiveSnapshot: Price={0}|Qty={1}", optionMoneyPolicy.SellPrice.AsCurrency(false, null), priceTier.Quantity);
            }

            arg.Policies.Remove(arg.Policies.OfType <PurchaseOptionMoneyPolicy>().FirstOrDefault());

            if (optionMoneyPolicy.SellPrice == null)
            {
                return(false);
            }

            arg.SetPolicy(optionMoneyPolicy);

            if (!string.IsNullOrEmpty(sellPriceMessage))
            {
                messagesComponent.AddMessage(context.GetPolicy <KnownMessageCodePolicy>().Pricing, sellPriceMessage);
            }

            if (!string.IsNullOrEmpty(listPriceMessage))
            {
                messagesComponent.AddMessage(context.GetPolicy <KnownMessageCodePolicy>().Pricing, listPriceMessage);
            }

            return(true);
        }
Beispiel #8
0
        public static float GetPriceByTier(PriceTier priceTier)
        {
            int tierint = (int)priceTier;

            tierint++;

            float price = 0f;

            float tier = (float)tierint;

            if (tier < 51)
            {
                price = tier - 0.01f;
            }
            else if (tier < 61)
            {
                float dif = tier - 50f;
                price = 50f + (dif * 5f) - 0.01f;
            }
            else
            {
                switch (tierint)
                {
                case 61:
                    price = 109.99f;
                    break;

                case 62:
                    price = 119.99f;
                    break;

                case 63:
                    price = 124.99f;
                    break;

                case 64:
                    price = 129.99f;
                    break;


                case 65:
                    price = 139.99f;
                    break;


                case 66:
                    price = 149.99f;
                    break;


                case 67:
                    price = 159.99f;
                    break;


                case 68:
                    price = 169.99f;
                    break;


                case 69:
                    price = 174.99f;
                    break;


                case 70:
                    price = 179.99f;
                    break;



                case 72:
                    price = 199.99f;
                    break;


                case 73:
                    price = 209.99f;
                    break;


                case 74:
                    price = 219.99f;
                    break;


                case 75:
                    price = 229.99f;
                    break;



                case 76:
                    price = 239.99f;
                    break;


                case 77:
                    price = 249.99f;
                    break;

                case 78:
                    price = 299.99f;
                    break;


                case 79:
                    price = 349.99f;
                    break;


                case 80:
                    price = 399.99f;
                    break;


                case 81:
                    price = 449.99f;
                    break;


                case 82:
                    price = 499.99f;
                    break;


                case 83:
                    price = 599.99f;
                    break;

                case 84:
                    price = 699.99f;
                    break;

                case 85:
                    price = 799.99f;
                    break;

                case 86:
                    price = 899.99f;
                    break;

                case 87:
                    price = 999.99f;
                    break;
                }
            }



            return(price);
        }
Beispiel #9
0
        public override async Task <SellableItem> Run(
            SellableItem arg,
            CommercePipelineExecutionContext context)
        {
            if (arg == null)
            {
                return(null);
            }

            if (arg.HasPolicy <PurchaseOptionMoneyPolicy>() && arg.GetPolicy <PurchaseOptionMoneyPolicy>().Expires > DateTimeOffset.UtcNow && arg.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice.CurrencyCode.Equals(context.CommerceContext.CurrentCurrency(), StringComparison.OrdinalIgnoreCase))
            {
                return(arg);
            }

            if (arg.HasComponent <PriceSnapshotComponent>())
            {
                arg.Components.Remove(arg.GetComponent <PriceSnapshotComponent>());
            }

            string                 currentCurrency   = context.CommerceContext.CurrentCurrency();
            MessagesComponent      messagesComponent = arg.GetComponent <MessagesComponent>();
            Money                  sellPrice         = null;
            PriceCardPolicy        priceCardPolicy   = arg.Policies.OfType <PriceCardPolicy>().FirstOrDefault();
            PriceSnapshotComponent snapshotComponent = null;
            bool pricingByTags = false;

            if (!string.IsNullOrEmpty(priceCardPolicy?.PriceCardName))
            {
                snapshotComponent = await _resolveSnapshotByCardPipeline.Run(priceCardPolicy.PriceCardName, context);
            }
            else if (arg.Tags.Any())
            {
                snapshotComponent = await _resolveSnapshotByTagsPipeline.Run(arg.Tags, context);

                pricingByTags = true;
            }

            PriceTier priceTier = snapshotComponent?.Tiers.FirstOrDefault(t =>
            {
                return(t.Currency.Equals(currentCurrency, StringComparison.OrdinalIgnoreCase) ? t.Quantity == decimal.One : false);
            });

            Customer customer = await _findEntityPipeline.Run(new FindEntityArgument(typeof(Customer), context.CommerceContext.CurrentCustomerId(), false), context) as Customer;

            bool isMembershipLevelPrice = false;

            if (customer != null && customer.HasComponent <MembershipSubscriptionComponent>())
            {
                var membershipSubscriptionComponent = customer.GetComponent <MembershipSubscriptionComponent>();
                var customerMemerbshipLevelName     = membershipSubscriptionComponent.MemerbshipLevelName;
                var memerbshipLevelName             = membershipSubscriptionComponent.MemerbshipLevelName;

                if (snapshotComponent != null && snapshotComponent.HasComponent <MembershipTiersComponent>())
                {
                    var membershipTiersComponent = snapshotComponent.GetComponent <MembershipTiersComponent>();
                    var membershipPriceTier      = membershipTiersComponent.Tiers.FirstOrDefault(x => x.MembershipLevel == memerbshipLevelName);

                    if (membershipPriceTier != null)
                    {
                        sellPrice = new Money(membershipPriceTier.Currency, membershipPriceTier.Price);
                        isMembershipLevelPrice = true;
                        messagesComponent.AddMessage(context.GetPolicy <KnownMessageCodePolicy>().Pricing, pricingByTags
                            ? string.Format("SellPrice<=Tags.Snapshot: MembershipLevel={0}|Price={1}|Qty={2}|Tags='{3}'", customerMemerbshipLevelName, sellPrice.AsCurrency(false, null), membershipPriceTier.Quantity, string.Join(", ", snapshotComponent.Tags.Select(c => c.Name)))
                            : string.Format("SellPrice<=PriceCard.Snapshot: MembershipLevel={0}|Price={1}|Qty={2}|PriceCard={3}", customerMemerbshipLevelName, sellPrice.AsCurrency(false, null), membershipPriceTier.Quantity, priceCardPolicy.PriceCardName));
                    }
                }
            }

            if (!isMembershipLevelPrice && priceTier != null)
            {
                sellPrice = new Money(priceTier.Currency, priceTier.Price);
                messagesComponent.AddMessage(context.GetPolicy <KnownMessageCodePolicy>().Pricing, pricingByTags ? string.Format("SellPrice<=Tags.Snapshot: Price={0}|Qty={1}|Tags='{2}'", sellPrice.AsCurrency(false, null), priceTier.Quantity, string.Join(", ", snapshotComponent.Tags.Select(c => c.Name))) : string.Format("SellPrice<=PriceCard.Snapshot: Price={0}|Qty={1}|PriceCard={2}", sellPrice.AsCurrency(false, null), priceTier.Quantity, priceCardPolicy.PriceCardName));
            }

            if (snapshotComponent != null)
            {
                arg.SetComponent(snapshotComponent);
            }

            if (sellPrice != null)
            {
                arg.SetPolicy(new PurchaseOptionMoneyPolicy()
                {
                    SellPrice = sellPrice
                });
            }

            return(arg);
        }