public override bool UpdatePlacedPrice(ILineItem lineItem, CustomerContact customerContact, MarketId marketId,
                                               Currency currency, Action <ILineItem, ValidationIssue> onValidationError)
        {
            var entryContent = lineItem.GetEntryContent(_referenceConverter, _contentLoader);

            if (entryContent == null)
            {
                onValidationError(lineItem, ValidationIssue.RemovedDueToUnavailableItem);
                return(false);
            }

            if (lineItem.Properties[Constant.Quote.PreQuotePrice] != null &&
                !string.IsNullOrEmpty(lineItem.Properties[Constant.Quote.PreQuotePrice].ToString()))
            {
                return(true);
            }

            var placedPrice = GetPlacedPrice(entryContent, lineItem.Quantity, customerContact, marketId, currency);

            if (placedPrice.HasValue)
            {
                if (new Money(currency.Round(lineItem.PlacedPrice), currency) == placedPrice.Value)
                {
                    return(true);
                }
                onValidationError(lineItem, ValidationIssue.PlacedPricedChanged);
                lineItem.PlacedPrice = placedPrice.Value.Amount;
                return(true);
            }

            onValidationError(lineItem, ValidationIssue.RemovedDueToInvalidPrice);
            return(false);
        }
示例#2
0
 private int GetTaxCategoryId(ILineItem lineItem)
 {
     if (!lineItem.TaxCategoryId.HasValue)
     {
         return((lineItem.GetEntryContent(_referenceConverter, _contentRepository) as IPricing)?.TaxCategoryId ?? 0);
     }
     return(lineItem.TaxCategoryId.Value);
 }
示例#3
0
        private static OrderLine GetOrderLine(
            ILineItem lineItem,
            bool includeProductAndImageUrl,
            int unitPrice,
            int totalAmount,
            int totalDiscountAmount,
            int totalTaxAmount,
            int taxRate)
        {
            var orderLine = new OrderLine
            {
                Quantity  = (int)lineItem.Quantity,
                Name      = lineItem.DisplayName,
                Reference = lineItem.Code.Length > 64
                    ? lineItem.Code.Substring(0, (MaxOrderLineReference - 1))
                    : lineItem.Code, // can't use more then 64 characters for the order reference
                Type = OrderLineType.physical
            };

            if (string.IsNullOrEmpty(orderLine.Name))
            {
                var entry = lineItem.GetEntryContent();
                if (entry != null)
                {
                    orderLine.Name = entry.DisplayName;
                }
            }

            orderLine.UnitPrice           = unitPrice;
            orderLine.TotalAmount         = totalAmount;
            orderLine.TotalDiscountAmount = totalDiscountAmount;
            orderLine.TotalTaxAmount      = totalTaxAmount;
            orderLine.TaxRate             = taxRate;

            if (includeProductAndImageUrl)
            {
                var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Code);
                if (!ContentReference.IsNullOrEmpty(contentLink))
                {
                    orderLine.ProductUrl = _urlResolver.Service.GetUrl(contentLink, _languageService.Service.GetPreferredCulture().Name, new VirtualPathArguments {
                        ValidateTemplate = false
                    }).ToAbsoluteUrl();
                    orderLine.ImageUrl = GetVariantImage(contentLink).ToAbsoluteUrl();
                }
            }
            return(orderLine);
        }
示例#4
0
        public static decimal GetWeight(this ILineItem lineItem)
        {
            if (string.IsNullOrEmpty(lineItem.Code))
            {
                return(0);
            }

            var entry = lineItem.GetEntryContent();

            if (entry == null)
            {
                return(0);
            }

            decimal weight  = 0;
            var     package = entry as PackageContent;
            var     bundle  = entry as BundleContent;

            if (package != null)
            {
                weight = package.CalculateRelationsWeight <PackageEntry>();
            }
            else if (bundle != null)
            {
                weight = bundle.CalculateRelationsWeight <BundleEntry>();
            }

            if (weight == 0)
            {
                var stockPlacementEntry = entry as IStockPlacement;

                if (stockPlacementEntry != null)
                {
                    weight = (decimal)stockPlacementEntry.Weight;
                }
            }

            return(weight);
        }
示例#5
0
        private static OrderLine GetOrderLine(ILineItem lineItem, bool includeProductAndImageUrl, int unitPrice, int totalAmount, int totalDiscountAmount, int totalTaxAmount, int taxRate)
        {
            var orderLine = new PatchedOrderLine
            {
                Quantity  = (int)lineItem.Quantity,
                Name      = lineItem.DisplayName,
                Reference = lineItem.Code.Length > 64 ? lineItem.Code.Substring(0, (_maxOrderlineReference - 1)) : lineItem.Code, // can't use more then 64 characters for the order reference
                Type      = "physical"
            };

            if (string.IsNullOrEmpty(orderLine.Name))
            {
                var entry = lineItem.GetEntryContent();
                if (entry != null)
                {
                    orderLine.Name = entry.DisplayName;
                }
            }

            orderLine.UnitPrice           = unitPrice;
            orderLine.TotalAmount         = totalAmount;
            orderLine.TotalDiscountAmount = totalDiscountAmount;
            orderLine.TotalTaxAmount      = totalTaxAmount;
            orderLine.TaxRate             = taxRate;

            if (includeProductAndImageUrl)
            {
                var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Code);
                if (!ContentReference.IsNullOrEmpty(contentLink))
                {
                    orderLine.ProductUrl      = SiteUrlHelper.GetAbsoluteUrl() + _urlResolver.Service.GetUrl(contentLink);
                    orderLine.ProductImageUrl = SiteUrlHelper.GetAbsoluteUrl() + GetVariantImage(contentLink);
                }
            }
            return(orderLine);
        }
 public static string GetUrl(this ILineItem lineItem)
 {
     return(lineItem.GetEntryContent()?.GetUrl());
 }
示例#7
0
        public static bool IsVirtualVariant(this ILineItem lineItem)
        {
            var entry = lineItem.GetEntryContent <EntryContentBase>() as GenericVariant;

            return(entry != null && entry.VirtualProductMode != null && !string.IsNullOrWhiteSpace(entry.VirtualProductMode) && !entry.VirtualProductMode.Equals("None"));
        }
示例#8
0
 public static string GetUrl(this ILineItem lineItem) => lineItem.GetEntryContent()?.GetUrl();