コード例 #1
0
                public void SellableItemCompare_ByImportData_ListPricingTest_04_DifferentCount(
                    SellableItem ItemA,
                    List <Money> PricesA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.GetPolicy <ListPricingPolicy>().AddPrices(PricesA);
                    var ItemB  = ItemA.Clone();
                    var policy = ItemA.GetPolicy <ListPricingPolicy>();

                    policy.RemovePrice(policy.Prices.Cast <Money>().First());

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count().Should().NotBe(ItemB.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count());
                    result.Should().BeFalse();
                }
コード例 #2
0
                public void SellableItemCompare_ByImportData_ListPricingTest_08_AreEqual(
                    SellableItem ItemA,
                    List <Money> PricesA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.GetPolicy <ListPricingPolicy>().AddPrices(PricesA);
                    var ItemB = ItemA.Clone();

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count().Should().BeGreaterThan(0);
                    ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count().Should().Be(ItemB.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count());
                    result.Should().BeTrue();
                }
コード例 #3
0
                public void SellableItemCompare_ByImportData_ListPricingTest_03_PoliciesBoth_IsNull(
                    SellableItem ItemA,
                    List <Money> PricesA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.GetPolicy <ListPricingPolicy>().AddPrices(PricesA);
                    var ItemB = ItemA.Clone();

                    ItemA.Policies = null;
                    ItemB.Policies = null;

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    result.Should().BeTrue();
                }
        private SellableItem TransformCore(CommerceContext commerceContext, JToken rawLine, List <SellableItem> importItems)
        {
            var productId = rawLine[ProductIdIndex].ToString();
            var id        = productId.ToEntityId <SellableItem>();

            var item = importItems.FirstOrDefault(i => i.Id.Equals(id));

            if (item == null)
            {
                item             = new SellableItem();
                item.ProductId   = productId;
                item.Id          = id;
                item.FriendlyId  = item.ProductId;
                item.Name        = rawLine[ProductNameIndex].ToString();
                item.SitecoreId  = GuidUtils.GetDeterministicGuidString(item.Id);
                item.DisplayName = rawLine[DisplayNameIndex].ToString();
                item.TypeOfGood  = rawLine[TypeOfGoodIndex].ToString();

                var listPricePolicy = item.GetPolicy <ListPricingPolicy>();
                listPricePolicy.AddPrice(new Money
                {
                    CurrencyCode = "USD",
                    Amount       = decimal.Parse(rawLine[ListPriceIndex].ToString())
                });

                var component = item.GetComponent <ListMembershipsComponent>();
                component.Memberships.Add(string.Format("{0}", CommerceEntity.ListName <SellableItem>()));
                component.Memberships.Add(commerceContext.GetPolicy <KnownCatalogListsPolicy>().CatalogItems);

                importItems.Add(item);
            }

            return(item);
        }
 protected virtual bool GetPricingStatus(SellableItem sellableItem, string variantId)
 {
     if (string.IsNullOrWhiteSpace(variantId))
     {
         return(sellableItem.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice != null);
     }
     else
     {
         var variant = sellableItem.GetVariation(variantId);
         return(variant.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice != null);
     }
 }
