/// <summary>
        /// Return the total price for a line item without the VAT included
        /// </summary>
        /// <remarks>
        /// Use this to get the total price for 1 or more products without VAT if
        /// your prices include VAT by default.
        /// </remarks>
        /// <param name="lineItem"></param>
        /// <param name="vatPercent"></param>
        /// <returns></returns>
        private decimal GetTotalPriceWithoutVat(LineItem lineItem, int vatPercent)
        {
            decimal vatFactor = 1 + (vatPercent / 100m);
            // IMPORTANT: The extended price is for all items (quantities)
            // Hence we MUST NOT multiply by quantity. DIBS expect us to
            // give the price per item, so we need to divide by quantity)
            decimal linePriceWithoutVat = (lineItem.ExtendedPrice / vatFactor) / lineItem.Quantity;

            // Round, DIBS limits us to 2 decimal values
            return(Math.Round(linePriceWithoutVat, 2));
        }
        /// <summary>
        /// Calculates VAT according to http://tech.dibspayment.com/DPW_hosted_input_parameters_order_information
        /// </summary>
        /// <remarks>
        /// Important! This assumes the ExtendedPrice is without VAT.
        /// </remarks>
        /// <param name="lineItem"></param>
        /// <param name="vatPercent"></param>
        /// <returns></returns>
        private int CalculateVatAmount(LineItem lineItem, int vatPercent)
        {
            // Count: 2	Price: 11.25 VAT%:50.25
            // Product2 = Round (1125 * 2 * (1 + 5025/10000)) = Round (3380.625) = 3381

            throw new NotImplementedException("This method has not been verified. Please test before use.");
            //int priceNormalized = (int)lineItem.ExtendedPrice*100;
            //int vatPercentNormalized = vatPercent*100;
            //// IMPORTANT: The extended price is for all items (quantities)
            //// Hence we MUST NOT multiply by quantity
            //int total = (int)Math.Round((decimal)priceNormalized * (1 + vatPercentNormalized / 10000));
            //return total;
        }
Ejemplo n.º 3
0
 private LineItemModel MapToModel(Mediachase.Commerce.Orders.LineItem item)
 {
     return(new LineItemModel()
     {
         ArticleNumber = item.GetStringValue(Constants.Metadata.LineItem.ArticleNumber),
         CatalogEntryId = item.Code,
         Color = item.GetStringValue(Constants.Metadata.LineItem.Color),
         Description = item.GetStringValue(Constants.Metadata.LineItem.Description),
         Discounts = MapDiscounts(item.Discounts),
         DisplayName = item.DisplayName,
         ExtendedPrice = item.ExtendedPrice,
         LineItemDiscountAmount = item.LineItemDiscountAmount,
         OrderLevelDiscountAmount = item.OrderLevelDiscountAmount,
         Quantity = (int)item.Quantity,
         Size = item.GetStringValue(Constants.Metadata.LineItem.Size),
         WarehouseCode = item.WarehouseCode
     });
 }
Ejemplo n.º 4
0
 public LineItem(Mediachase.Commerce.Orders.LineItem lineItem, string language)
 {
     Code                       = lineItem.Code;
     Name                       = lineItem.GetStringValue(Constants.Metadata.LineItem.DisplayName);
     ArticleNumber              = lineItem.GetStringValue(Constants.Metadata.LineItem.ArticleNumber);
     ImageUrl                   = lineItem.GetString(Constants.Metadata.LineItem.ImageUrl);
     Color                      = lineItem.GetStringValue(Constants.Metadata.LineItem.Color);
     ColorImageUrl              = lineItem.GetStringValue(Constants.Metadata.LineItem.ColorImageUrl);
     Description                = lineItem.GetStringValue(Constants.Metadata.LineItem.Description);
     Size                       = lineItem.GetStringValue(Constants.Metadata.LineItem.Size);
     PlacedPrice                = lineItem.PlacedPrice;
     LineItemTotal              = lineItem.Quantity * lineItem.PlacedPrice;
     LineItemDiscount           = lineItem.LineItemDiscountAmount;
     LineItemOrderLevelDiscount = lineItem.OrderLevelDiscountAmount;
     Quantity                   = Convert.ToInt32(lineItem.Quantity);
     Url                  = lineItem.GetEntryLink(language);
     Discounts            = lineItem.Discounts.Cast <Discount>().Select(x => new DiscountItem(x)).ToList();
     IsInventoryAllocated = lineItem.IsInventoryAllocated;
 }
        /// <summary>
        /// Updates the data for a line item object based on data we might know, but that has not been
        /// set previously. The line item could have been added from Commerce Manager or some other API
        /// </summary>
        /// <param name="lineItemDto">The line item dto.</param>
        /// <param name="lineItem">The line item.</param>
        public static void UpdateData(this OxxCommerceStarterKit.Core.Objects.LineItem lineItemDto, Mediachase.Commerce.Orders.LineItem lineItem)
        {
            if (string.IsNullOrEmpty(lineItemDto.ArticleNumber))
            {
                lineItemDto.ArticleNumber = lineItem.Code;
            }

            if (string.IsNullOrEmpty(lineItemDto.ImageUrl))
            {
                // Attempt to get it again - the variation could have been added
                // manually from Commerce Mangager
                var entryContent = GetEntryContent <EntryContentBase>(lineItem);
                if (entryContent != null)
                {
                    lineItemDto.ImageUrl = entryContent.GetImage();
                }
            }
        }