Skip to content

Commit

Permalink
add a new condition (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
basilkot authored and OlegoO committed Mar 18, 2024
1 parent 1aececb commit 3f09674
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Linq;
using VirtoCommerce.CoreModule.Core.Common;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.CoreModule.Core.Conditions
{
public class UserGroupIsCondition : ConditionTree
{
public string[] Groups { get; set; }

/// <summary>
/// ((EvaluationContextBase)x).UserGroupsContains
/// </summary>
public override bool IsSatisfiedBy(IEvaluationContext context)
{
var result = false;
if (context is EvaluationContextBase evaluationContextBase && !Groups.IsNullOrEmpty())
{
result = evaluationContextBase.UserGroups != null;
if (result)
{
result = evaluationContextBase.UserGroups
.Any(x => Groups.Any(group => string.Equals(x, group, StringComparison.InvariantCultureIgnoreCase)));
}
}

return result;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,22 @@
<a class="__link" ng-click="openItemSelectWizard(element)">{{element.productName?element.productName + ' (' + element.productCode + ')' : 'select product' }}</a> items
</script>
<script type="text/ng-template" id="expression-UserGroupsContainsCondition.html">
User groups contains
User group contains
<div class="form-input">
<input required class="form-control" ng-model="element1.group" placeholder="Enter group" />
</div>
</script>
<script type="text/ng-template" id="expression-UserGroupIsCondition.html">
User group is
<div class="form-input">
<ui-select multiple ng-model="element1.groups" ng-controller="virtoCommerce.dynamicExpressions.conditionUserGroupsController">
<ui-select-match placeholder="{{'customer.blades.contact-detail.placeholders.groups' | translate}}">{{$item|json}}</ui-select-match>
<ui-select-choices repeat="x in groups | filter: $select.search">
<span ng-bind-html="x | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
</script>
<!--DYNAMIC CONTENT PUBLISHING-->
<script type="text/ng-template" id="expression-BlockContentCondition.html">
If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ angular.module('virtoCommerce.coreModule.common')
id: 'UserGroupsContainsCondition',
displayName: 'User group contains...'
});
dynamicExpressionService.registerExpression({
id: 'UserGroupIsCondition',
displayName: 'User group is...'
});

var availableExcludings = [
{
Expand Down Expand Up @@ -251,6 +255,9 @@ angular.module('virtoCommerce.coreModule.common')
.controller('virtoCommerce.dynamicExpressions.conditionGeoTimeZoneController', ['$scope', 'platformWebApp.common.timeZones', function ($scope, timeZones) {
$scope.timeZones = timeZones.query();
}])
.controller('virtoCommerce.dynamicExpressions.conditionUserGroupsController', ['$scope', 'platformWebApp.settings', function ($scope, settings) {
$scope.groups = settings.getValues({ id: 'Customer.MemberGroups' });
}])
.controller('virtoCommerce.dynamicExpressions.shippingMethodRewardController', ['$scope', function ($scope) {
function initialize(storeIds) {
//Use stores ($scope.stores) from parent controller virtoCommerce.marketingModule.promotionDetailController
Expand Down

0 comments on commit 3f09674

Please sign in to comment.