コード例 #6
0
                public void SellableItemCompare_ByImportData_ListPricingTest_05_SameCount_EachListWithDifferentDuplicates(
                    SellableItem ItemA,
                    List <Money> PricesA)
                {
                    /**********************************************
                    * Arrange
                    **********************************************/
                    var comparer = new ImportSellableItemComparer(SellableItemComparerConfiguration.ByImportData);

                    ItemA.GetPolicy <ListPricingPolicy>().AddPrices(PricesA);
                    var ItemB             = ItemA.Clone();
                    var initialPriceCount = ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count();
                    var policyA           = ItemA.GetPolicy <ListPricingPolicy>();

                    policyA.AddPrice(policyA.Prices.Cast <Money>().ElementAt(0).Clone());
                    var policyB = ItemA.GetPolicy <ListPricingPolicy>();

                    policyB.AddPrice(policyB.Prices.Cast <Money>().ElementAt(2).Clone());

                    /**********************************************
                    * Act
                    **********************************************/
                    bool   result        = false;
                    Action executeAction = () => result = comparer.Equals(ItemA, ItemB);

                    /**********************************************
                    * Assert
                    **********************************************/
                    executeAction.Should().NotThrow <Exception>();
                    ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count().Should().Be(ItemB.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count());
                    // Turns out we can't add duplicates. If this behaviour every changes, you will need to revist.
                    ItemA.GetPolicy <ListPricingPolicy>().Prices.Cast <Money>().Count().Should().Be(initialPriceCount);
                    result.Should().BeTrue();
                }
        private async Task CopyCategoryAddressRemoved(CommerceContext commerceContext, SellableItem existingItem, List <string> associationsToRemove)
        {
            if (associationsToRemove == null || associationsToRemove.Count().Equals(0))
            {
                return;
            }

            var transientData = existingItem.GetPolicy <TransientImportSellableItemDataPolicy>();

            var allCatalogs = commerceContext.GetObject <IEnumerable <Sitecore.Commerce.Plugin.Catalog.Catalog> >();

            if (allCatalogs == null)
            {
                allCatalogs = await Command <GetCatalogsCommand>().Process(commerceContext);

                commerceContext.AddObject(allCatalogs);
            }

            var existingCatalogSitecoreIdList = existingItem.ParentCatalogList.Split('|');

            var catalogNameList = new List <string>();

            foreach (var catalogSitecoreId in existingCatalogSitecoreIdList)
            {
                var catalog = allCatalogs.FirstOrDefault(c => c.SitecoreId.Equals(catalogSitecoreId));
                catalogNameList.Add(catalog.Name);
            }

            var catalogContextList = await Command <GetCatalogContextCommand>().Process(commerceContext, catalogNameList);

            foreach (var categoryToRemoveSitecoreId in associationsToRemove)
            {
                bool found = false;
                foreach (var catalogContext in catalogContextList)
                {
                    catalogContext.CategoriesBySitecoreId.TryGetValue(categoryToRemoveSitecoreId, out Category category);

                    if (category != null)
                    {
                        transientData.ParentAssociationsToRemoveList.Add(new CatalogItemParentAssociationModel(existingItem.Id, catalogContext.Catalog.Id, category));

                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    commerceContext.Logger.LogWarning($"Unable to find category with SitecoreId {categoryToRemoveSitecoreId}. We need to disacciate it from SellableItem {existingItem.Id}");
                }
            }
        }
        //public static void AddListPrice(this ImportSellableItemResponse sellableItem, decimal sellableItemListPrice)
        //{
        //    var listPricingPolicy = sellableItem.SellableItem.GetPolicy<ListPricingPolicy>();
        //    listPricingPolicy.ClearPrices();
        //    if (sellableItemListPrice == 0)
        //    {
        //        return;
        //    }
        //    listPricingPolicy.AddPrice(new Money("USD", sellableItemListPrice));
        //}

        public static decimal GetLisPrice(this SellableItem sellableItem)
        {
            if (!sellableItem.HasPolicy(typeof(ListPricingPolicy)))
            {
                return(0);
            }
            var listPricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>();

            if (listPricingPolicy == null || listPricingPolicy.Prices == null || listPricingPolicy.Prices.Count() < 1)
            {
                return(0);
            }

            return(listPricingPolicy.Prices.ToList()[0].Amount);
        }
コード例 #9
0
        private static void MapPricingEntities(SellableItem sellableItem, CsvImportLine csvImportLine)
        {
            var pricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>();

            foreach (var listPrice in csvImportLine.ListPrices)
            {
                var moneyEntity = pricingPolicy.Prices.FirstOrDefault(x => x.CurrencyCode == listPrice.CurrencyCode);
                if (moneyEntity != null)
                {
                    moneyEntity.Amount = listPrice.Amount;
                }
                else
                {
                    var money = new Money(listPrice.CurrencyCode, listPrice.Amount);
                    (pricingPolicy.Prices as List <Money>)?.Add(money);
                }
            }
        }
        protected async virtual Task <PricingModel> CreatePricingModel(SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context)
        {
            PricingModel pricingModel = null;

            if (string.IsNullOrWhiteSpace(variantId))
            {
                pricingModel = new PricingModel(sellableItem.ListPrice, sellableItem.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice, sellableItem.GetComponent <MessagesComponent>());
            }
            else
            {
                var variation = sellableItem.GetVariation(variantId);
                if (variation == null)
                {
                    return(await Task.FromResult(pricingModel).ConfigureAwait(false));
                }

                pricingModel = new PricingModel(variation.ListPrice, variation.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice, variation.GetComponent <MessagesComponent>());
            }

            return(await Task.FromResult(pricingModel).ConfigureAwait(false));
        }
コード例 #11
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);
        }
