public virtual bool IsSatisfiedBy(CartProduct product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            return(product.Product.IsActive.GetValueOrDefault(false) && product.Product.IsBuyable.GetValueOrDefault(false) && product.Price != null);
        }
示例#2
0
        public virtual bool IsSatisfiedBy(CartProduct product, long requestedQuantity)
        {
            var result = AbstractTypeFactory <ProductIsBuyableSpecification> .TryCreateInstance().IsSatisfiedBy(product);

            if (result && product.Product.TrackInventory.GetValueOrDefault(false))
            {
                result = product.Inventory != null;
                if (result)
                {
                    result = product.Inventory.AllowPreorder ||
                             product.Inventory.AllowBackorder ||
                             product.AvailableQuantity >= requestedQuantity;
                }
            }

            return(result);
        }
        protected virtual async Task <CartAggregate> InnerAddLineItemAsync(LineItem lineItem, CartProduct product = null)
        {
            var existingLineItem = Cart.Items.FirstOrDefault(li => li.ProductId == lineItem.ProductId);

            if (existingLineItem != null)
            {
                await InnerChangeItemQuantityAsync(existingLineItem, existingLineItem.Quantity + Math.Max(1, lineItem.Quantity), product);
            }
            else
            {
                lineItem.Id = null;
                Cart.Items.Add(lineItem);
            }

            return(this);
        }
        protected virtual Task <CartAggregate> InnerChangeItemQuantityAsync(LineItem lineItem, int quantity, CartProduct product = null)
        {
            if (lineItem == null)
            {
                throw new ArgumentNullException(nameof(lineItem));
            }

            if (!lineItem.IsReadOnly && product != null)
            {
                var salePrice = product.Price.GetTierPrice(quantity).Price;
                if (salePrice != 0)
                {
                    lineItem.SalePrice = salePrice.Amount;
                }
                //List price should be always greater ot equals sale price because it may cause incorrect totals calculation
                if (lineItem.ListPrice < lineItem.SalePrice)
                {
                    lineItem.ListPrice = lineItem.SalePrice;
                }
            }
            if (quantity > 0)
            {
                lineItem.Quantity = quantity;
            }
            else
            {
                Cart.Items.Remove(lineItem);
            }
            return(Task.FromResult(this));
        }
示例#5
0
        protected virtual async Task <CartAggregate> InnerAddLineItemAsync(LineItem lineItem, CartProduct product = null, IList <DynamicPropertyValue> dynamicProperties = null)
        {
            var existingLineItem = LineItems.FirstOrDefault(li => li.ProductId == lineItem.ProductId);

            if (existingLineItem != null)
            {
                await InnerChangeItemQuantityAsync(existingLineItem, existingLineItem.Quantity + Math.Max(1, lineItem.Quantity), product);

                existingLineItem.FulfillmentCenterId   = lineItem.FulfillmentCenterId;
                existingLineItem.FulfillmentCenterName = lineItem.FulfillmentCenterName;

                lineItem = existingLineItem;
            }
            else
            {
                lineItem.Id = null;
                Cart.Items.Add(lineItem);
            }

            if (dynamicProperties != null)
            {
                await UpdateCartItemDynamicProperties(lineItem, dynamicProperties);
            }

            return(this);
        }
示例#6
0
 protected virtual async Task <CartAggregate> InnerAddLineItemAsync(LineItem lineItem, CartProduct product = null)
 {
     return(await InnerAddLineItemAsync(lineItem, product, dynamicProperties : null));
 }
示例#7
0
        public virtual Task <CartAggregate> SetItemFulfillmentCenterAsync(LineItem lineItem, CartProduct cartProduct)
        {
            lineItem.FulfillmentCenterId   = cartProduct?.Inventory?.FulfillmentCenterId;
            lineItem.FulfillmentCenterName = cartProduct?.Inventory?.FulfillmentCenterName;

            return(Task.FromResult(this));
        }