← All changes
|
includes/Admin/Components/SettingPageComponents.php
+35
-26
1.9.0
→
1.10.19
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Admin\Components; |
| 4 | 4 | |
| 5 | 5 | use SyncBasalam\Admin\Settings\SettingsConfig; |
| 6 | +use SyncBasalam\Utilities\PriceAdjustment; | |
| 6 | 7 | |
| 7 | 8 | defined('ABSPATH') || exit; |
| 8 | 9 | |
| 9 | 10 | class SettingPageComponents |
| @@ -80,24 +81,25 @@ | ||
| 80 | 81 | . '<option value="product"' . selected($current_value, 'product', false) . '>موجودی والد</option>' |
| 81 | 82 | . '</select>'; |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | - public static function renderDefaultPercentage() | |
| 85 | + public static function renderPriceChange() | |
| 85 | 86 | { |
| 86 | - static $increasePriceControlIndex = 0; | |
| 87 | - $increasePriceControlIndex++; | |
| 87 | + static $priceChangeControlIndex = 0; | |
| 88 | + $priceChangeControlIndex++; | |
| 88 | 89 | |
| 89 | - $current_value = syncBasalamSettings()->getSettings(SettingsConfig::INCREASE_PRICE_VALUE); | |
| 90 | - $is_checked = ($current_value == -1) ? 'checked' : ''; | |
| 91 | - $input_disabled = ($current_value == -1) ? 'disabled' : ''; | |
| 92 | - $input_value = ($current_value == -1) ? '' : number_format($current_value); | |
| 93 | - $checkbox_id = 'toggle-percentage-' . $increasePriceControlIndex; | |
| 94 | - $hidden_input_id = 'final-value-' . $increasePriceControlIndex; | |
| 95 | - $text_input_id = 'increase-price-input-' . $increasePriceControlIndex; | |
| 90 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRICE_CHANGE_VALUE); | |
| 91 | + $is_commission = PriceAdjustment::isCommission($current_value); | |
| 92 | + $is_checked = $is_commission ? 'checked' : ''; | |
| 93 | + $input_disabled = $is_commission ? 'disabled' : ''; | |
| 94 | + $input_value = $is_commission || !is_numeric($current_value) ? '' : number_format((int) $current_value); | |
| 95 | + $checkbox_id = 'toggle-percentage-' . $priceChangeControlIndex; | |
| 96 | + $hidden_input_id = 'price-change-value-' . $priceChangeControlIndex; | |
| 97 | + $text_input_id = 'price-change-input-' . $priceChangeControlIndex; | |
| 96 | 98 | |
| 97 | 99 | echo '<div class="basalam-input-container">'; |
| 98 | - echo '<input type="text" id="' . esc_attr($text_input_id) . '" data-role="increase-price-input" name="sync_basalam_settings[' . esc_attr(SettingsConfig::INCREASE_PRICE_VALUE) . ']" min="0" value="' . esc_attr($input_value) . '" class="basalam-input basalam-p percentage-input" ' . esc_attr($input_disabled) . ' required>'; | |
| 99 | - echo '<span class="percentage-unit basalam-p basalam-min-width-0 basalam-font-13">' . ($current_value <= 100 ? 'درصد' : 'تومان') . '</span>'; | |
| 100 | + echo '<input type="text" id="' . esc_attr($text_input_id) . '" data-role="price-change-input" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRICE_CHANGE_VALUE) . ']" value="' . esc_attr($input_value) . '" class="basalam-input basalam-p percentage-input" inputmode="text" autocomplete="off" ' . esc_attr($input_disabled) . ' required>'; | |
| 101 | + echo '<span class="percentage-unit basalam-p basalam-min-width-0 basalam-font-13">' . esc_html(PriceAdjustment::unitLabel($current_value)) . '</span>'; | |
| 100 | 102 | echo '</div>'; |
| 101 | 103 | |
| 102 | 104 | echo '<div class="basalam-flex-end-gap-4 basalam-margin-top-8">'; |
| 103 | 105 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| @@ -103,9 +105,9 @@ | ||
| 103 | 105 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| 104 | 106 | echo '<label class="basalam-font-10" for="' . esc_attr($checkbox_id) . '">کارمزد دستهبندی</label>'; |
| 105 | 107 | echo '</div>'; |
| 106 | 108 | |
| 107 | - echo '<input type="hidden" id="' . esc_attr($hidden_input_id) . '" data-role="increase-price-hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::INCREASE_PRICE_VALUE) . ']" value="' . esc_attr($current_value) . '">'; | |
| 109 | + echo '<input type="hidden" id="' . esc_attr($hidden_input_id) . '" data-role="price-change-hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRICE_CHANGE_VALUE) . ']" value="' . esc_attr($current_value) . '">'; | |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | public static function renderDefaultRound() |
| 111 | 113 | { |
| @@ -119,9 +121,9 @@ | ||
| 119 | 121 | |
| 120 | 122 | public static function renderSyncProduct() |
| 121 | 123 | { |
| 122 | 124 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::SYNC_PRODUCT_FIELDS); |
| 123 | - echo '<select class="basalam-select basalam-select-center" name="sync_basalam_settings[' . esc_attr(SettingsConfig::SYNC_PRODUCT_FIELDS) . ']" onchange="BasalamToggleCustomFields(this.value)" id="basalam-sync-type">' | |
| 125 | + echo '<select class="basalam-select basalam-select-center" name="sync_basalam_settings[' . esc_attr(SettingsConfig::SYNC_PRODUCT_FIELDS) . ']" id="basalam-sync-type">' | |
| 124 | 126 | . '<option value="all"' . selected($current_value, "all", false) . '>همه اطلاعات</option>' |
| 125 | 127 | . '<option value="price_stock"' . selected($current_value, "price_stock", false) . '>فقط قیمت و موجودی</option>' |
| 126 | 128 | . '<option value="custom"' . selected($current_value, "custom", false) . '>سفارشی</option>' |
| 127 | 129 | . '</select>'; |
| @@ -192,9 +194,9 @@ | ||
| 192 | 194 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::TASKS_PER_MINUTE); |
| 193 | 195 | $is_auto = syncBasalamSettings()->getSettings(SettingsConfig::TASKS_PER_MINUTE_AUTO) == 'true'; |
| 194 | 196 | $disabled = $is_auto ? 'disabled' : ''; |
| 195 | 197 | |
| 196 | - echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE) . ']" min="1" max="60" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p basalam-tasks-manual-input" ' . $disabled . ' required>'; | |
| 198 | + echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE) . ']" min="1" max="60" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p basalam-tasks-manual-input" ' . esc_attr($disabled) . ' required>'; | |
| 197 | 199 | } |
| 198 | 200 | |
| 199 | 201 | public static function renderTasksPerMinuteAutoToggle() |
| 200 | 202 | { |
| @@ -202,9 +204,9 @@ | ||
| 202 | 204 | $checked = $is_auto ? 'checked' : ''; |
| 203 | 205 | |
| 204 | 206 | echo '<label class="basalam-switch">'; |
| 205 | 207 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE_AUTO) . ']" value="false">'; |
| 206 | - echo '<input type="checkbox" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE_AUTO) . ']" value="true" ' . $checked . ' class="basalam-tasks-auto-toggle">'; | |
| 208 | + echo '<input type="checkbox" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE_AUTO) . ']" value="true" ' . esc_attr($checked) . ' class="basalam-tasks-auto-toggle">'; | |
| 207 | 209 | echo '<span class="basalam-slider"></span>'; |
| 208 | 210 | echo '</label>'; |
| 209 | 211 | } |
| 210 | 212 | |
| @@ -249,9 +251,9 @@ | ||
| 249 | 251 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED); |
| 250 | 252 | $checked = $current_value == 'yes' ? 'checked' : ''; |
| 251 | 253 | |
| 252 | 254 | echo '<label class="basalam-switch">'; |
| 253 | - echo '<input type="checkbox" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) . ']" value="yes" ' . $checked . ' class="basalam-attribute-suffix-toggle">'; | |
| 255 | + echo '<input type="checkbox" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) . ']" value="yes" ' . esc_attr($checked) . ' class="basalam-attribute-suffix-toggle">'; | |
| 254 | 256 | echo '<span class="basalam-slider"></span>'; |
| 255 | 257 | echo '</label>'; |
| 256 | 258 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) . ']" value="no" class="basalam-attribute-suffix-hidden">'; |
| 257 | 259 | } |
| @@ -261,9 +263,9 @@ | ||
| 261 | 263 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY); |
| 262 | 264 | $is_enabled = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) == 'yes'; |
| 263 | 265 | $disabled = $is_enabled ? '' : 'disabled'; |
| 264 | 266 | |
| 265 | - echo '<input type="text" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY) . ']" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p basalam-attribute-suffix-priority basalam-max-width-80 basalam-font-12" placeholder="مثال: ناشر" ' . $disabled . '>'; | |
| 267 | + echo '<input type="text" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY) . ']" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p basalam-attribute-suffix-priority basalam-max-width-80 basalam-font-12" placeholder="مثال: ناشر" ' . esc_attr($disabled) . '>'; | |
| 266 | 268 | } |
| 267 | 269 | |
| 268 | 270 | public static function renderMapOptionsProduct() |
| 269 | 271 | { |
| @@ -281,16 +283,23 @@ | ||
| 281 | 283 | |
| 282 | 284 | public static function renderSyncProductFields() |
| 283 | 285 | { |
| 284 | 286 | echo '<div>'; |
| 285 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_NAME, 'نام'); | |
| 286 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PHOTOS, 'عکس'); | |
| 287 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PRICE, 'قیمت'); | |
| 288 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_STOCK, 'موجودی'); | |
| 289 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); | |
| 290 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_DESCRIPTION, 'توضیحات'); | |
| 291 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_ATTR, 'ویژگی ها'); | |
| 292 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VIDEO, 'ویدیو'); | |
| 287 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_NAME, 'نام'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 288 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_SKU, 'کد محصول (SKU)'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 289 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PHOTOS, 'عکس'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 290 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PRICE, 'قیمت'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 291 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_STOCK, 'موجودی'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 292 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 293 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_DESCRIPTION, 'توضیحات'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 294 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_ATTR, 'ویژگی ها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 295 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VIDEO, 'ویدیو'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 296 | + echo '</div>'; | |
| 297 | + | |
| 298 | + echo '<div class="basalam-margin-top-25-bottom-10">'; | |
| 299 | + echo '<label class="basalam-label basalam-p">متغیرها</label><br>'; | |
| 300 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_PRICE, 'قیمت متغیرها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 301 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_STOCK, 'موجودی متغیرها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 293 | 302 | echo '</div>'; |
| 294 | 303 | } |
| 295 | 304 | |
| 296 | 305 | private static function renderSingleCheckbox($field_key, $label) |