Skip to content

Commit

Permalink
VCST-750: Add public-property (#58)
Browse files Browse the repository at this point in the history
feat: Add public store property.
fix: Update property description and fix misspelling.
  • Loading branch information
OlegoO authored Apr 11, 2024
1 parent 74a8a0f commit d014ce6
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 107 deletions.
40 changes: 26 additions & 14 deletions src/VirtoCommerce.CustomerReviews.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ public static class General
Name = "CustomerReviews.CustomerReviewsEnabled",
GroupName = "Store|Product Reviews",
ValueType = SettingValueType.Boolean,
DefaultValue = false
DefaultValue = false,
IsPublic = true,
};

public static readonly SettingDescriptor CustomerReviewsEnabledForAnonymous = new SettingDescriptor
{
Name = "CustomerReviews.CustomerReviewsEnabledForAnonymous",
GroupName = "Store|Product Reviews",
ValueType = SettingValueType.Boolean,
DefaultValue = false
DefaultValue = false,
IsPublic = true,
};

public static readonly SettingDescriptor CanSubmitReviewWhenHasOrder = new SettingDescriptor
Expand All @@ -85,12 +87,13 @@ public static class General
GroupName = "Store|Product Reviews",
ValueType = SettingValueType.Boolean,
DefaultValue = true,
IsPublic = true,
};

public static readonly SettingDescriptor CalculationMethod = new SettingDescriptor
{
Name = "CustomerReviews.Calculation.Method",
GroupName = "Product Reviews|General",
GroupName = "Store|Product Reviews",
ValueType = SettingValueType.ShortText,
DefaultValue = "Average",
};
Expand All @@ -99,21 +102,30 @@ public static IEnumerable<SettingDescriptor> AllSettings
{
get
{
return new List<SettingDescriptor>
{
CustomerReviewsEnabled,
CustomerReviewsEnabledForAnonymous,
CanSubmitReviewWhenHasOrder,
RequestReviewEnableJob,
RequestReviewCronJob,
RequestReviewDaysInState,
RequestReviewOrderInState,
RequestReviewMaxRequests
};
yield return CustomerReviewsEnabled;
yield return CustomerReviewsEnabledForAnonymous;
yield return CanSubmitReviewWhenHasOrder;
yield return RequestReviewEnableJob;
yield return RequestReviewCronJob;
yield return RequestReviewDaysInState;
yield return RequestReviewOrderInState;
yield return RequestReviewMaxRequests;
yield return CalculationMethod;
}
}
}

public static IEnumerable<SettingDescriptor> StoreSettings
{
get
{
yield return General.CustomerReviewsEnabled;
yield return General.CustomerReviewsEnabledForAnonymous;
yield return General.CanSubmitReviewWhenHasOrder;
yield return General.CalculationMethod;
}
}

