feat(Rule): add new rules
This commit is contained in:
@@ -25,8 +25,9 @@ class Sodino_Rules_List_Table extends WP_List_Table {
|
||||
return [
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'name' => __('عنوان قانون', 'sodino'),
|
||||
'condition_type' => __('شرط', 'sodino'),
|
||||
'action_value' => __('عملیات', 'sodino'),
|
||||
'conditions' => __('شرطها', 'sodino'),
|
||||
'actions_summary'=> __('عملیاتها', 'sodino'),
|
||||
'usage' => __('استفاده', 'sodino'),
|
||||
'enabled' => __('وضعیت', 'sodino'),
|
||||
'actions' => __('عملیات', 'sodino'),
|
||||
];
|
||||
@@ -68,31 +69,64 @@ class Sodino_Rules_List_Table extends WP_List_Table {
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function column_condition_type($item) {
|
||||
$labels = [
|
||||
private function conditionLabels() {
|
||||
return [
|
||||
'user_type' => __('نوع کاربر', 'sodino'),
|
||||
'product_category' => __('دستهبندی محصول', 'sodino'),
|
||||
'exclude_product_category' => __('بهجز دستهبندی', 'sodino'),
|
||||
'product_tag' => __('برچسب محصول', 'sodino'),
|
||||
'product_ids' => __('محصولات خاص', 'sodino'),
|
||||
'exclude_product_ids' => __('بهجز محصولات', 'sodino'),
|
||||
'cart_total_min' => __('حداقل مبلغ سبد', 'sodino'),
|
||||
'cart_total_max' => __('حداکثر مبلغ سبد', 'sodino'),
|
||||
'cart_item_count_min' => __('حداقل تعداد سبد', 'sodino'),
|
||||
'cart_item_count_max' => __('حداکثر تعداد سبد', 'sodino'),
|
||||
'cart_contains_product' => __('سبد شامل محصول', 'sodino'),
|
||||
'cart_contains_category' => __('سبد شامل دستهبندی', 'sodino'),
|
||||
'customer_order_count_min' => __('حداقل سفارش مشتری', 'sodino'),
|
||||
'customer_order_count_max' => __('حداکثر سفارش مشتری', 'sodino'),
|
||||
'day_of_week' => __('روز هفته', 'sodino'),
|
||||
];
|
||||
|
||||
$type = $labels[$item->condition_type] ?? $item->condition_type;
|
||||
return esc_html(sprintf('%s: %s', $type, $item->condition_value));
|
||||
}
|
||||
|
||||
public function column_action_value($item) {
|
||||
public function column_conditions($item) {
|
||||
$labels = [
|
||||
];
|
||||
$labels = $this->conditionLabels();
|
||||
$parts = [];
|
||||
foreach ((array) $item->conditions as $condition) {
|
||||
$type = $condition['type'] ?? '';
|
||||
$value = $condition['value'] ?? '';
|
||||
$parts[] = esc_html(sprintf('%s: %s', $labels[$type] ?? $type, is_array($value) ? implode(',', $value) : $value));
|
||||
}
|
||||
return $parts ? implode('<br>', $parts) : esc_html__('بدون شرط', 'sodino');
|
||||
}
|
||||
|
||||
public function column_actions_summary($item) {
|
||||
$labels = [
|
||||
'discount_percent' => __('درصد تخفیف', 'sodino'),
|
||||
'discount_fixed' => __('تخفیف ثابت', 'sodino'),
|
||||
'set_price' => __('قیمت ثابت', 'sodino'),
|
||||
'increase_percent' => __('افزایش درصدی', 'sodino'),
|
||||
'increase_fixed' => __('افزایش ثابت', 'sodino'),
|
||||
'free_shipping' => __('ارسال رایگان', 'sodino'),
|
||||
];
|
||||
|
||||
$type = $labels[$item->action_type] ?? $item->action_type;
|
||||
return esc_html(sprintf('%s: %s', $type, $item->action_value));
|
||||
$parts = [];
|
||||
foreach ((array) $item->actions as $action) {
|
||||
$type = $action['type'] ?? '';
|
||||
$value = $action['value'] ?? 0;
|
||||
$parts[] = esc_html(sprintf('%s: %s', $labels[$type] ?? $type, $type === 'free_shipping' ? '-' : $value));
|
||||
}
|
||||
return $parts ? implode('<br>', $parts) : esc_html__('بدون عملیات', 'sodino');
|
||||
}
|
||||
|
||||
public function column_usage($item) {
|
||||
$limit = (int) $item->usage_limit;
|
||||
if ($limit <= 0) {
|
||||
return esc_html(sprintf('%s / %s', number_format_i18n($item->usage_count), __('نامحدود', 'sodino')));
|
||||
}
|
||||
return esc_html(sprintf('%s / %s', number_format_i18n($item->usage_count), number_format_i18n($limit)));
|
||||
}
|
||||
|
||||
public function column_enabled($item) {
|
||||
@@ -102,8 +136,9 @@ class Sodino_Rules_List_Table extends WP_List_Table {
|
||||
public function column_default($item, $column_name) {
|
||||
switch ($column_name) {
|
||||
case 'name':
|
||||
case 'condition_type':
|
||||
case 'action_value':
|
||||
case 'conditions':
|
||||
case 'actions_summary':
|
||||
case 'usage':
|
||||
case 'enabled':
|
||||
case 'actions':
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user