Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nopSolutions/nopCommerce
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
Marianna Koroleva authored and Marianna Koroleva committed Apr 5, 2020
2 parents c34e797 + fa9e8b6 commit b55bfd2
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/Libraries/Nop.Core/Domain/Orders/GiftCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class GiftCard : BaseEntity
/// <summary>
/// Gets or sets the associated order item identifier
/// </summary>
public int? PurchasedWithOrderItemId { get; set; } //TODO: why not OrderId?
public int? PurchasedWithOrderItemId { get; set; }

/// <summary>
/// Gets or sets the gift card type identifier
Expand Down
22 changes: 22 additions & 0 deletions src/Libraries/Nop.Core/Security/CookieSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Nop.Core.Configuration;

namespace Nop.Core.Security
{
public partial class CookieSettings : ISettings
{
/// <summary>
/// Expiration time on hours for the "Compare products" cookie
/// </summary>
public int CompareProductsCookieExpires { get; set; }

/// <summary>
/// Expiration time on hours for the "Recently viewed products" cookie
/// </summary>
public int RecentlyViewedProductsCookieExpires { get; set; }

/// <summary>
/// Expiration time on hours for the "Customer" cookie
/// </summary>
public int CustomerCookieExpires { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Data;
using FluentMigrator.Builders.Create.Table;
using FluentMigrator.Builders.Create.Table;
using Nop.Core.Domain.Messages;
using Nop.Data.Extensions;

namespace Nop.Data.Mapping.Builders.Messages
{
Expand All @@ -22,7 +20,8 @@ public override void MapEntity(CreateTableExpressionBuilder table)
.WithColumn(nameof(MessageTemplate.Name)).AsString(200).NotNullable()
.WithColumn(nameof(MessageTemplate.BccEmailAddresses)).AsString(200).Nullable()
.WithColumn(nameof(MessageTemplate.Subject)).AsString(1000).Nullable()
.WithColumn(nameof(MessageTemplate.EmailAccountId)).AsInt32().ForeignKey<EmailAccount>(onDelete: Rule.None);
//don't create an ForeignKey for the EmailAccount table, because this field may by zero
.WithColumn(nameof(MessageTemplate.EmailAccountId)).AsInt32();
}

#endregion
Expand Down
6 changes: 5 additions & 1 deletion src/Libraries/Nop.Services/Catalog/CompareProductsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Nop.Core;
using Nop.Core.Domain.Catalog;
using Nop.Core.Http;
using Nop.Core.Security;

namespace Nop.Services.Catalog
{
Expand All @@ -16,6 +17,7 @@ public partial class CompareProductsService : ICompareProductsService
#region Fields

private readonly CatalogSettings _catalogSettings;
private readonly CookieSettings _cookieSettings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IProductService _productService;
private readonly IWebHelper _webHelper;
Expand All @@ -25,11 +27,13 @@ public partial class CompareProductsService : ICompareProductsService
#region Ctor

public CompareProductsService(CatalogSettings catalogSettings,
CookieSettings cookieSettings,
IHttpContextAccessor httpContextAccessor,
IProductService productService,
IWebHelper webHelper)
{
_catalogSettings = catalogSettings;
_cookieSettings = cookieSettings;
_httpContextAccessor = httpContextAccessor;
_productService = productService;
_webHelper = webHelper;
Expand Down Expand Up @@ -75,7 +79,7 @@ protected virtual void AddCompareProductsCookie(IEnumerable<int> comparedProduct
var comparedProductIdsCookie = string.Join(",", comparedProductIds);

//create cookie options
var cookieExpires = 24 * 10; //TODO make configurable
var cookieExpires = _cookieSettings.CompareProductsCookieExpires;
var cookieOptions = new CookieOptions
{
Expires = DateTime.Now.AddHours(cookieExpires),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Nop.Core;
using Nop.Core.Domain.Catalog;
using Nop.Core.Http;
using Nop.Core.Security;

namespace Nop.Services.Catalog
{
Expand All @@ -16,6 +17,7 @@ public partial class RecentlyViewedProductsService : IRecentlyViewedProductsServ
#region Fields

private readonly CatalogSettings _catalogSettings;
private readonly CookieSettings _cookieSettings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IProductService _productService;
private readonly IWebHelper _webHelper;
Expand All @@ -25,11 +27,13 @@ public partial class RecentlyViewedProductsService : IRecentlyViewedProductsServ
#region Ctor

public RecentlyViewedProductsService(CatalogSettings catalogSettings,
CookieSettings cookieSettings,
IHttpContextAccessor httpContextAccessor,
IProductService productService,
IWebHelper webHelper)
{
_catalogSettings = catalogSettings;
_cookieSettings = cookieSettings;
_httpContextAccessor = httpContextAccessor;
_productService = productService;
_webHelper = webHelper;
Expand Down Expand Up @@ -85,7 +89,7 @@ protected virtual void AddRecentlyViewedProductsCookie(IEnumerable<int> recently
var productIdsCookie = string.Join(",", recentlyViewedProductIds);

//create cookie options
var cookieExpires = 24 * 10; //TODO make configurable
var cookieExpires = _cookieSettings.RecentlyViewedProductsCookieExpires;
var cookieOptions = new CookieOptions
{
Expires = DateTime.Now.AddHours(cookieExpires),
Expand Down
4 changes: 1 addition & 3 deletions src/Libraries/Nop.Services/ExportImport/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,6 @@ private int ExportSpecificationAttributes(Product item, PropertyManager<ExportSp

private byte[] ExportOrderToXlsxWithProducts(PropertyByName<Order>[] properties, IEnumerable<Order> itemsToExport)
{
//TODO: _productService.GetProductById(oi.ProductId) - variant add as local func with cache

var orderItemProperties = new[]
{
new PropertyByName<OrderItem>("Name", oi => _productService.GetProductById(oi.ProductId).Name),
Expand Down Expand Up @@ -1854,7 +1852,7 @@ public virtual byte[] ExportCustomerGdprInfoToXlsx(Customer customer, int storeI
}, _catalogSettings);

var orderItemsManager = new PropertyManager<OrderItem>(new[]
{ //TODO: _productService.GetProductById(oi.ProductId) - variant add as local func with cache
{
new PropertyByName<OrderItem>("SKU", oi => _productService.GetProductById(oi.ProductId).Sku),
new PropertyByName<OrderItem>("Name", oi => _localizationService.GetLocalized(_productService.GetProductById(oi.ProductId), p => p.Name)),
new PropertyByName<OrderItem>("Price", oi => _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(_orderService.GetOrderById(oi.OrderId).CustomerTaxDisplayType == TaxDisplayType.IncludingTax ? oi.UnitPriceInclTax : oi.UnitPriceExclTax, _orderService.GetOrderById(oi.OrderId).CurrencyRate), true, _orderService.GetOrderById(oi.OrderId).CustomerCurrencyCode, false, _workContext.WorkingLanguage)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using Nop.Core.Domain.Topics;
using Nop.Core.Domain.Vendors;
using Nop.Core.Infrastructure;
using Nop.Core.Security;
using Nop.Data;
using Nop.Services.Blogs;
using Nop.Services.Caching.Extensions;
Expand Down Expand Up @@ -6815,6 +6816,13 @@ protected virtual void InstallSettings()
BypassOnLocal = true,
PreAuthenticate = true
});

settingService.SaveSetting(new CookieSettings
{
CompareProductsCookieExpires = 24 *10,
RecentlyViewedProductsCookieExpires = 24 *10,
CustomerCookieExpires = 24 * 365
});
}

protected virtual void InstallCheckoutAttributes()
Expand Down
2 changes: 0 additions & 2 deletions src/Libraries/Nop.Services/Media/PictureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,6 @@ public virtual string GetFileExtensionFromMimeType(string mimeType)
if (mimeType == null)
return null;

//TODO use FileExtensionContentTypeProvider to get file extension

var parts = mimeType.Split('/');
var lastPart = parts[parts.Length - 1];
switch (lastPart)
Expand Down
24 changes: 18 additions & 6 deletions src/Libraries/Nop.Services/Orders/OrderProcessingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,20 +1136,32 @@ protected virtual void ProcessOrderPaid(Order order)
_pdfService.PrintOrderToPdf(order) : null;
var orderPaidAttachmentFileName = _orderSettings.AttachPdfInvoiceToOrderPaidEmail ?
"order.pdf" : null;
_workflowMessageService.SendOrderPaidCustomerNotification(order, order.CustomerLanguageId,
var orderPaidCustomerNotificationQueuedEmailIds = _workflowMessageService.SendOrderPaidCustomerNotification(order, order.CustomerLanguageId,
orderPaidAttachmentFilePath, orderPaidAttachmentFileName);

_workflowMessageService.SendOrderPaidStoreOwnerNotification(order, _localizationSettings.DefaultAdminLanguageId);
if (orderPaidCustomerNotificationQueuedEmailIds.Any())
AddOrderNote(order, $"\"Order paid\" email (to customer) has been queued. Queued email identifiers: {string.Join(", ", orderPaidCustomerNotificationQueuedEmailIds)}.");

var orderPaidStoreOwnerNotificationQueuedEmailIds = _workflowMessageService.SendOrderPaidStoreOwnerNotification(order, _localizationSettings.DefaultAdminLanguageId);
if (orderPaidStoreOwnerNotificationQueuedEmailIds.Any())
AddOrderNote(order, $"\"Order paid\" email (to store owner) has been queued. Queued email identifiers: {string.Join(", ", orderPaidStoreOwnerNotificationQueuedEmailIds)}.");

var vendors = GetVendorsInOrder(order);
foreach (var vendor in vendors)
{
_workflowMessageService.SendOrderPaidVendorNotification(order, vendor, _localizationSettings.DefaultAdminLanguageId);
var orderPaidVendorNotificationQueuedEmailIds = _workflowMessageService.SendOrderPaidVendorNotification(order, vendor, _localizationSettings.DefaultAdminLanguageId);

if (orderPaidVendorNotificationQueuedEmailIds.Any())
AddOrderNote(order, $"\"Order paid\" email (to vendor) has been queued. Queued email identifiers: {string.Join(", ", orderPaidVendorNotificationQueuedEmailIds)}.");
}

if (order.AffiliateId != 0)
_workflowMessageService.SendOrderPaidAffiliateNotification(order, _localizationSettings.DefaultAdminLanguageId);

//TODO add "order paid email sent" order note
{
var orderPaidAffiliateNotificationQueuedEmailIds = _workflowMessageService.SendOrderPaidAffiliateNotification(order,
_localizationSettings.DefaultAdminLanguageId);
if (orderPaidAffiliateNotificationQueuedEmailIds.Any())
AddOrderNote(order, $"\"Order paid\" email (to affiliate) has been queued. Queued email identifiers: {string.Join(", ", orderPaidAffiliateNotificationQueuedEmailIds)}.");
}
}

//customer roles with "purchased with product" specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public virtual decimal AdjustShippingRate(decimal shippingRate,
return decimal.Zero;

ShippingOption shippingOption = null;
if (customer != null) //TODO: customer can't be null
if (customer != null)
shippingOption = _genericAttributeService.GetAttribute<ShippingOption>(customer, NopCustomerDefaults.SelectedShippingOptionAttribute, _storeContext.CurrentStore.Id);

if (shippingOption != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/Nop.Services/Orders/ShoppingCartService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected virtual bool ShoppingCartItemIsEqual(ShoppingCartItem shoppingCartItem
//price is the same (for products which require customers to enter a price)
if (product.CustomerEntersPrice)
{
//TODO should we use PriceCalculationService.RoundPrice here?
//we use rounding to eliminate errors associated with storing real numbers in memory when comparing
var customerEnteredPricesEqual = Math.Round(shoppingCartItem.CustomerEnteredPrice, 2) == Math.Round(customerEnteredPrice, 2);
if (!customerEnteredPricesEqual)
return false;
Expand Down
8 changes: 6 additions & 2 deletions src/Presentation/Nop.Web.Framework/WebWorkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Nop.Core.Domain.Tax;
using Nop.Core.Domain.Vendors;
using Nop.Core.Http;
using Nop.Core.Security;
using Nop.Services.Authentication;
using Nop.Services.Common;
using Nop.Services.Customers;
Expand All @@ -28,6 +29,7 @@ public partial class WebWorkContext : IWorkContext
{
#region Fields

private readonly CookieSettings _cookieSettings;
private readonly CurrencySettings _currencySettings;
private readonly IAuthenticationService _authenticationService;
private readonly ICurrencyService _currencyService;
Expand All @@ -54,7 +56,8 @@ public partial class WebWorkContext : IWorkContext

#region Ctor

public WebWorkContext(CurrencySettings currencySettings,
public WebWorkContext(CookieSettings cookieSettings,
CurrencySettings currencySettings,
IAuthenticationService authenticationService,
ICurrencyService currencyService,
ICustomerService customerService,
Expand All @@ -69,6 +72,7 @@ public WebWorkContext(CurrencySettings currencySettings,
LocalizationSettings localizationSettings,
TaxSettings taxSettings)
{
_cookieSettings = cookieSettings;
_currencySettings = currencySettings;
_authenticationService = authenticationService;
_currencyService = currencyService;
Expand Down Expand Up @@ -113,7 +117,7 @@ protected virtual void SetCustomerCookie(Guid customerGuid)
_httpContextAccessor.HttpContext.Response.Cookies.Delete(cookieName);

//get date of cookie expiration
var cookieExpires = 24 * 365; //TODO make configurable
var cookieExpires = _cookieSettings.CustomerCookieExpires;
var cookieExpiresDate = DateTime.Now.AddHours(cookieExpires);

//if passed guid is empty set cookie as expired
Expand Down
18 changes: 18 additions & 0 deletions src/Presentation/Nop.Web/Areas/Admin/Factories/BlogModelFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Mvc.Rendering;
using Nop.Core.Domain.Blogs;
using Nop.Core.Domain.Catalog;
Expand Down Expand Up @@ -181,6 +183,22 @@ public virtual BlogPostModel PrepareBlogPostModel(BlogPostModel model, BlogPost
model.IncludeInSitemap = true;
}

var blogTags = _blogService.GetAllBlogPostTags(0, 0, true);
var blogTagsSb = new StringBuilder();
blogTagsSb.Append("var initialBlogTags = [");
for (var i = 0; i < blogTags.Count; i++)
{
var tag = blogTags[i];
blogTagsSb.Append("'");
blogTagsSb.Append(JavaScriptEncoder.Default.Encode(tag.Name));
blogTagsSb.Append("'");
if (i != blogTags.Count - 1)
blogTagsSb.Append(",");
}
blogTagsSb.Append("]");

model.InitialBlogTags = blogTagsSb.ToString();

//prepare available languages
_baseAdminModelFactory.PrepareLanguages(model.AvailableLanguages, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Mvc.Rendering;
using Nop.Core;
using Nop.Core.Domain.Catalog;
Expand Down Expand Up @@ -905,6 +906,22 @@ public virtual ProductModel PrepareProductModel(ProductModel model, Product prod
//prepare model stores
_storeMappingSupportedModelFactory.PrepareModelStores(model, product, excludeProperties);

var productTags = _productTagService.GetAllProductTags();
var productTagsSb = new StringBuilder();
productTagsSb.Append("var initialProductTags = [");
for (var i = 0; i < productTags.Count; i++)
{
var tag = productTags[i];
productTagsSb.Append("'");
productTagsSb.Append(JavaScriptEncoder.Default.Encode(tag.Name));
productTagsSb.Append("'");
if (i != productTags.Count - 1)
productTagsSb.Append(",");
}
productTagsSb.Append("]");

model.InitialProductTags = productTagsSb.ToString();

return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ protected virtual void CreateBlogsMaps()
.ForMember(model => model.CreatedOn, options => options.Ignore())
.ForMember(model => model.LanguageName, options => options.Ignore())
.ForMember(model => model.NotApprovedComments, options => options.Ignore())
.ForMember(model => model.SeName, options => options.Ignore());
.ForMember(model => model.SeName, options => options.Ignore())
.ForMember(model => model.InitialBlogTags, options => options.Ignore());
CreateMap<BlogPostModel, BlogPost>()
.ForMember(entity => entity.CreatedOnUtc, options => options.Ignore());

Expand Down Expand Up @@ -439,7 +440,8 @@ protected virtual void CreateCatalogMaps()
.ForMember(model => model.StockQuantityHistory, options => options.Ignore())
.ForMember(model => model.StockQuantityHistorySearchModel, options => options.Ignore())
.ForMember(model => model.StockQuantityStr, options => options.Ignore())
.ForMember(model => model.TierPriceSearchModel, options => options.Ignore());
.ForMember(model => model.TierPriceSearchModel, options => options.Ignore())
.ForMember(model => model.InitialProductTags, options => options.Ignore());
CreateMap<ProductModel, Product>()
.ForMember(entity => entity.ApprovedRatingSum, options => options.Ignore())
.ForMember(entity => entity.ApprovedTotalReviews, options => options.Ignore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public BlogPostModel()
[NopResourceDisplayName("Admin.ContentManagement.Blog.BlogPosts.Fields.Tags")]
public string Tags { get; set; }

public string InitialBlogTags { get; set; }

public int ApprovedComments { get; set; }

public int NotApprovedComments { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public ProductModel()
[NopResourceDisplayName("Admin.Catalog.Products.Fields.ProductTags")]
public string ProductTags { get; set; }

public string InitialProductTags { get; set; }

[NopResourceDisplayName("Admin.Catalog.Products.Fields.Sku")]
public string Sku { get; set; }

Expand Down
Loading

0 comments on commit b55bfd2

Please sign in to comment.