Exemplo n.º 1
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));
        }
Exemplo n.º 2
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
                });
            }
        }
Exemplo n.º 3
0
 private static bool HasCategory(bool includeSubCategories, CartLineComponent line, string categorySitecoreId)
 {
     return(line.HasComponent <CategoryComponent>() &&
            line.GetComponent <CategoryComponent>().IsMatch(categorySitecoreId, includeSubCategories));
 }
Exemplo n.º 4
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);
        }