示例#1
0
        public override async Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            _commerceContext = context.CommerceContext;

            var cartLine = context.CommerceContext.GetObject <CartLineArgument>();
            CartLineComponent addedLine = arg.Lines.FirstOrDefault(line => line.Id.EqualsOrdinalIgnoreCase(cartLine.Line.Id));

            if (addedLine == null)
            {
                return(arg);
            }

            SellableItem sellableItem = await getSellableItemCommand.Process(_commerceContext, addedLine.ItemId, false);

            var categoryComponent = addedLine.GetComponent <CategoryComponent>();

            if (sellableItem.ParentCategoryList != null && !categoryComponent.ParentCategoryList.Any())
            {
                foreach (string categoryId in sellableItem.ParentCategoryList.Split('|'))
                {
                    categoryComponent.ParentCategoryList.Add(await GetCategoryIdPath(categoryId, ""));
                }
            }

            return(arg);
        }
        public virtual void Process(CommerceContext commerceContext, CartLineComponent cartLineComponent, bool autoRemove)
        {
            if (!autoRemove && cartLineComponent.UnitListPrice.Amount != 0.0m)
            {
                return;
            }

            var propertiesModel = commerceContext.GetObject <PropertiesModel>();
            var freeGiftEligibilityComponent = cartLineComponent.GetComponent <FreeGiftAutoRemoveComponent>();

            freeGiftEligibilityComponent.PromotionId = propertiesModel?.GetPropertyValue("PromotionId") as string;
        }
        public override Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull("The cart argument can not be null");

            var cartLine = context.CommerceContext.GetObjects <CartLineArgument>().First();
            CartLineComponent addedLine = arg.Lines.FirstOrDefault <CartLineComponent>(line => line.Id.Equals(cartLine.Line.Id, StringComparison.OrdinalIgnoreCase));

            var loyalty = addedLine.GetComponent <LoyaltyComponent>();

            loyalty.PointsEarned = (int)addedLine.Totals.SubTotal.Amount;
            return(Task.FromResult(arg));
        }
示例#4
0
        private int GetPoints(CartLineComponent line)
        {
            if (!line.HasComponent <LoyaltyPointsComponent>())
            {
                return(0);
            }

            var loyaltyPoints = line.GetComponent <LoyaltyPointsComponent>();

            if (loyaltyPoints.HasComponent <Applied>())
            {
                return(0);
            }

            loyaltyPoints.SetComponent(new Applied());

            return((int)Math.Floor(line.Quantity * loyaltyPoints.Points));
        }
示例#5
0
        /// <summary>
        /// To add the new shared cart data to the line item
        /// </summary>
        /// <param name="entityView"></param>
        /// <param name="line"></param>
        /// <param name="context"></param>
        private void PopulateLineChildView(EntityView entityView, CartLineComponent line, CommercePipelineExecutionContext context)
        {
            var lineEntityView = entityView.ChildViews.OfType <EntityView>().FirstOrDefault(p => p.ItemId == line.Id);

            if (line.HasComponent <SharedCartLineComponent>())
            {
                var sharedCartLineComponent = line.GetComponent <SharedCartLineComponent>();
                //Add shop name property to the line item view
                lineEntityView.Properties.Add(new ViewProperty {
                    Name = "ShopName", DisplayName = "Store", IsReadOnly = true, RawValue = sharedCartLineComponent.ShopName
                });
            }
            else
            {
                //Add blank value if component doesn't exist, because Headers
                lineEntityView.Properties.Add(new ViewProperty {
                    Name = "ShopName", DisplayName = "Store", IsReadOnly = true, RawValue = string.Empty
                });
            }
        }
        /// <summary>
        /// The process of the command
        /// </summary>
        /// <param name="commerceContext">
        /// The commerce context
        /// </param>
        /// <param name="cartLineComponent"></param>
        /// <param name="awardingAction"></param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public virtual void Process(CommerceContext commerceContext, [NotNull] CartLineComponent cartLineComponent, [NotNull] string awardingAction)
        {
            using (CommandActivity.Start(commerceContext, this))
            {
                var discountAdjustmentType = commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount;
                var propertiesModel        = commerceContext.GetObject <PropertiesModel>();
                var totals         = commerceContext?.GetObject <CartTotals>();
                var discountAmount = cartLineComponent.UnitListPrice.Amount * decimal.MinusOne;

                cartLineComponent.Adjustments.Add(new CartLineLevelAwardedAdjustment
                {
                    Name           = (propertiesModel?.GetPropertyValue("PromotionText") as string ?? discountAdjustmentType),
                    DisplayName    = (propertiesModel?.GetPropertyValue("PromotionCartText") as string ?? discountAdjustmentType),
                    Adjustment     = new Money(commerceContext.CurrentCurrency(), discountAmount),
                    AdjustmentType = discountAdjustmentType,
                    IsTaxable      = false,
                    AwardingBlock  = propertiesModel?.GetPropertyValue("PromotionId") as string
                });

                totals.Lines[cartLineComponent.Id].SubTotal.Amount = totals.Lines[cartLineComponent.Id].SubTotal.Amount + discountAmount;
                cartLineComponent.GetComponent <MessagesComponent>().AddMessage(commerceContext.GetPolicy <KnownMessageCodePolicy>().Promotions, string.Format("PromotionApplied: {0}", propertiesModel?.GetPropertyValue("PromotionId") ?? awardingAction));
            }
        }
