public void AddShoppingCartTokens(LiquidObject liquidObject, Customer customer, string personalMessage = "", string customerEmail = "") { var liquidShoppingCart = new LiquidShoppingCart(customer, personalMessage, customerEmail); liquidObject.ShoppingCart = liquidShoppingCart; _eventPublisher.EntityTokensAdded(customer, liquidShoppingCart, liquidObject); }
public async Task AddShoppingCartTokens(LiquidObject liquidObject, Customer customer, Store store, Language language, string personalMessage = "", string customerEmail = "") { var liquidShoppingCart = new LiquidShoppingCart(customer, store, language, personalMessage, customerEmail); liquidShoppingCart.ShoppingCartProducts = await ShoppingCartWishListProductListToHtmlTable(true, false); liquidShoppingCart.ShoppingCartProductsWithPictures = await ShoppingCartWishListProductListToHtmlTable(true, true); liquidShoppingCart.WishlistProducts = await ShoppingCartWishListProductListToHtmlTable(false, false); liquidShoppingCart.WishlistProductsWithPictures = await ShoppingCartWishListProductListToHtmlTable(false, true); async Task <string> ShoppingCartWishListProductListToHtmlTable(bool cart, bool withPicture) { string result; var sb = new StringBuilder(); sb.AppendLine("<table border=\"0\" style=\"width:100%;\">"); #region Products sb.AppendLine(string.Format("<tr style=\"background-color:{0};text-align:center;\">", _templatesSettings.Color1)); if (withPicture) { sb.AppendLine(string.Format("<th>{0}</th>", cart ? _localizationService.GetResource("Messages.ShoppingCart.Product(s).Picture", language.Id) : _localizationService.GetResource("Messages.Wishlist.Product(s).Picture", language.Id))); } sb.AppendLine(string.Format("<th>{0}</th>", cart ? _localizationService.GetResource("Messages.ShoppingCart.Product(s).Name", language.Id) : _localizationService.GetResource("Messages.Wishlist.Product(s).Name", language.Id))); sb.AppendLine(string.Format("<th>{0}</th>", cart ? _localizationService.GetResource("Messages.ShoppingCart.Product(s).Quantity", language.Id) : _localizationService.GetResource("Messages.Wishlist.Product(s).Quantity", language.Id))); sb.AppendLine("</tr>"); var productService = _serviceProvider.GetRequiredService <IProductService>(); var productAttributeFormatter = _serviceProvider.GetRequiredService <IProductAttributeFormatter>(); var pictureService = _serviceProvider.GetRequiredService <IPictureService>(); foreach (var item in cart ? customer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart) : customer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.Wishlist)) { var product = await productService.GetProductById(item.ProductId); sb.AppendLine(string.Format("<tr style=\"background-color: {0};text-align: center;\">", _templatesSettings.Color2)); //product name string productName = product.GetLocalized(x => x.Name, language.Id); if (withPicture) { string pictureUrl = ""; if (product.ProductPictures.Any()) { pictureUrl = await pictureService.GetPictureUrl(product.ProductPictures.OrderBy(x => x.DisplayOrder).FirstOrDefault().PictureId, _templatesSettings.PictureSize, storeLocation : store.SslEnabled?store.SecureUrl : store.Url); } sb.Append(string.Format("<td><img src=\"{0}\" alt=\"\"/></td>", pictureUrl)); } sb.AppendLine("<td style=\"padding: 0.6em 0.4em;text-align: left;\">" + WebUtility.HtmlEncode(productName)); //attributes if (!string.IsNullOrEmpty(item.AttributesXml)) { sb.AppendLine("<br />"); string attributeDescription = await productAttributeFormatter.FormatAttributes(product, item.AttributesXml, customer); sb.AppendLine(attributeDescription); } sb.AppendLine("</td>"); sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: center;\">{0}</td>", item.Quantity)); sb.AppendLine("</tr>"); } #endregion sb.AppendLine("</table>"); result = sb.ToString(); return(result); } liquidObject.ShoppingCart = liquidShoppingCart; await _mediator.EntityTokensAdded(customer, liquidShoppingCart, liquidObject); }