/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (ShipFromAddress == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ShipFromAddress"); } if (LabelPrepPreference == null) { throw new ValidationException(ValidationRules.CannotBeNull, "LabelPrepPreference"); } if (InboundShipmentPlanRequestItems == null) { throw new ValidationException(ValidationRules.CannotBeNull, "InboundShipmentPlanRequestItems"); } if (ShipFromAddress != null) { ShipFromAddress.Validate(); } if (InboundShipmentPlanRequestItems != null) { foreach (var element in InboundShipmentPlanRequestItems) { if (element != null) { element.Validate(); } } } }
/// <summary> /// A collection of the tokens and the replaceable content for email templates. /// </summary> /// <param name="context">An instance of the Hotcakes Request context.</param> /// <returns>List of HtmlTemplateTag</returns> public List <HtmlTemplateTag> GetReplaceableTags(HccRequestContext context) { var result = new List <HtmlTemplateTag>(); var culture = context.MainContentCulture; result.Add(new HtmlTemplateTag("[[LineItem.AdjustedPrice]]", AdjustedPricePerItem.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.BasePrice]]", BasePricePerItem.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.LineTotalBeforeVAT]]", (LineTotal - TaxPortion).ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.Discounts]]", DiscountDetailsAsHtml())); result.Add(new HtmlTemplateTag("[[LineItem.LineTotal]]", LineTotal.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.ProductId]]", ProductId)); result.Add(new HtmlTemplateTag("[[LineItem.VariantId]]", VariantId)); result.Add(new HtmlTemplateTag("[[LineItem.ProductName]]", ProductName)); result.Add(new HtmlTemplateTag("[[LineItem.ProductSku]]", ProductSku)); result.Add(new HtmlTemplateTag("[[LineItem.Sku]]", "Obsolete. Please use [[LineItem.ProductSku]] instead.", true)); result.Add(new HtmlTemplateTag("[[LineItem.ProductDescription]]", ProductShortDescription)); result.Add(new HtmlTemplateTag("[[LineItem.Quantity]]", Quantity.ToString("#"))); result.Add(new HtmlTemplateTag("[[LineItem.QuantityShipped]]", QuantityShipped.ToString("#"))); result.Add(new HtmlTemplateTag("[[LineItem.QuantityReturned]]", QuantityReturned.ToString("#"))); result.Add(new HtmlTemplateTag("[[LineItem.ShippingStatus]]", LocalizationUtils.GetOrderShippingStatus(ShippingStatus, culture))); result.Add(new HtmlTemplateTag("[[LineItem.TaxRate]]", decimal.Parse(TaxRate.ToString("p3").Replace("%", "")).ToString("G29") + " %")); result.Add(new HtmlTemplateTag("[[LineItem.ShippingPortion]]", ShippingPortion.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.TaxPortion]]", TaxPortion.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.ExtraShipCharge]]", ExtraShipCharge.ToString("c"))); result.Add(new HtmlTemplateTag("[[LineItem.ShipFromAddress]]", ShipFromAddress.ToHtmlString())); result.Add(new HtmlTemplateTag("[[LineItem.ShipSeparately]]", ShipSeparately ? "Yes" : "No")); return(result); }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (ShipmentName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ShipmentName"); } if (ShipFromAddress == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ShipFromAddress"); } if (DestinationFulfillmentCenterId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "DestinationFulfillmentCenterId"); } if (ShipmentStatus == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ShipmentStatus"); } if (LabelPrepPreference == null) { throw new ValidationException(ValidationRules.CannotBeNull, "LabelPrepPreference"); } if (ShipFromAddress != null) { ShipFromAddress.Validate(); } }
/// <summary> /// Allows you to convert the current line object to the DTO equivalent for use with the REST API /// </summary> /// <returns>A new instance of LineItemDTO</returns> public LineItemDTO ToDto() { var dto = new LineItemDTO(); dto.Id = Id; dto.StoreId = StoreId; dto.LastUpdatedUtc = LastUpdatedUtc; dto.BasePricePerItem = BasePricePerItem; dto.PromotionIds = PromotionIds; dto.FreeQuantity = FreeQuantity; dto.LineTotal = LineTotal; dto.AdjustedPricePerItem = AdjustedPricePerItem; dto.IsUserSuppliedPrice = IsUserSuppliedPrice; dto.IsBundle = IsBundle; dto.IsGiftCard = IsGiftCard; foreach (var detail in DiscountDetails) { dto.DiscountDetails.Add(detail.ToDto()); } dto.OrderBvin = OrderBvin ?? string.Empty; dto.ProductId = ProductId ?? string.Empty; dto.VariantId = VariantId ?? string.Empty; dto.ProductName = ProductName ?? string.Empty; dto.ProductSku = ProductSku ?? string.Empty; dto.ProductShortDescription = ProductShortDescription ?? string.Empty; dto.Quantity = Quantity; dto.QuantityReturned = QuantityReturned; dto.QuantityShipped = QuantityShipped; dto.ShippingPortion = ShippingPortion; dto.StatusCode = StatusCode ?? string.Empty; dto.StatusName = StatusName ?? string.Empty; dto.TaxRate = TaxRate; dto.TaxPortion = TaxPortion; foreach (var op in SelectionData.OptionSelectionList) { dto.SelectionData.Add(op.ToDto()); } dto.IsNonShipping = IsNonShipping; dto.TaxSchedule = TaxSchedule; dto.ProductShippingHeight = ProductShippingHeight; dto.ProductShippingLength = ProductShippingLength; dto.ProductShippingWeight = ProductShippingWeight; dto.ProductShippingWidth = ProductShippingWidth; foreach (var cp in CustomProperties) { dto.CustomProperties.Add(cp.ToDto()); } dto.ShipFromAddress = ShipFromAddress.ToDto(); dto.ShipFromMode = (ShippingModeDTO)(int)ShipFromMode; dto.ShipFromNotificationId = ShipFromNotificationId ?? string.Empty; dto.ShipSeparately = ShipSeparately; dto.ExtraShipCharge = ExtraShipCharge; dto.ShippingCharge = (ShippingChargeTypeDTO)(int)ShippingCharge; return(dto); }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (ShipFromAddress == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ShipFromAddress"); } if (ShipFromAddress != null) { ShipFromAddress.Validate(); } if (EstimatedBoxContentsFee != null) { EstimatedBoxContentsFee.Validate(); } }
/// <summary> /// Allows you to populate the current line item object using a LineItemDTO instance /// </summary> /// <param name="dto">An instance of the line item from the REST API</param> public void FromDto(LineItemDTO dto) { if (dto == null) { return; } Id = dto.Id; StoreId = dto.StoreId; LastUpdatedUtc = dto.LastUpdatedUtc; BasePricePerItem = dto.BasePricePerItem; LineTotal = dto.LineTotal; AdjustedPricePerItem = dto.AdjustedPricePerItem; IsUserSuppliedPrice = dto.IsUserSuppliedPrice; IsBundle = dto.IsBundle; IsGiftCard = dto.IsGiftCard; PromotionIds = dto.PromotionIds; FreeQuantity = dto.FreeQuantity; DiscountDetails.Clear(); if (dto.DiscountDetails != null) { foreach (var detail in dto.DiscountDetails) { var d = new DiscountDetail(); d.FromDto(detail); DiscountDetails.Add(d); } } OrderBvin = dto.OrderBvin ?? string.Empty; ProductId = dto.ProductId ?? string.Empty; VariantId = dto.VariantId ?? string.Empty; ProductName = dto.ProductName ?? string.Empty; ProductSku = dto.ProductSku ?? string.Empty; ProductShortDescription = dto.ProductShortDescription ?? string.Empty; Quantity = dto.Quantity; QuantityReturned = dto.QuantityReturned; QuantityShipped = dto.QuantityShipped; ShippingPortion = dto.ShippingPortion; TaxRate = dto.TaxRate; TaxPortion = dto.TaxPortion; StatusCode = dto.StatusCode ?? string.Empty; StatusName = dto.StatusName ?? string.Empty; SelectionData.Clear(); if (dto.SelectionData != null) { foreach (var op in dto.SelectionData) { var o = new OptionSelection(); o.FromDto(op); SelectionData.OptionSelectionList.Add(o); } } IsNonShipping = dto.IsNonShipping; TaxSchedule = dto.TaxSchedule; ProductShippingHeight = dto.ProductShippingHeight; ProductShippingLength = dto.ProductShippingLength; ProductShippingWeight = dto.ProductShippingWeight; ProductShippingWidth = dto.ProductShippingWidth; CustomProperties.Clear(); if (dto.CustomProperties != null) { foreach (var cpd in dto.CustomProperties) { var prop = new CustomProperty(); prop.FromDto(cpd); CustomProperties.Add(prop); } } ShipFromAddress.FromDto(dto.ShipFromAddress); ShipFromMode = (ShippingMode)(int)dto.ShipFromMode; ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty; ShipSeparately = dto.ShipSeparately; ExtraShipCharge = dto.ExtraShipCharge; ShippingCharge = (ShippingChargeType)(int)dto.ShippingCharge; }