protected virtual async Task <PdfPTable> PreparePackagingSlipsProducts(Order order, Shipment shipment, Language language) { var font = PdfExtensions.GetFont(_pdfSettings.FontFileName); var productsTable = new PdfPTable(3); productsTable.WidthPercentage = 100f; if (language.Rtl) { productsTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; productsTable.SetWidths(new[] { 20, 20, 60 }); } else { productsTable.SetWidths(new[] { 60, 20, 20 }); } //product name var cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.ProductName", language.Id), font)); cell.BackgroundColor = BaseColor.LightGray; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //SKU cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.SKU", language.Id), font)); cell.BackgroundColor = BaseColor.LightGray; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //qty cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.QTY", language.Id), font)); cell.BackgroundColor = BaseColor.LightGray; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); foreach (var si in shipment.ShipmentItems) { var productAttribTable = new PdfPTable(1); if (language.Rtl) { productAttribTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } productAttribTable.DefaultCell.Border = Rectangle.NO_BORDER; //product name var orderItem = order.OrderItems.Where(x => x.Id == si.OrderItemId).FirstOrDefault(); if (orderItem == null) { continue; } var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId); string name = product.GetLocalized(x => x.Name, language.Id); productAttribTable.AddCell(new Paragraph(name, font)); //attributes if (!string.IsNullOrEmpty(orderItem.AttributeDescription)) { var attributesFont = PdfExtensions.GetFont(_pdfSettings.FontFileName); attributesFont.SetStyle(Font.ITALIC); var attributesParagraph = new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderItem.AttributeDescription, true, true), attributesFont); productAttribTable.AddCell(attributesParagraph); } productsTable.AddCell(productAttribTable); //SKU var sku = product.FormatSku(orderItem.AttributesXml, _productAttributeParser); cell = new PdfPCell(new Phrase(sku ?? String.Empty, font)); cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //qty cell = new PdfPCell(new Phrase(si.Quantity.ToString(), font)); cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); } return(productsTable); }
protected virtual async Task <PdfPTable> PreparePackagingSlipsAddress(Order order, Shipment shipment, Language language) { var font = PdfExtensions.GetFont(_pdfSettings.FontFileName); var titleFont = PdfExtensions.PrepareTitleFont(_pdfSettings.FontFileName); var addressTable = new PdfPTable(1); if (language.Rtl) { addressTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } addressTable.DefaultCell.Border = Rectangle.NO_BORDER; addressTable.WidthPercentage = 100f; addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Shipment", language.Id), shipment.ShipmentNumber), titleFont)); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Order", language.Id), order.OrderNumber), titleFont)); if (!order.PickUpInStore) { if (order.ShippingAddress == null) { throw new GrandException(string.Format("Shipping is required, but address is not available. Order ID = {0}", order.Id)); } if (_addressSettings.CompanyEnabled && !String.IsNullOrEmpty(order.ShippingAddress.Company)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Company", language.Id), order.ShippingAddress.Company), font)); } addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Name", language.Id), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName), font)); if (_addressSettings.PhoneEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Phone", language.Id), order.ShippingAddress.PhoneNumber), font)); } if (_addressSettings.StreetAddressEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address", language.Id), order.ShippingAddress.Address1), font)); } if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.ShippingAddress.Address2)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address2", language.Id), order.ShippingAddress.Address2), font)); } if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled) { addressTable.AddCell(new Paragraph(String.Format("{0}, {1} {2}", order.ShippingAddress.City, !String.IsNullOrEmpty(order.ShippingAddress.StateProvinceId) ? (await _serviceProvider.GetRequiredService <IStateProvinceService>().GetStateProvinceById(order.ShippingAddress.StateProvinceId)).GetLocalized(x => x.Name, language.Id) : "", order.ShippingAddress.ZipPostalCode), font)); } if (_addressSettings.CountryEnabled && !String.IsNullOrEmpty(order.ShippingAddress.CountryId)) { addressTable.AddCell(new Paragraph(String.Format("{0}", !String.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _serviceProvider.GetRequiredService <ICountryService>().GetCountryById(order.ShippingAddress.CountryId)).GetLocalized(x => x.Name, language.Id) : ""), font)); } //custom attributes var customShippingAddressAttributes = await _addressAttributeFormatter.FormatAttributes(order.ShippingAddress.CustomAttributes); if (!String.IsNullOrEmpty(customShippingAddressAttributes)) { addressTable.AddCell(new Paragraph(HtmlHelper.ConvertHtmlToPlainText(customShippingAddressAttributes, true, true), font)); } } else if (order.PickupPoint != null) { if (order.PickupPoint.Address != null) { addressTable.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.Pickup", language.Id), titleFont)); if (!string.IsNullOrEmpty(order.PickupPoint.Address.Address1)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", string.Format(_localizationService.GetResource("PDFInvoice.Address", language.Id), order.PickupPoint.Address.Address1)), font)); } if (!string.IsNullOrEmpty(order.PickupPoint.Address.City)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", order.PickupPoint.Address.City), font)); } if (!string.IsNullOrEmpty(order.PickupPoint.Address.CountryId)) { var country = await _serviceProvider.GetRequiredService <ICountryService>().GetCountryById(order.PickupPoint.Address.CountryId); if (country != null) { addressTable.AddCell(new Paragraph(string.Format(" {0}", country.Name), font)); } } if (!string.IsNullOrEmpty(order.PickupPoint.Address.ZipPostalCode)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", order.PickupPoint.Address.ZipPostalCode), font)); } addressTable.AddCell(new Paragraph(" ")); } } addressTable.AddCell(new Paragraph(" ")); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.ShippingMethod", language.Id), order.ShippingMethod), font)); addressTable.AddCell(new Paragraph(" ")); return(addressTable); }
protected virtual async Task <PdfPTable> PrepareProducts(Product product, Language language, int productNumber) { var productName = product.GetLocalized(x => x.Name, language.Id); var productDescription = product.GetLocalized(x => x.FullDescription, language.Id); var font = PdfExtensions.GetFont(_pdfSettings.FontFileName); var titleFont = PdfExtensions.PrepareTitleFont(_pdfSettings.FontFileName); var productTable = new PdfPTable(1); productTable.WidthPercentage = 100f; productTable.DefaultCell.Border = Rectangle.NO_BORDER; if (language.Rtl) { productTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } productTable.AddCell(new Paragraph(String.Format("{0}. {1}", productNumber, productName), titleFont)); productTable.AddCell(new Paragraph(" ")); productTable.AddCell(new Paragraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(productDescription, decode: true)), font)); productTable.AddCell(new Paragraph(" ")); if (product.ProductType != ProductType.GroupedProduct) { //simple product //render its properties such as price, weight, etc var priceStr = string.Format("{0} {1}", product.Price.ToString("0.00"), (await _currencyService.GetPrimaryStoreCurrency()).CurrencyCode); if (product.ProductType == ProductType.Reservation) { priceStr = _priceFormatter.FormatReservationProductPeriod(product, priceStr); } productTable.AddCell(new Paragraph(String.Format("{0}: {1}", _localizationService.GetResource("PDFProductCatalog.Price", language.Id), priceStr), font)); productTable.AddCell(new Paragraph(String.Format("{0}: {1}", _localizationService.GetResource("PDFProductCatalog.SKU", language.Id), product.Sku), font)); if (product.IsShipEnabled && product.Weight > Decimal.Zero) { productTable.AddCell(new Paragraph(String.Format("{0}: {1} {2}", _localizationService.GetResource("PDFProductCatalog.Weight", language.Id), product.Weight.ToString("0.00"), (await _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId)).Name), font)); } if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock) { productTable.AddCell(new Paragraph(String.Format("{0}: {1}", _localizationService.GetResource("PDFProductCatalog.StockQuantity", language.Id), product.GetTotalStockQuantity(warehouseId: _storeContext.CurrentStore.DefaultWarehouseId)), font)); } productTable.AddCell(new Paragraph(" ")); } var pictures = product.ProductPictures; if (pictures.Count > 0) { var table = new PdfPTable(2); table.WidthPercentage = 100f; if (language.Rtl) { table.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } foreach (var pic in pictures) { var pp = await _pictureService.GetPictureById(pic.PictureId); if (pp != null) { var picBinary = await _pictureService.LoadPictureBinary(pp); if (picBinary != null && picBinary.Length > 0) { var pictureLocalPath = await _pictureService.GetThumbLocalPath(pp, 200, false); var cell = new PdfPCell(Image.GetInstance(pictureLocalPath)); cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.Border = Rectangle.NO_BORDER; table.AddCell(cell); } } } if (pictures.Count % 2 > 0) { var cell = new PdfPCell(new Phrase(" ")); cell.Border = Rectangle.NO_BORDER; table.AddCell(cell); } productTable.AddCell(table); productTable.AddCell(new Paragraph(" ")); } if (product.ProductType == ProductType.GroupedProduct) { //grouped product. render its associated products int pvNum = 1; var associatedProducts = await _productService.GetAssociatedProducts(product.Id, showHidden : true); foreach (var associatedProduct in associatedProducts) { productTable.AddCell(new Paragraph(String.Format("{0}-{1}. {2}", productNumber, pvNum, associatedProduct.GetLocalized(x => x.Name, language.Id)), font)); productTable.AddCell(new Paragraph(" ")); productTable.AddCell(new Paragraph(String.Format("{0}: {1} {2}", _localizationService.GetResource("PDFProductCatalog.Price", language.Id), associatedProduct.Price.ToString("0.00"), (await _currencyService.GetPrimaryStoreCurrency()).CurrencyCode), font)); productTable.AddCell(new Paragraph(String.Format("{0}: {1}", _localizationService.GetResource("PDFProductCatalog.SKU", language.Id), associatedProduct.Sku), font)); if (associatedProduct.IsShipEnabled && associatedProduct.Weight > Decimal.Zero) { productTable.AddCell(new Paragraph(String.Format("{0}: {1} {2}", _localizationService.GetResource("PDFProductCatalog.Weight", language.Id), associatedProduct.Weight.ToString("0.00"), (await _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId)).Name), font)); } if (associatedProduct.ManageInventoryMethod == ManageInventoryMethod.ManageStock) { productTable.AddCell(new Paragraph(String.Format("{0}: {1}", _localizationService.GetResource("PDFProductCatalog.StockQuantity", language.Id), associatedProduct.GetTotalStockQuantity()), font)); } productTable.AddCell(new Paragraph(" ")); pvNum++; } } return(productTable); }