コード例 #12
0
        private void AddSellableItemPricing(EntityView entityView, SellableItem entity, ItemVariationComponent variation, CommercePipelineExecutionContext context)
        {
            var policy      = context.GetPolicy <KnownCatalogViewsPolicy>();
            var entityView1 = new EntityView
            {
                Name          = policy.SellableItemPricing,
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = variation != null ? variation.Id : string.Empty,
                UiHint        = "Flat"
            };
            var entityView2 = entityView1;
            var entityView3 = new EntityView
            {
                Name          = policy.SellableItemListPricing,
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = variation != null ? variation.Id : string.Empty,
                UiHint        = "Table"
            };
            var entityView4 = entityView3;

            if (entity != null)
            {
                var str = variation != null?variation.GetPolicy <PriceCardPolicy>().PriceCardName : entity.GetPolicy <PriceCardPolicy>().PriceCardName;

                var properties1   = entityView2.Properties;
                var viewProperty1 = new ViewProperty
                {
                    Name       = "PriceCardName",
                    RawValue   = str ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties1.Add(viewProperty1);
                foreach (var price in (variation != null ? variation.GetPolicy <ListPricingPolicy>() : entity.GetPolicy <ListPricingPolicy>()).Prices)
                {
                    var entityView5 = new EntityView
                    {
                        Name     = context.GetPolicy <KnownCatalogViewsPolicy>().Summary,
                        EntityId = entityView.EntityId,
                        ItemId   = (variation != null ? variation.Id : string.Empty) + "|" + price.CurrencyCode,
                        UiHint   = "Flat"
                    };
                    var entityView6   = entityView5;
                    var properties2   = entityView6.Properties;
                    var viewProperty2 = new ViewProperty
                    {
                        Name     = "Currency",
                        RawValue = price.CurrencyCode
                    };
                    properties2.Add(viewProperty2);
                    var properties3   = entityView6.Properties;
                    var viewProperty3 = new ViewProperty
                    {
                        Name     = "ListPrice",
                        RawValue = price.Amount
                    };
                    properties3.Add(viewProperty3);
                    entityView4.ChildViews.Add(entityView6);
                }
            }
            entityView2.ChildViews.Add(entityView4);
            entityView.ChildViews.Add(entityView2);
        }
コード例 #13
0
        public async Task <ItemType> PrepareItem(CommerceContext commerceContext, SellableItem sellableItem)
        {
            using (var activity = CommandActivity.Start(commerceContext, this))
            {
                //Instantiate the call wrapper class
                var apiCall = new AddFixedPriceItemCall(await GetEbayContext(commerceContext).ConfigureAwait(false));

                var item = await this._commerceCommander.Pipeline <IPrepareEbayItemPipeline>().Run(sellableItem, commerceContext.PipelineContextOptions).ConfigureAwait(false);

                item.Description = sellableItem.Description;
                item.Title       = sellableItem.DisplayName;
                item.SubTitle    = "Test Item";

                var listPricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>();
                var listPrice         = listPricingPolicy.Prices.FirstOrDefault();

                item.StartPrice = new AmountType {
                    currencyID = CurrencyCodeType.USD, Value = System.Convert.ToDouble(listPrice.Amount, System.Globalization.CultureInfo.InvariantCulture)
                };

                item.ConditionID = 1000;  //new

                item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection();
                item.PaymentMethods.Add(BuyerPaymentMethodCodeType.PayPal);
                item.PaymentMethods.Add(BuyerPaymentMethodCodeType.VisaMC);
                item.PayPalEmailAddress = "*****@*****.**";
                item.PostalCode         = "98014";

                item.DispatchTimeMax = 3;
                item.ShippingDetails = new ShippingDetailsType();
                item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection();

                item.ShippingDetails.ShippingType = ShippingTypeCodeType.Flat;

                ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType();
                shipservice1.ShippingService                = "USPSPriority";
                shipservice1.ShippingServicePriority        = 1;
                shipservice1.ShippingServiceCost            = new AmountType();
                shipservice1.ShippingServiceCost.currencyID = CurrencyCodeType.USD;
                shipservice1.ShippingServiceCost.Value      = 5.0;

                shipservice1.ShippingServiceAdditionalCost            = new AmountType();
                shipservice1.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.USD;
                shipservice1.ShippingServiceAdditionalCost.Value      = 1.0;

                item.ShippingDetails.ShippingServiceOptions.Add(shipservice1);


                //ShippingServiceOptionsType shipservice2 = new ShippingServiceOptionsType();
                //shipservice2.ShippingService = "US_Regular";
                //shipservice2.ShippingServicePriority = 2;
                //shipservice2.ShippingServiceCost = new AmountType();
                //shipservice2.ShippingServiceCost.currencyID = CurrencyCodeType.USD;
                //shipservice2.ShippingServiceCost.Value = 1.0;

                //shipservice2.ShippingServiceAdditionalCost = new AmountType();
                //shipservice2.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.USD;
                //shipservice2.ShippingServiceAdditionalCost.Value = 1.0;

                //item.ShippingDetails.ShippingServiceOptions.Add(shipservice2);

                //item.Variations.

                item.ReturnPolicy = new ReturnPolicyType {
                    ReturnsAcceptedOption = "ReturnsAccepted"
                };

                //Add pictures
                item.PictureDetails = new PictureDetailsType();

                //Specify GalleryType
                item.PictureDetails.GalleryType          = GalleryTypeCodeType.None;
                item.PictureDetails.GalleryTypeSpecified = true;

                return(item);
            }
        }
コード例 #14
0
        public override async Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires <Cart>(arg).IsNotNull <Cart>(string.Format("{0}: the cart can not be null.", (object)this.Name));
            if (arg.HasComponent <TemporaryCartComponent>())
            {
                return(arg);
            }

            AddToCartBundlesBlock addBundlesBlock = this;

            context.CommerceContext.AddObject((object)arg);
            Cart cart = arg;

            FindEntityArgument getSavedCartArg = new FindEntityArgument(typeof(Cart), arg.Id, false);
            Cart savedCart = await this._findEntityPipeline.Run(getSavedCartArg, (CommercePipelineExecutionContext)context).ConfigureAwait(false) as Cart;

            CartLineComponent existingLine;

            IList <CartLineComponent> savedCartLines   = new List <CartLineComponent>();
            IList <CartLineComponent> currentCartLines = new List <CartLineComponent>();

            if (savedCart == null)
            {
                existingLine = arg.Lines.FirstOrDefault <CartLineComponent>();
            }
            else
            {
                savedCartLines   = savedCart.Lines;
                currentCartLines = cart.Lines;
                var addedCartLine = cart.Lines.Where(l => savedCartLines.Where(sc => sc.Id == l.Id).FirstOrDefault() == null).FirstOrDefault();
                existingLine = addedCartLine;
            }
            if (existingLine != null)
            {
                FindEntityArgument getProductArg  = new FindEntityArgument(typeof(SellableItem), "Entity-SellableItem-" + (existingLine.ItemId.Split('|').Count() > 1 ? existingLine.ItemId.Split('|')[1] : existingLine.ItemId), false);
                SellableItem       carLineProduct = await this._findEntityPipeline.Run(getProductArg, (CommercePipelineExecutionContext)context).ConfigureAwait(false) as SellableItem;

                bool hasTag = carLineProduct.Tags.Any <Tag>((Func <Tag, bool>)(t => t.Name.Equals("bundle", StringComparison.OrdinalIgnoreCase)));

                if (hasTag)
                {
                    string listId = String.Format("relatedproduct-{0}", existingLine.ItemId.Split('|').Count() > 1 ? existingLine.ItemId.Split('|')[1] : existingLine.ItemId);

                    var relatedProducts = await _findEntitiesInListPipeline.Run(
                        new FindEntitiesInListArgument(typeof(CommerceEntity), listId, 0, 10)
                    {
                        LoadEntities = true
                    },
                        context);

                    foreach (var relProd in relatedProducts.List.Items)
                    {
                        if (savedCartLines.Any(l => l.ItemId.Contains(relProd.FriendlyId)) || currentCartLines.Any(l => l.ItemId.Contains(relProd.FriendlyId)))
                        {
                            FindEntityArgument getRelatedProductArg = new FindEntityArgument(typeof(SellableItem), "Entity-SellableItem-" + relProd.FriendlyId, false);
                            SellableItem       relatedProduct       = await this._findEntityPipeline.Run(getRelatedProductArg, (CommercePipelineExecutionContext)context).ConfigureAwait(false) as SellableItem;

                            string listPrice = String.Empty;
                            if (relatedProduct.HasPolicy <ListPricingPolicy>())
                            {
                                ListPricingPolicy policy = relatedProduct.GetPolicy <ListPricingPolicy>();
                                listPrice = policy.Prices.FirstOrDefault().Amount.ToString();
                            }
                            existingLine.Comments += relProd.FriendlyId + ',' + relProd.DisplayName + ',' + listPrice + '|';
                        }
                    }

                    cart.Lines.Remove(existingLine);
                }
            }
            return(cart);
        }
