← All changes
|
includes/Admin/Components/SettingPageComponents.php
+23
-14
1.10.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>'; |
| @@ -282,8 +284,9 @@ | ||
| 282 | 284 | public static function renderSyncProductFields() |
| 283 | 285 | { |
| 284 | 286 | echo '<div>'; |
| 285 | 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. | |
| 286 | 289 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PHOTOS, 'عکس'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 287 | 290 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PRICE, 'قیمت'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 288 | 291 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_STOCK, 'موجودی'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 289 | 292 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| @@ -289,8 +292,14 @@ | ||
| 289 | 292 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 290 | 293 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_DESCRIPTION, 'توضیحات'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 291 | 294 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_ATTR, 'ویژگی ها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 292 | 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) |