Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Further improvements with AttributeControlType.FileUpload

supportcfd37f4afe50
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
index aa81bfa5e..b3dbbe97c 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
@@ -198,23 +198,17 @@ namespace Grand.Business.Catalog.Services.Products
else if (attribute.AttributeControlTypeId == AttributeControlType.FileUpload)
{
//file upload
- _ = Guid.TryParse(valueStr, out var downloadGuid);
- var attributeName = productAttribute.GetTranslation(a => a.Name, langId);
- var attributeText = "";
- if (allowHyperlinks)
- {
- var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), downloadGuid);
- attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, attributeName);
- }
- else
+ if (Guid.TryParse(valueStr, out var downloadGuid))
{
- //hyperlinks aren't allowed
- attributeText = attributeName;
+ var attributeText = string.Empty;
+ var attributeName = productAttribute.GetTranslation(a => a.Name, langId);
+ if (allowHyperlinks)
+ {
+ var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), downloadGuid);
+ attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, attribute.GetTranslation(a => a.TextPrompt, langId));
+ }
+ formattedAttribute = string.Format("{0}: {1}", attributeName, attributeText);
}
- //encode
- if (htmlEncode)
- attributeName = WebUtility.HtmlEncode(attributeName);
- formattedAttribute = string.Format("{0}: {1}", attributeName, attributeText);
}
else
{
diff --git a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
index 14b9d4824..4a94232b5 100644
--- a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
+++ b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
@@ -1,9 +1,8 @@
+using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Prices;
using Grand.Business.Core.Interfaces.Catalog.Tax;
using Grand.Business.Core.Interfaces.Checkout.CheckoutAttributes;
-using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Storage;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Customers;
@@ -23,21 +22,18 @@ namespace Grand.Business.Checkout.Services.CheckoutAttributes
private readonly ICurrencyService _currencyService;
private readonly ITaxService _taxService;
private readonly IPriceFormatter _priceFormatter;
- private readonly IDownloadService _downloadService;
public CheckoutAttributeFormatter(IWorkContext workContext,
ICheckoutAttributeParser checkoutAttributeParser,
ICurrencyService currencyService,
ITaxService taxService,
- IPriceFormatter priceFormatter,
- IDownloadService downloadService)
+ IPriceFormatter priceFormatter)
{
_workContext = workContext;
_checkoutAttributeParser = checkoutAttributeParser;
_currencyService = currencyService;
_taxService = taxService;
_priceFormatter = priceFormatter;
- _downloadService = downloadService;
}
/// <summary>
@@ -87,33 +83,16 @@ namespace Grand.Business.Checkout.Services.CheckoutAttributes
else if (attribute.AttributeControlTypeId == AttributeControlType.FileUpload)
{
//file upload
- Guid downloadGuid;
- Guid.TryParse(valueStr, out downloadGuid);
- var download = await _downloadService.GetDownloadByGuid(downloadGuid);
- if (download != null)
+ if (Guid.TryParse(valueStr, out var downloadGuid))
{
- string attributeText = "";
- var fileName = string.Format("{0}{1}",
- download.Filename ?? download.DownloadGuid.ToString(),
- download.Extension);
- //encode (if required)
- if (htmlEncode)
- fileName = WebUtility.HtmlEncode(fileName);
+ var attributeText = string.Empty;
+ var attributeName = attribute.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id);
if (allowHyperlinks)
{
//hyperlinks are allowed
- var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), download.DownloadGuid);
- attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, fileName);
+ var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), downloadGuid);
+ attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, attribute.GetTranslation(a => a.TextPrompt, _workContext.WorkingLanguage.Id));
}
- else
- {
- //hyperlinks aren't allowed
- attributeText = fileName;
- }
- var attributeName = attribute.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id);
- //encode (if required)
- if (htmlEncode)
- attributeName = WebUtility.HtmlEncode(attributeName);
formattedAttribute = string.Format("{0}: {1}", attributeName, attributeText);
}
}
diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
index 673ce1643..ddd7246f4 100644
--- a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
@@ -1,7 +1,5 @@
using Grand.Business.Core.Extensions;
-using Grand.Business.Marketing.Extensions;
using Grand.Business.Core.Interfaces.Marketing.Contacts;
-using Grand.Business.Core.Interfaces.Storage;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Customers;
@@ -19,17 +17,14 @@ namespace Grand.Business.Marketing.Services.Contacts
public partial class ContactAttributeParser : IContactAttributeParser
{
private readonly IContactAttributeService _contactAttributeService;
- private readonly IDownloadService _downloadService;
private readonly IWorkContext _workContext;
public ContactAttributeParser(
IContactAttributeService contactAttributeService,
- IDownloadService downloadService,
IWorkContext workContext
)
{
_contactAttributeService = contactAttributeService;
- _downloadService = downloadService;
_workContext = workContext;
}
@@ -212,33 +207,15 @@ namespace Grand.Business.Marketing.Services.Contacts
else if (attribute.AttributeControlType == AttributeControlType.FileUpload)
{
//file upload
- Guid downloadGuid;
- Guid.TryParse(valueStr, out downloadGuid);
- var download = await _downloadService.GetDownloadByGuid(downloadGuid);
- if (download != null)
+ if (Guid.TryParse(valueStr, out var downloadGuid))
{
- string attributeText = "";
- var fileName = string.Format("{0}{1}",
- download.Filename ?? download.DownloadGuid.ToString(),
- download.Extension);
- //encode (if required)
- if (htmlEncode)
- fileName = WebUtility.HtmlEncode(fileName);
+ var attributeText = string.Empty;
+ var attributeName = attribute.GetTranslation(a => a.Name, language.Id);
if (allowHyperlinks)
{
- //hyperlinks are allowed
- var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), download.DownloadGuid);
- attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, fileName);
- }
- else
- {
- //hyperlinks aren't allowed
- attributeText = fileName;
+ var downloadLink = string.Format("{0}/download/getfileupload/?downloadId={1}", _workContext.CurrentHost.Url.TrimEnd('/'), downloadGuid);
+ attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, attribute.GetTranslation(a => a.TextPrompt, language.Id));
}
- var attributeName = attribute.GetTranslation(a => a.Name, language.Id);
- //encode (if required)
- if (htmlEncode)
- attributeName = WebUtility.HtmlEncode(attributeName);
formattedAttribute = string.Format("{0}: {1}", attributeName, attributeText);
}
}