コード例 #15
0
        public async Task <ItemType> PrepareItem(CommerceContext commerceContext, SellableItem sellableItem)
        {
            ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType
            {
                ShippingService         = "USPSPriority",
                ShippingServicePriority = 1,
                ShippingServiceCost     = new AmountType {
                    currencyID = CurrencyCodeType.USD, Value = 5.0
                }
            };

            using (CommandActivity.Start(commerceContext, this))
            {
                var item = await this._commerceCommander.Pipeline <IPrepareEbayItemPipeline>().Run(sellableItem, commerceContext.GetPipelineContextOptions());

                item.Description = sellableItem.Description;
                item.Title       = sellableItem.DisplayName;
                item.SubTitle    = "Test Item";

                var listPricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>();
                var listPrice         = listPricingPolicy.Prices.FirstOrDefault();

                item.StartPrice = new AmountType {
                    currencyID = CurrencyCodeType.USD, Value = System.Convert.ToDouble(listPrice.Amount)
                };

                item.ConditionID = 1000;

                item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection
                {
                    BuyerPaymentMethodCodeType.PayPal, BuyerPaymentMethodCodeType.VisaMC
                };
                item.PayPalEmailAddress = "*****@*****.**";
                item.PostalCode         = "98014";

                item.DispatchTimeMax = 3;
                item.ShippingDetails = new ShippingDetailsType
                {
                    ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(),
                    ShippingType           = ShippingTypeCodeType.Flat
                };

                shipservice1.ShippingServiceAdditionalCost = new AmountType
                {
                    currencyID = CurrencyCodeType.USD, Value = 1.0
                };

                item.ShippingDetails.ShippingServiceOptions.Add(shipservice1);

                item.ReturnPolicy = new ReturnPolicyType {
                    ReturnsAcceptedOption = "ReturnsAccepted"
                };

                // Add pictures
                item.PictureDetails = new PictureDetailsType
                {
                    GalleryType = GalleryTypeCodeType.None, GalleryTypeSpecified = true
                };

                return(item);
            }
        }
        private void CopyCategoryAddressAdded(CommerceContext commerceContext, SellableItem existingItem, List <string> associationsToCreate)
        {
            var transientData = existingItem.GetPolicy <TransientImportSellableItemDataPolicy>();

            transientData.ParentAssociationsToCreateList = transientData.ParentAssociationsToCreateList.Where(a => associationsToCreate.Contains(a.ParentSitecoreId)).ToList();
        }
 private void CopyListPrice(SellableItem itemNewData, SellableItem item)
 {
     item.RemovePolicy(typeof(ListPricingPolicy));
     item.Policies.Add(itemNewData.GetPolicy <ListPricingPolicy>());
 }