Skip to content

Commit 363d034

Browse files
update discount widget
1 parent e33a572 commit 363d034

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/helpers/DiscountConditionHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public function getIsTrue()
116116

117117
} else {
118118

119-
if ($this->field && strpos("element.", $this->field) != -1) {
119+
if ($this->field && strpos($this->field, "element.") !== false) {
120+
120121
$field = str_replace("element.", "", $this->field);
121122

122123
return $this->isTrue($this->value, $this->shopCmsContentElement->{$field});
@@ -142,6 +143,10 @@ public function getIsTrue()
142143
}
143144
}
144145
}
146+
} elseif ($this->field && strpos($this->field, "shop.") !== false) {
147+
$field = str_replace("shop.", "", $this->field);
148+
149+
return $this->isTrue($this->value, $this->shopCmsContentElement->shopProduct->{$field});
145150
}
146151

147152
return true;

src/widgets/discount/DiscountConditionsWidget.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function getAvailableConditions()
7272
}
7373
}
7474

75+
$fields["Свойства магазина"] = [
76+
'shop.brand_id' => 'Бренд'
77+
];
78+
$this->allConditions['shop.brand_id'] = "Бренд";
79+
7580
$fields["Основные свойства"] = $elementOptions;
7681

7782
$props = CmsContentProperty::find()->all();
@@ -88,6 +93,9 @@ public function getAvailableConditions()
8893

8994
$fields["Свойства"] = $propsOptions;
9095

96+
97+
98+
9199
return $fields;
92100
}
93101
}

src/widgets/discount/views/discount-rule.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@
112112
],
113113
]);
114114
?>
115+
<? elseif (in_array(\yii\helpers\ArrayHelper::getValue($rule, 'field'), ['shop.brand_id'])) : ?>
116+
<?
117+
echo \skeeks\cms\backend\widgets\SelectModelDialogWidget::widget([
118+
'name' => 'value',
119+
'dialogRoute' => ["/shop/admin-shop-brand"],
120+
'modelClassName' => \skeeks\cms\shop\models\ShopBrand::class,
121+
'multiple' => true,
122+
'value' => \yii\helpers\ArrayHelper::getValue($rule, 'value'),
123+
'options' => [
124+
'data-no-update' => 'true',
125+
'class' => 'sx-value-element',
126+
],
127+
]);
128+
?>
115129
<? elseif (in_array(\yii\helpers\ArrayHelper::getValue($rule, 'field'), ['element.name', 'element.id'])) : ?>
116130
<?
117131
echo \yii\helpers\Html::textInput('value', \yii\helpers\ArrayHelper::getValue($rule, 'value'), [
@@ -123,7 +137,7 @@
123137
<? else : ?>
124138
<?
125139
$value = \yii\helpers\ArrayHelper::getValue($rule, 'value');
126-
if (is_string($value)) {
140+
if (is_string($value) || !$value) {
127141
echo \yii\helpers\Html::textInput('value', \yii\helpers\ArrayHelper::getValue($rule, 'value'), [
128142
'size' => 1,
129143
'class' => 'form-control sx-value-element',

0 commit comments

Comments
 (0)