/// <summary>
        /// Creates a line item of a particular type for a shipment rate quote
        /// </summary>
        /// <typeparam name="T">The type of the line item to create</typeparam>
        /// <param name="shipmentRateQuote">The <see cref="ShipmentRateQuote"/> to be translated to a line item</param>
        /// <returns>A <see cref="LineItemBase"/> of type T</returns>
        public static T AsLineItemOf <T>(this IShipmentRateQuote shipmentRateQuote) where T : LineItemBase
        {
            var extendedData = new ExtendedDataCollection();

            extendedData.AddShipment(shipmentRateQuote.Shipment);

            var ctrValues = new object[]
            {
                EnumTypeFieldConverter.LineItemType.Shipping.TypeKey,
                shipmentRateQuote.ShipmentLineItemName(),
                shipmentRateQuote.ShipMethod.ServiceCode,     // TODO this may not be unique (SKU) once multiple shipments are exposed
                1,
                shipmentRateQuote.Rate,
                extendedData
            };

            var attempt = ActivatorHelper.CreateInstance <LineItemBase>(typeof(T), ctrValues);

            if (attempt.Success)
            {
                return(attempt.Result as T);
            }

            MultiLogHelper.Error <ILineItem>("Failed instiating a line item from shipmentRateQuote", attempt.Exception);

            throw attempt.Exception;
        }
        /// <summary>
        /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
        /// </summary>
        /// <param name="approvedShipmentRateQuote">
        /// The <see cref="IShipmentRateQuote"/> to be saved
        /// </param>
        public virtual void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote)
        {
            AddShipmentRateQuoteLineItem(approvedShipmentRateQuote);
            _merchelloContext.Services.ItemCacheService.Save(_itemCache);

            _customer.ExtendedData.AddAddress(approvedShipmentRateQuote.Shipment.GetDestinationAddress(), AddressType.Shipping);
            SaveCustomer(_merchelloContext, _customer, RaiseCustomerEvents);
        }
        /// <summary>
        /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
        /// </summary>
        /// <param name="approvedShipmentRateQuote">
        /// The <see cref="IShipmentRateQuote"/> to be saved
        /// </param>
        public override void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote)
        {
            this.AddShipmentRateQuoteLineItem(approvedShipmentRateQuote);
            this.Context.Services.ItemCacheService.Save(this.Context.ItemCache);

            this.Context.Customer.ExtendedData.AddAddress(approvedShipmentRateQuote.Shipment.GetDestinationAddress(), AddressType.Shipping);
            this.SaveCustomer();
        }
示例#4
0
        /// <summary>
        /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
        /// </summary>
        /// <param name="approvedShipmentRateQuote">
        /// The <see cref="IShipmentRateQuote"/> to be saved
        /// </param>
        public override void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote)
        {
            this.AddShipmentRateQuoteLineItem(approvedShipmentRateQuote);
            this.Context.Services.ItemCacheService.Save(this.Context.ItemCache);

            this.Context.Customer.ExtendedData.AddAddress(approvedShipmentRateQuote.Shipment.GetDestinationAddress(), AddressType.Shipping);
            this.SaveCustomer();
        }
        /// <summary>
        /// Maps the <see cref="IShipmentRateQuote"/> to a <see cref="ILineItem"/>
        /// </summary>
        /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> to be added as a <see cref="ILineItem"/></param>
        private void AddShipmentRateQuoteLineItem(IShipmentRateQuote shipmentRateQuote)
        {
            var lineItem = shipmentRateQuote.AsLineItemOf <ItemCacheLineItem>();

            if (_shippingTaxable.Value)
            {
                lineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString());
            }
            _itemCache.AddItem(lineItem);
        }
示例#6
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
     });
 }
示例#7
0
 /// <summary>
 /// Maps the <see cref="IShipmentRateQuote"/> to a <see cref="ILineItem"/> 
 /// </summary>
 /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> to be added as a <see cref="ILineItem"/></param>
 private void AddShipmentRateQuoteLineItem(IShipmentRateQuote shipmentRateQuote)
 {
     _itemCache.AddItem(shipmentRateQuote.AsLineItemOf<ItemCacheLineItem>());
 }