public static IEnumerable<SettingDescriptor> JobSettings
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.OrdersModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.813.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"customerReviews": {
"blades": {
"review-list": {
"title": "Product Reviews",
"labels": {
"title": "Title",
"rating": "Rating",
"review": "Review",
"modifiedDate": "Last updated",
"no-review": "No Reviews found"
},
"customerReviews": {
"blades": {
"review-list": {
"title": "Product Reviews",
"labels": {
"title": "Title",
"rating": "Rating",
"review": "Review",
"modifiedDate": "Last updated",
"no-review": "No Reviews found"
},
"placeholders": {
"select-review-Status": "Select review status",
"select-entity-type": "Select entity type"
}
},
"store": {
"calculate-btn": {
"title": "Calculate product rating"
}
},
},
"store": {
"calculate-btn": {
"title": "Calculate product rating"
}
},
"review-detail": {
"labels": {
"title": "Title",
Expand All @@ -42,15 +42,15 @@
"product-detail": {
"description": "Product detail"
}
},
"widgets": {
"item-detail": {
"title": "Reviews"
},
"product-rating": {
"title": "Rating"
}
},
},
"widgets": {
"item-detail": {
"title": "Reviews"
},
"product-rating": {
"title": "Rating"
}
},
"dialogs": {
"customerReview-save": {
"title": "Save changes",
Expand All @@ -65,59 +65,59 @@
"message": "This action may result in a rating change. Are you sure you want to delete review?"
}
}
},
"permissions": {
"customerReviews:read": "Open product reviews",
"customerReviews:update": "Approve, reject and reset review status",
"customerReviews:delete": "Delete customer review related data",
"customerReviews:ratingRead": "Read rating",
"customerReviews:ratingRecalc": "Recalculate rating"
},
"notificationTypes": {
"CustomerReviewEmailNotification": {
"displayName": "Order request review notification",
"description": "The customer will get an email notification when the order is completed and the customer does not leave any product feedback."
}
},
"settings": {
"CustomerReviews": {
"CustomerReviewsEnabled": {
"title": "Product reviews enabled",
"description": ""
},
"CustomerReviewsEnabledForAnonymous": {
"title": "Allow anonymous to submit product reviews",
"description": ""
},
"CanSubmitReviewWhenHasOrder": {
"title": "Only customer who bought product can create new review",
"description": ""
},
"Calculation.Method": {
"title": "Rating calculation method",
"description": ""
},
"CustomerReviewsEnabledRequestReviewJob": {
"title": "Enable job to send e-mails request a reviews to customer when order in state at x days",
"description": ""
},
"CustomerReviewsRequestReviewCronJob": {
"title": "Cron expression for processing job execution",
"description": "The value is a regular CRON expression.\nTo run task every X minutes please use \"0/x * * * *\".\nTo run it every X hours at 00 minutes use \"0 */X * * *\". You can also specify minutes: \"15 */x * * *\"\nTo run it every X days at midnight use \"0 0 */x * *\""
},
"CustomerReviewsRequestReviewDaysInState": {
"title": "Order state at x days",
"description": ""
},
"CustomerReviewsRequestReviewOrderInState": {
"title": "Order state to send mails",
"description": ""
},
"CustomerReviewsRequestReviewMaxRequests": {
"title": "Max e-mails sent to customer",
"description": ""
}
},
"permissions": {
"customerReviews:read": "Open product reviews",
"customerReviews:update": "Approve, reject and reset review status",
"customerReviews:delete": "Delete customer review related data",
"customerReviews:ratingRead": "Read rating",
"customerReviews:ratingRecalc": "Recalculate rating"
},
"notificationTypes": {
"CustomerReviewEmailNotification": {
"displayName": "Order request review notification",
"description": "The customer will get an email notification when the order is completed and the customer does not leave any product feedback."
}
},
"settings": {
"CustomerReviews": {
"CustomerReviewsEnabled": {
"title": "Product reviews enabled",
"description": "When enabled, customers can provide feedback and reviews for products."
},
"CustomerReviewsEnabledForAnonymous": {
"title": "Allow anonymous to submit product reviews",
"description": "Enabling this option allows non-registered users to share their opinions on products."
},
"CanSubmitReviewWhenHasOrder": {
"title": "Only customer who bought product can create new review",
"description": "This restriction ensures that reviews are authored by genuine buyers."
},
"Calculation.Method": {
"title": "Rating calculation method",
"description": "Defines the approach or algorithm employed to determine ratings based on specific criteria or parameters. "
},
"CustomerReviewsEnabledRequestReviewJob": {
"title": "Auto Review Email Enabled",
"description": "Enable job to send emails requesting a review to customer when order is in state after x days"
},
"CustomerReviewsRequestReviewCronJob": {
"title": "Cron expression for processing job execution",
"description": "The value is a regular CRON expression.\nTo run task every X minutes please use \"0/x * * * *\".\nTo run it every X hours at 00 minutes use \"0 */X * * *\". You can also specify minutes: \"15 */x * * *\"\nTo run it every X days at midnight use \"0 0 */x * *\""
},
"CustomerReviewsRequestReviewDaysInState": {
"title": "Order state at x days",
"description": "Specifies the duration in days after which an order transitions to a new state."
},
"CustomerReviewsRequestReviewOrderInState": {
"title": "Order state to send mails",
"description": "Defines the order state at which emails are automatically sent to customers."
},
"CustomerReviewsRequestReviewMaxRequests": {
"title": "Max e-mails sent to customer",
"description": "Limits the maximum number of emails that can be sent to a customer within a specified timeframe."
}

}
}
}
}
}
}
14 changes: 4 additions & 10 deletions src/VirtoCommerce.CustomerReviews.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace VirtoCommerce.CustomerReviews.Web
public class Module : IModule, IHasConfiguration
{
private IApplicationBuilder _applicationBuilder;
private const string _storeModuleId = "VirtoCommerce.Store";

public ManifestModuleInfo ModuleInfo { get; set; }
public IConfiguration Configuration { get; set; }
Expand Down Expand Up @@ -92,11 +91,8 @@ public void PostInitialize(IApplicationBuilder appBuilder)
var settingsRegistrar = appBuilder.ApplicationServices.GetRequiredService<ISettingsRegistrar>();
settingsRegistrar.RegisterSettings(ReviewSettings.AllSettings, ModuleInfo.Id);

var jobSettings = ReviewSettings.JobSettings.Select(s => s.Name).ToList();
var storeSettings = settingsRegistrar.AllRegisteredSettings.Where(x => x.ModuleId.EqualsInvariant(ModuleInfo.Id) && !jobSettings.Contains(x.Name)).ToList();
storeSettings.Add(GetCalculatorStoreSetting());
settingsRegistrar.RegisterSettingsForType(storeSettings, nameof(Store));
settingsRegistrar.RegisterSettings(storeSettings, _storeModuleId);
UpdateCalculationMethod();
settingsRegistrar.RegisterSettingsForType(ReviewSettings.StoreSettings, nameof(Store));

var permissionsRegistrar = appBuilder.ApplicationServices.GetRequiredService<IPermissionsRegistrar>();
permissionsRegistrar.RegisterPermissions(ModuleInfo.Id, "CustomerReviews", ModuleConstants.Security.Permissions.AllPermissions);
Expand Down Expand Up @@ -132,13 +128,11 @@ public void Uninstall()
// Nothing to do here
}

private SettingDescriptor GetCalculatorStoreSetting()
private void UpdateCalculationMethod()
{
var result = ReviewSettings.General.CalculationMethod;
result.AllowedValues = _applicationBuilder.ApplicationServices.GetServices<IRatingCalculator>()
ReviewSettings.General.CalculationMethod.AllowedValues = _applicationBuilder.ApplicationServices.GetServices<IRatingCalculator>()
.Select(x => x.Name)
.ToArray<object>();
return result;
}
}
}
2 changes: 1 addition & 1 deletion src/VirtoCommerce.CustomerReviews.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>VirtoCommerce.CustomerReviews</id>
<version>3.801.0</version>
<version-tag />
<platformVersion>3.800.0</platformVersion>
<platformVersion>3.813.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Catalog" version="3.800.0" />
<dependency id="VirtoCommerce.Customer" version="3.800.0" />
Expand Down

0 comments on commit d014ce6

Please sign in to comment.