Exemple #1
0
        /// <summary>
        /// The as product line item.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        /// <returns>
        /// The <see cref="ProductLineItem"/>.
        /// </returns>
        public static ProductLineItem AsProductLineItem(this ILineItem item, MerchelloHelper merchello)
        {
            if (!item.ExtendedData.ContainsProductKey())
            {
                return(null);
            }
            var product = merchello.TypedProductContent(item.ExtendedData.GetProductKey());

            if (product == null)
            {
                return(null);
            }

            var images = product.GetPropertyValue <IEnumerable <IPublishedContent> >("images").ToArray();

            return(new ProductLineItem()
            {
                Key = item.Key,
                FormattedUnitPrice = StoreHelper.FormatCurrency(item.Price),
                FormattedPrice = StoreHelper.FormatCurrency(item.TotalPrice),
                Image = images.Any() ? images.First().GetCropUrl(50, 50) : string.Empty,
                Name = item.Name,
                Quantity = item.Quantity
            });
        }
Exemple #2
0
        /// <summary>
        /// Maps an <see cref="IInvoice"/> to <see cref="CustomerOrder"/>.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <returns>
        /// The <see cref="CustomerOrder"/>.
        /// </returns>
        public static CustomerOrder AsCustomerOrder(this IInvoice invoice)
        {
            var shippingLineItem = invoice.ShippingLineItems().FirstOrDefault();

            var shippingAdr = shippingLineItem != null
                                  ? shippingLineItem.ExtendedData.GetShipment <InvoiceLineItem>()
                              .GetDestinationAddress()
                              .AsAddressModel()
                                  : new AddressModel();

            var billingAdr = invoice.GetBillingAddress().AsAddressModel();

            var merchello = new MerchelloHelper();

            return(new CustomerOrder
            {
                BillingAddress = billingAdr,
                ShippingAddress = shippingAdr,
                FormattedDiscountTotal = StoreHelper.FormatCurrency(0),
                FormattedShippingTotal = StoreHelper.FormatCurrency(invoice.TotalShipping()),
                FormattedSubTotal = StoreHelper.FormatCurrency(invoice.TotalItemPrice()),
                FormattedTotal = StoreHelper.FormatCurrency(invoice.Total),
                InvoiceDate = invoice.InvoiceDate,
                InvoiceNumber = invoice.PrefixedInvoiceNumber(),
                InvoiceStatus = invoice.InvoiceStatus.Name,
                OrderStatus = invoice.Orders.Any() ? invoice.Orders.First().OrderStatus.Name : "Being prepared",
                Key = invoice.Key,
                Products = invoice.ProductLineItems().Select(x => x.AsBasketItem(merchello))
            });
        }
Exemple #3
0
 /// <summary>
 /// Maps <see cref="IShipmentRateQuote"/> to <see cref="DeliveryQuote"/>.
 /// </summary>
 /// <param name="quote">
 /// The quote.
 /// </param>
 /// <returns>
 /// The <see cref="DeliveryQuote"/>.
 /// </returns>
 public static DeliveryQuote AsDeliveryQuote(this IShipmentRateQuote quote)
 {
     return(new DeliveryQuote
     {
         Key = quote.ShipMethod.Key,
         Rate = StoreHelper.FormatCurrency(quote.Rate),
         Description = quote.ShipMethod.Name == "Ground" ? "Standard delivery" : "Get it quick",
         MethodName = quote.ShipMethod.Name
     });
 }
Exemple #4
0
 /// <summary>
 /// Maps <see cref="IProductContent"/> to <see cref="ProductListItem"/>.
 /// </summary>
 /// <param name="product">
 /// The product.
 /// </param>
 /// <returns>
 /// The <see cref="ProductListItem"/>.
 /// </returns>
 public static ProductListItem AsProductListItem(this IProductContent product)
 {
     return(new ProductListItem
     {
         Key = product.Key,
         Name = product.Name,
         Url = product.Url,
         FormattedPrice = StoreHelper.FormatCurrency(product.Price),
         FormattedSalePrice = StoreHelper.FormatCurrency(product.SalePrice),
         OnSale = product.OnSale,
         IsNew = product.WillWork("isNew") && product.GetPropertyValue <bool>("isNew"),
         ImageUrl =
             product.WillWork("images")
                            ? product.GetPropertyValue <IEnumerable <IPublishedContent> >("images")
             .First()
             .GetCropUrl(255, 255)
                            : string.Empty,
         Price = product.OnSale ? product.SalePrice : product.Price
     });
 }