示例#7
0
        public CartLineComponent Build()
        {
            var line = new CartLineComponent
            {
                Id            = lineId,
                Quantity      = quantity,
                ItemId        = itemId,
                UnitListPrice = new Money(price),
                Policies      =
                {
                    new PurchaseOptionMoneyPolicy
                    {
                        SellPrice = new Money(price)
                    }
                },
                Totals = new Totals
                {
                    GrandTotal = new Money(quantity * price)
                }
            };

            if (fullfilmentMethod != null)
            {
                line.SetComponent(new FulfillmentComponent
                {
                    FulfillmentMethod = fullfilmentMethod
                });
            }

            if (categorySitecoreId != null)
            {
                var categoryComponent = line.GetComponent <CategoryComponent>();
                categoryComponent.ParentCategoryList.Add(categorySitecoreId);
            }

            return(line);
        }
示例#8
0
 private static Func <CartLineComponent, bool> ProductExistsInOrderAndCart(CartLineComponent cartLine)
 {
     return(orderLine => cartLine.GetComponent <CartProductComponent>().Id == orderLine.GetComponent <CartProductComponent>().Id);
 }
示例#9
0
 private static bool HasCategory(bool includeSubCategories, CartLineComponent line, string categorySitecoreId)
 {
     return(line.HasComponent <CategoryComponent>() &&
            line.GetComponent <CategoryComponent>().IsMatch(categorySitecoreId, includeSubCategories));
 }
示例#10
0
        private void PopulateLineChildView(EntityView lineEntityView, CartLineComponent line, CommercePipelineExecutionContext context)
        {
            if (line == null || lineEntityView == null || context == null)
            {
                return;
            }

            LineQuantityPolicy policy = context.GetPolicy <LineQuantityPolicy>();

            ViewProperty itemIdProperty = new ViewProperty();

            itemIdProperty.Name       = "ItemId";
            itemIdProperty.IsHidden   = true;
            itemIdProperty.IsReadOnly = true;
            itemIdProperty.RawValue   = (object)line.Id;
            lineEntityView.Properties.Add(itemIdProperty);

            ViewProperty listPriceProperty = new ViewProperty();

            listPriceProperty.Name       = "ListPrice";
            listPriceProperty.IsReadOnly = true;
            listPriceProperty.RawValue   = (object)line.UnitListPrice;
            lineEntityView.Properties.Add(listPriceProperty);

            ViewProperty sellPriceProperty = new ViewProperty();

            sellPriceProperty.Name       = "SellPrice";
            sellPriceProperty.IsReadOnly = true;
            sellPriceProperty.RawValue   = (object)line.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice;
            lineEntityView.Properties.Add(sellPriceProperty);

            ViewProperty quantityProperty = new ViewProperty();

            quantityProperty.Name         = "Quantity";
            quantityProperty.IsReadOnly   = true;
            quantityProperty.RawValue     = (object)(policy.AllowDecimal ? line.Quantity : (Decimal)(int)line.Quantity);
            quantityProperty.OriginalType = policy.AllowDecimal ? typeof(Decimal).FullName : typeof(int).FullName;
            lineEntityView.Properties.Add(quantityProperty);

            ViewProperty subtotalProperty = new ViewProperty();

            subtotalProperty.Name       = "Subtotal";
            subtotalProperty.IsReadOnly = true;
            subtotalProperty.RawValue   = (object)line.Totals.SubTotal;
            lineEntityView.Properties.Add(subtotalProperty);

            ViewProperty adjustmentsProperty = new ViewProperty();

            adjustmentsProperty.Name       = "Adjustments";
            adjustmentsProperty.IsReadOnly = true;
            adjustmentsProperty.RawValue   = (object)line.Totals.AdjustmentsTotal;
            lineEntityView.Properties.Add(adjustmentsProperty);

            ViewProperty lineTotalProperty = new ViewProperty();

            lineTotalProperty.Name       = "LineTotal";
            lineTotalProperty.IsReadOnly = true;
            lineTotalProperty.RawValue   = (object)line.Totals.GrandTotal;
            lineEntityView.Properties.Add(lineTotalProperty);

            CartProductComponent component = line.GetComponent <CartProductComponent>();
            ViewProperty         sellableItemNameProperty = new ViewProperty();

            sellableItemNameProperty.Name       = "Name";
            sellableItemNameProperty.IsReadOnly = true;
            sellableItemNameProperty.RawValue   = (object)component.DisplayName;
            lineEntityView.Properties.Add(sellableItemNameProperty);

            ViewProperty sizeProperty = new ViewProperty();

            sizeProperty.Name       = "Size";
            sizeProperty.IsReadOnly = true;
            sizeProperty.RawValue   = (object)component.Size;
            lineEntityView.Properties.Add(sizeProperty);

            ViewProperty colourProperty = new ViewProperty();

            colourProperty.Name       = "Color";
            colourProperty.IsReadOnly = true;
            colourProperty.RawValue   = (object)component.Color;
            lineEntityView.Properties.Add(colourProperty);

            ViewProperty styleProperty = new ViewProperty();

            styleProperty.Name       = "Style";
            styleProperty.IsReadOnly = true;
            styleProperty.RawValue   = (object)component.Style;
            lineEntityView.Properties.Add(styleProperty);

            ViewProperty variationProperty = new ViewProperty();

            variationProperty.Name       = "Variation";
            variationProperty.IsReadOnly = true;
            variationProperty.RawValue   = line.HasComponent <ItemVariationSelectedComponent>() ? (object)line.GetComponent <ItemVariationSelectedComponent>().VariationId : (object)string.Empty;
            lineEntityView.Properties.Add(variationProperty);
        }