示例#8
0
        /// <summary>
        /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
        /// </summary>
        /// <param name="approvedShipmentRateQuote">
        /// The <see cref="IShipmentRateQuote"/> to be saved
        /// </param>
        public virtual void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote)
        {
            AddShipmentRateQuoteLineItem(approvedShipmentRateQuote);
            _merchelloContext.Services.ItemCacheService.Save(_itemCache);

            _customer.ExtendedData.AddAddress(approvedShipmentRateQuote.Shipment.GetDestinationAddress(), AddressType.Shipping);
            SaveCustomer(_merchelloContext, _customer);
        }
 private void WriteShipRateQuote(IShipmentRateQuote srq)
 {
     Console.WriteLine("---------- Shipment Rate Quote ---------------------");
     Console.WriteLine("Name: {0}", srq.ShipmentLineItemName());
     Console.WriteLine("Rate Quote: {0}", srq.Rate);
 }
 /// <summary>
 /// Maps the <see cref="IShipmentRateQuote"/> to a <see cref="ILineItem"/>
 /// </summary>
 /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> to be added as a <see cref="ILineItem"/></param>
 private void AddShipmentRateQuoteLineItem(IShipmentRateQuote shipmentRateQuote)
 {
     _itemCache.AddItem(shipmentRateQuote.AsLineItemOf <ItemCacheLineItem>());
 }
示例#11
0
 /// <summary>
 /// Returns a string intended to be used as a 'Shipment Line Item' title or name
 /// </summary>
 /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> used to quote the line item</param>
 public static string ShimpentLineItemName(this IShipmentRateQuote shipmentRateQuote)
 {
     return(string.Format("Shipment - {0} - {1} items", shipmentRateQuote.ShipMethod.Name, shipmentRateQuote.Shipment.Items.Count));
 }
 /// <summary>
 /// Maps the <see cref="IShipmentRateQuote"/> to a <see cref="ILineItem"/> 
 /// </summary>
 /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> to be added as a <see cref="ILineItem"/></param>
 protected virtual void AddShipmentRateQuoteLineItem(IShipmentRateQuote shipmentRateQuote)
 {
     var lineItem = shipmentRateQuote.AsLineItemOf<ItemCacheLineItem>();
     if (_shippingTaxable.Value) lineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString());
     Context.ItemCache.AddItem(lineItem);
 }
 /// <summary>
 /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
 /// </summary>
 /// <param name="approvedShipmentRateQuote">
 /// The <see cref="IShipmentRateQuote"/> to be saved
 /// </param>
 public abstract void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote);
 private void WriteShipRateQuote(IShipmentRateQuote srq)
 {
     Console.WriteLine("---------- Shipment Rate Quote ---------------------");
     Console.WriteLine("Name: {0}", srq.ShipmentLineItemName());
     Console.WriteLine("Rate Quote: {0}", srq.Rate);
 }
 /// <summary>
 /// Saves a <see cref="IShipmentRateQuote"/> as a shipment line item
 /// </summary>
 /// <param name="approvedShipmentRateQuote">
 /// The <see cref="IShipmentRateQuote"/> to be saved
 /// </param>
 public abstract void SaveShipmentRateQuote(IShipmentRateQuote approvedShipmentRateQuote);
示例#16
0
 /// <summary>
 /// The to shipment rate quote display.
 /// </summary>
 /// <param name="quote">
 /// The quote.
 /// </param>
 /// <returns>
 /// The <see cref="ShipmentRateQuoteDisplay"/>.
 /// </returns>
 public static ShipmentRateQuoteDisplay ToShipmentRateQuoteDisplay(this IShipmentRateQuote quote)
 {
     return(AutoMapper.Mapper.Map <ShipmentRateQuoteDisplay>(quote));
 }