public EntityTokensAddedEvent(T entity, Drop liquidDrop, LiquidObject liquidObject)
 {
     _entity       = entity;
     _liquidDrop   = liquidDrop;
     _liquidObject = liquidObject;
 }
Example #2
0
        /// <summary>
        /// Sends a campaign to specified emails
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="subscriptions">Subscriptions</param>
        /// <returns>Total emails sent</returns>
        public virtual async Task <int> SendCampaign(Campaign campaign, EmailAccount emailAccount,
                                                     IEnumerable <NewsLetterSubscription> subscriptions)
        {
            if (campaign == null)
            {
                throw new ArgumentNullException("campaign");
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }

            int totalEmailsSent = 0;
            var language        = _serviceProvider.GetRequiredService <IWorkContext>().WorkingLanguage;

            foreach (var subscription in subscriptions)
            {
                Customer customer = null;

                if (!String.IsNullOrEmpty(subscription.CustomerId))
                {
                    customer = await _customerService.GetCustomerById(subscription.CustomerId);
                }

                if (customer == null)
                {
                    customer = await _customerService.GetCustomerByEmail(subscription.Email);
                }

                //ignore deleted or inactive customers when sending newsletter campaigns
                if (customer != null && (!customer.Active || customer.Deleted))
                {
                    continue;
                }

                LiquidObject liquidObject = new LiquidObject();
                await _messageTokenProvider.AddStoreTokens(liquidObject, _storeContext.CurrentStore, language, emailAccount);

                await _messageTokenProvider.AddNewsLetterSubscriptionTokens(liquidObject, subscription, _storeContext.CurrentStore);

                if (customer != null)
                {
                    await _messageTokenProvider.AddCustomerTokens(liquidObject, customer, _storeContext.CurrentStore, language);

                    await _messageTokenProvider.AddShoppingCartTokens(liquidObject, customer, _storeContext.CurrentStore, language);
                }

                var body    = LiquidExtensions.Render(liquidObject, campaign.Body);
                var subject = LiquidExtensions.Render(liquidObject, campaign.Subject);

                var email = new QueuedEmail
                {
                    Priority       = QueuedEmailPriority.Low,
                    From           = emailAccount.Email,
                    FromName       = emailAccount.DisplayName,
                    To             = subscription.Email,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };
                await _queuedEmailService.InsertQueuedEmail(email);
                await InsertCampaignHistory(new CampaignHistory()
                {
                    CampaignId = campaign.Id, CustomerId = subscription.CustomerId, Email = subscription.Email, CreatedDateUtc = DateTime.UtcNow, StoreId = campaign.StoreId
                });

                //activity log
                if (customer != null)
                {
                    await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), customer, campaign.Name);
                }
                else
                {
                    await _customerActivityService.InsertActivity("CustomerReminder.SendCampaign", campaign.Id, _localizationService.GetResource("ActivityLog.SendCampaign"), campaign.Name + " - " + subscription.Email);
                }

                totalEmailsSent++;
            }
            return(totalEmailsSent);
        }
        public async Task AddReturnRequestTokens(LiquidObject liquidObject, ReturnRequest returnRequest, Order order, Language language)
        {
            var liquidReturnRequest = new LiquidReturnRequest(returnRequest, order);

            liquidReturnRequest.Status   = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext);
            liquidReturnRequest.Products = await ProductListToHtmlTable();

            liquidReturnRequest.PickupAddressStateProvince =
                !string.IsNullOrEmpty(returnRequest.PickupAddress.StateProvinceId) ?
                (await _stateProvinceService.GetStateProvinceById(returnRequest.PickupAddress.StateProvinceId))?.GetLocalized(x => x.Name, language.Id) : "";

            liquidReturnRequest.PickupAddressCountry =
                !string.IsNullOrEmpty(returnRequest.PickupAddress.CountryId) ?
                (await _countryService.GetCountryById(returnRequest.PickupAddress.CountryId))?.GetLocalized(x => x.Name, language.Id) : "";

            async Task <string> ProductListToHtmlTable()
            {
                var sb = new StringBuilder();

                sb.AppendLine("<table border=\"0\" style=\"width:100%;\">");

                sb.AppendLine(string.Format("<tr style=\"text-align:center;\">"));
                sb.AppendLine(string.Format("<th>{0}</th>", _localizationService.GetResource("Messages.Order.Product(s).Name")));
                sb.AppendLine(string.Format("<th>{0}</th>", _localizationService.GetResource("Messages.Order.Product(s).Price")));
                sb.AppendLine(string.Format("<th>{0}</th>", _localizationService.GetResource("Messages.Order.Product(s).Quantity")));
                sb.AppendLine(string.Format("<th>{0}</th>", _localizationService.GetResource("Messages.Order.Product(s).ReturnReason")));
                sb.AppendLine(string.Format("<th>{0}</th>", _localizationService.GetResource("Messages.Order.Product(s).ReturnAction")));
                sb.AppendLine("</tr>");

                IProductService _productService = _serviceProvider.GetRequiredService <IProductService>();
                var             currency        = await _currencyService.GetCurrencyByCode(order.CustomerCurrencyCode);

                foreach (var rrItem in returnRequest.ReturnRequestItems)
                {
                    var orderItem = order.OrderItems.Where(x => x.Id == rrItem.OrderItemId).First();

                    sb.AppendLine(string.Format("<tr style=\"background-color: {0};text-align: center;\">", _templatesSettings.Color2));
                    string productName = (await _productService.GetProductById(orderItem.ProductId))?.GetLocalized(x => x.Name, order.CustomerLanguageId);

                    sb.AppendLine("<td style=\"padding: 0.6em 0.4em;text-align: left;\">" + WebUtility.HtmlEncode(productName));

                    sb.AppendLine("</td>");

                    string unitPriceStr;
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        unitPriceStr = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, currency, language, true);
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        unitPriceStr = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, currency, language, false);
                    }
                    sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: right;\">{0}</td>", unitPriceStr));
                    sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: center;\">{0}</td>", orderItem.Quantity));
                    sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: center;\">{0}</td>", rrItem.ReasonForReturn));
                    sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: center;\">{0}</td>", rrItem.RequestedAction));
                }

                sb.AppendLine("</table>");
                return(sb.ToString());
            }

            liquidObject.ReturnRequest = liquidReturnRequest;

            await _mediator.EntityTokensAdded(returnRequest, liquidReturnRequest, 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())
                        {
                            var picture = await pictureService.GetPictureById(product.ProductPictures.OrderBy(x => x.DisplayOrder).FirstOrDefault().PictureId);

                            if (picture != null)
                            {
                                pictureUrl = await pictureService.GetPictureUrl(picture, _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);
        }
        public async Task AddOrderTokens(LiquidObject liquidObject, Order order, Customer customer, Store store, OrderNote orderNote = null, Vendor vendor = null, decimal refundedAmount = 0)
        {
            var language = await _languageService.GetLanguageById(order.CustomerLanguageId);

            var currency = await _currencyService.GetCurrencyByCode(order.CustomerCurrencyCode);

            var productService  = _serviceProvider.GetRequiredService <IProductService>();
            var downloadService = _serviceProvider.GetRequiredService <IDownloadService>();
            var vendorService   = _serviceProvider.GetRequiredService <IVendorService>();

            var liquidOrder = new LiquidOrder(order, customer, language, currency, store, orderNote, vendor);

            foreach (var item in order.OrderItems.Where(x => x.VendorId == vendor?.Id || vendor == null))
            {
                var product = await productService.GetProductById(item.ProductId);

                var vendorItem = await vendorService.GetVendorById(item.VendorId);

                var liqitem = new LiquidOrderItem(item, product, order, language, currency, store, vendorItem);

                #region Download

                liqitem.IsDownloadAllowed = await downloadService.IsDownloadAllowed(item);

                liqitem.IsLicenseDownloadAllowed = await downloadService.IsLicenseDownloadAllowed(item);

                #endregion

                #region Unit price
                string unitPriceStr;
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.UnitPriceInclTax, order.CurrencyRate);
                    unitPriceStr = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, currency, language, true);
                }
                else
                {
                    //excluding tax
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.UnitPriceExclTax, order.CurrencyRate);
                    unitPriceStr = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, currency, language, false);
                }
                liqitem.UnitPrice = unitPriceStr;

                #endregion

                #region total price
                string priceStr;
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.PriceInclTax, order.CurrencyRate);
                    priceStr = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, currency, language, true);
                }
                else
                {
                    //excluding tax
                    var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.PriceExclTax, order.CurrencyRate);
                    priceStr = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, currency, language, false);
                }
                liqitem.TotalPrice = priceStr;

                #endregion

                string sku = "";
                if (product != null)
                {
                    sku = product.FormatSku(item.AttributesXml, _productAttributeParser);
                }

                liqitem.ProductSku = WebUtility.HtmlEncode(sku);
                liqitem.ShowSkuOnProductDetailsPage = _catalogSettings.ShowSkuOnProductDetailsPage;
                liqitem.ProductOldPrice             = _priceFormatter.FormatPrice(product.OldPrice, true, currency, language, true);

                liquidOrder.OrderItems.Add(liqitem);
            }

            liquidOrder.BillingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(order.BillingAddress?.CustomAttributes);

            liquidOrder.BillingCountry       = order.BillingAddress != null && !string.IsNullOrEmpty(order.BillingAddress.CountryId) ? (await _countryService.GetCountryById(order.BillingAddress.CountryId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : "";
            liquidOrder.BillingStateProvince = !string.IsNullOrEmpty(order.BillingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(order.BillingAddress.StateProvinceId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : "";

            liquidOrder.ShippingCountry          = order.ShippingAddress != null && !string.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : "";
            liquidOrder.ShippingStateProvince    = order.ShippingAddress != null && !string.IsNullOrEmpty(order.ShippingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(order.ShippingAddress.StateProvinceId)).GetLocalized(x => x.Name, order.CustomerLanguageId) : "";
            liquidOrder.ShippingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(order.ShippingAddress != null?order.ShippingAddress.CustomAttributes : "");

            var paymentMethod = _serviceProvider.GetRequiredService <IPaymentService>().LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
            liquidOrder.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, language.Id) : order.PaymentMethodSystemName;

            liquidOrder.AmountRefunded = _priceFormatter.FormatPrice(refundedAmount, true, currency, language, false);

            Dictionary <string, string> dict = new Dictionary <string, string>();
            foreach (var item in order.TaxRatesDictionary)
            {
                string taxRate  = string.Format(_localizationService.GetResource("Messages.Order.TaxRateLine"), _priceFormatter.FormatTaxRate(item.Key));
                string taxValue = _priceFormatter.FormatPrice(item.Value, true, currency, language, false);
                dict.Add(taxRate, taxValue);
            }
            liquidOrder.TaxRates = dict;

            Dictionary <string, string> cards = new Dictionary <string, string>();
            var servicegiftCard = _serviceProvider.GetRequiredService <IGiftCardService>();
            var gcuhC           = await servicegiftCard.GetAllGiftCardUsageHistory(order.Id);

            foreach (var gcuh in gcuhC)
            {
                var giftCard = await servicegiftCard.GetGiftCardById(gcuh.GiftCardId);

                string giftCardText   = string.Format(_localizationService.GetResource("Messages.Order.GiftCardInfo", language.Id), WebUtility.HtmlEncode(giftCard.GiftCardCouponCode));
                string giftCardAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, currency, language, false);
                cards.Add(giftCardText, giftCardAmount);
            }
            liquidOrder.GiftCards = cards;
            if (order.RedeemedRewardPointsEntry != null)
            {
                liquidOrder.RPTitle  = string.Format(_localizationService.GetResource("Messages.Order.RewardPoints", language.Id), -order.RedeemedRewardPointsEntry?.Points);
                liquidOrder.RPAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, currency, language, false);
            }
            void CalculateSubTotals()
            {
                string _cusSubTotal;
                bool   _displaySubTotalDiscount;
                string _cusSubTotalDiscount;
                string _cusShipTotal;
                string _cusPaymentMethodAdditionalFee;
                bool   _displayTax;
                string _cusTaxTotal;
                bool   _displayTaxRates;
                bool   _displayDiscount;
                string _cusDiscount;
                string _cusTotal;

                _displaySubTotalDiscount = false;
                _cusSubTotalDiscount     = string.Empty;
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal)
                {
                    //including tax

                    //subtotal
                    var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate);
                    _cusSubTotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, currency, language, true);
                    //discount (applied to order subtotal)
                    var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate);
                    if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero)
                    {
                        _cusSubTotalDiscount     = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, currency, language, true);
                        _displaySubTotalDiscount = true;
                    }
                }
                else
                {
                    //exсluding tax

                    //subtotal
                    var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate);
                    _cusSubTotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, currency, language, false);
                    //discount (applied to order subtotal)
                    var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate);
                    if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero)
                    {
                        _cusSubTotalDiscount     = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, currency, language, false);
                        _displaySubTotalDiscount = true;
                    }
                }

                //shipping, payment method fee
                _cusTaxTotal = string.Empty;
                _cusDiscount = string.Empty;
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax

                    //shipping
                    var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate);
                    _cusShipTotal = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, currency, language, true);
                    //payment method additional fee
                    var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate);
                    _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, currency, language, true);
                }
                else
                {
                    //excluding tax

                    //shipping
                    var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate);
                    _cusShipTotal = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, currency, language, false);
                    //payment method additional fee
                    var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate);
                    _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, currency, language, false);
                }

                //shipping
                bool displayShipping = order.ShippingStatus != ShippingStatus.ShippingNotRequired;

                //payment method fee
                bool displayPaymentMethodFee = order.PaymentMethodAdditionalFeeExclTax > decimal.Zero;

                //tax
                _displayTax      = true;
                _displayTaxRates = true;
                if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    _displayTax      = false;
                    _displayTaxRates = false;
                }
                else
                {
                    if (order.OrderTax == 0 && _taxSettings.HideZeroTax)
                    {
                        _displayTax      = false;
                        _displayTaxRates = false;
                    }
                    else
                    {
                        var _taxRates = new SortedDictionary <decimal, decimal>();
                        foreach (var tr in order.TaxRatesDictionary)
                        {
                            _taxRates.Add(tr.Key, _currencyService.ConvertCurrency(tr.Value, order.CurrencyRate));
                        }

                        _displayTaxRates = _taxSettings.DisplayTaxRates && _taxRates.Any();
                        _displayTax      = !_displayTaxRates;

                        var    orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate);
                        string taxStr = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false);
                        _cusTaxTotal = taxStr;
                    }
                }

                //discount
                _displayDiscount = false;
                if (order.OrderDiscount > decimal.Zero)
                {
                    var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate);
                    _cusDiscount     = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false);
                    _displayDiscount = true;
                }

                //total
                var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate);

                _cusTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false);


                liquidOrder.SubTotal = _cusSubTotal;
                liquidOrder.DisplaySubTotalDiscount = _displaySubTotalDiscount;
                liquidOrder.SubTotalDiscount        = _cusSubTotalDiscount;
                liquidOrder.Shipping        = _cusShipTotal;
                liquidOrder.Tax             = _cusTaxTotal;
                liquidOrder.Total           = _cusTotal;
                liquidOrder.DisplayDiscount = _displayDiscount;
                liquidOrder.DisplayTaxRates = _displayTaxRates;
            }

            CalculateSubTotals();

            liquidObject.Order = liquidOrder;

            await _mediator.EntityTokensAdded(order, liquidOrder, liquidObject);
        }
 public LiquidObjectBuilder(IMediator mediator, LiquidObject liquidObject)
 {
     _object   = liquidObject;
     _chain    = new List <Func <LiquidObject, Task> >();
     _mediator = mediator;
 }
 public static void MessageTokensAdded(this IEventPublisher eventPublisher, MessageTemplate message, LiquidObject liquidObject)
 {
     eventPublisher.Publish(new MessageTokensAddedEvent(message, liquidObject));
 }
 public static void EntityTokensAdded <T>(this IEventPublisher eventPublisher, T entity, Drop liquidDrop, LiquidObject liquidObject) where T : ParentEntity
 {
     eventPublisher.Publish(new EntityTokensAddedEvent <T>(entity, liquidDrop, liquidObject));
 }
 public MessageTokensAddedEvent(MessageTemplate message, LiquidObject liquidObject)
 {
     _message      = message;
     _liquidObject = liquidObject;
 }