← All changes
|
includes/Admin/Components/SettingPageComponents.php
+72
-26
1.8.5
→
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 |
| @@ -40,9 +41,9 @@ | ||
| 40 | 41 | |
| 41 | 42 | public static function renderPackageWeight() |
| 42 | 43 | { |
| 43 | 44 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::DEFAULT_PACKAGE_WEIGHT); |
| 44 | - echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::DEFAULT_PACKAGE_WEIGHT) . ']" min="10" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p" required>'; | |
| 45 | + echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::DEFAULT_PACKAGE_WEIGHT) . ']" min="1" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p" required>'; | |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | public static function renderDefaultPreparation() |
| 48 | 49 | { |
| @@ -49,8 +50,17 @@ | ||
| 49 | 50 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::DEFAULT_PREPARATION); |
| 50 | 51 | echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::DEFAULT_PREPARATION) . ']" min="0" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p" required>'; |
| 51 | 52 | } |
| 52 | 53 | |
| 54 | + public static function renderCapPreparationToCategoryMax() | |
| 55 | + { | |
| 56 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::CAP_PREPARATION_TO_CATEGORY_MAX); | |
| 57 | + echo '<select class="basalam-select basalam-select-center" name="sync_basalam_settings[' . esc_attr(SettingsConfig::CAP_PREPARATION_TO_CATEGORY_MAX) . ']">' | |
| 58 | + . '<option value="yes"' . selected($current_value, 'yes', false) . '>کاهش به حداکثر مجاز</option>' | |
| 59 | + . '<option value="no"' . selected($current_value, 'no', false) . '>عدم ارسال</option>' | |
| 60 | + . '</select>'; | |
| 61 | + } | |
| 62 | + | |
| 53 | 63 | public static function renderDefaultStockQuantity() |
| 54 | 64 | { |
| 55 | 65 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::DEFAULT_STOCK_QUANTITY); |
| 56 | 66 | echo '<input type="number" name="sync_basalam_settings[' . esc_attr(SettingsConfig::DEFAULT_STOCK_QUANTITY) . ']" min="0" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p" required>'; |
| @@ -71,24 +81,25 @@ | ||
| 71 | 81 | . '<option value="product"' . selected($current_value, 'product', false) . '>موجودی والد</option>' |
| 72 | 82 | . '</select>'; |
| 73 | 83 | } |
| 74 | 84 | |
| 75 | - public static function renderDefaultPercentage() | |
| 85 | + public static function renderPriceChange() | |
| 76 | 86 | { |
| 77 | - static $increasePriceControlIndex = 0; | |
| 78 | - $increasePriceControlIndex++; | |
| 87 | + static $priceChangeControlIndex = 0; | |
| 88 | + $priceChangeControlIndex++; | |
| 79 | 89 | |
| 80 | - $current_value = syncBasalamSettings()->getSettings(SettingsConfig::INCREASE_PRICE_VALUE); | |
| 81 | - $is_checked = ($current_value == -1) ? 'checked' : ''; | |
| 82 | - $input_disabled = ($current_value == -1) ? 'disabled' : ''; | |
| 83 | - $input_value = ($current_value == -1) ? '' : number_format($current_value); | |
| 84 | - $checkbox_id = 'toggle-percentage-' . $increasePriceControlIndex; | |
| 85 | - $hidden_input_id = 'final-value-' . $increasePriceControlIndex; | |
| 86 | - $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; | |
| 87 | 98 | |
| 88 | 99 | echo '<div class="basalam-input-container">'; |
| 89 | - 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>'; | |
| 90 | - 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>'; | |
| 91 | 102 | echo '</div>'; |
| 92 | 103 | |
| 93 | 104 | echo '<div class="basalam-flex-end-gap-4 basalam-margin-top-8">'; |
| 94 | 105 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| @@ -94,9 +105,9 @@ | ||
| 94 | 105 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| 95 | 106 | echo '<label class="basalam-font-10" for="' . esc_attr($checkbox_id) . '">کارمزد دستهبندی</label>'; |
| 96 | 107 | echo '</div>'; |
| 97 | 108 | |
| 98 | - 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) . '">'; | |
| 99 | 110 | } |
| 100 | 111 | |
| 101 | 112 | public static function renderDefaultRound() |
| 102 | 113 | { |
| @@ -110,9 +121,9 @@ | ||
| 110 | 121 | |
| 111 | 122 | public static function renderSyncProduct() |
| 112 | 123 | { |
| 113 | 124 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::SYNC_PRODUCT_FIELDS); |
| 114 | - 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">' | |
| 115 | 126 | . '<option value="all"' . selected($current_value, "all", false) . '>همه اطلاعات</option>' |
| 116 | 127 | . '<option value="price_stock"' . selected($current_value, "price_stock", false) . '>فقط قیمت و موجودی</option>' |
| 117 | 128 | . '<option value="custom"' . selected($current_value, "custom", false) . '>سفارشی</option>' |
| 118 | 129 | . '</select>'; |
| @@ -183,9 +194,9 @@ | ||
| 183 | 194 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::TASKS_PER_MINUTE); |
| 184 | 195 | $is_auto = syncBasalamSettings()->getSettings(SettingsConfig::TASKS_PER_MINUTE_AUTO) == 'true'; |
| 185 | 196 | $disabled = $is_auto ? 'disabled' : ''; |
| 186 | 197 | |
| 187 | - 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>'; | |
| 188 | 199 | } |
| 189 | 200 | |
| 190 | 201 | public static function renderTasksPerMinuteAutoToggle() |
| 191 | 202 | { |
| @@ -193,9 +204,9 @@ | ||
| 193 | 204 | $checked = $is_auto ? 'checked' : ''; |
| 194 | 205 | |
| 195 | 206 | echo '<label class="basalam-switch">'; |
| 196 | 207 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::TASKS_PER_MINUTE_AUTO) . ']" value="false">'; |
| 197 | - 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">'; | |
| 198 | 209 | echo '<span class="basalam-slider"></span>'; |
| 199 | 210 | echo '</label>'; |
| 200 | 211 | } |
| 201 | 212 | |
| @@ -240,9 +251,9 @@ | ||
| 240 | 251 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED); |
| 241 | 252 | $checked = $current_value == 'yes' ? 'checked' : ''; |
| 242 | 253 | |
| 243 | 254 | echo '<label class="basalam-switch">'; |
| 244 | - 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">'; | |
| 245 | 256 | echo '<span class="basalam-slider"></span>'; |
| 246 | 257 | echo '</label>'; |
| 247 | 258 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) . ']" value="no" class="basalam-attribute-suffix-hidden">'; |
| 248 | 259 | } |
| @@ -252,9 +263,9 @@ | ||
| 252 | 263 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY); |
| 253 | 264 | $is_enabled = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) == 'yes'; |
| 254 | 265 | $disabled = $is_enabled ? '' : 'disabled'; |
| 255 | 266 | |
| 256 | - 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) . '>'; | |
| 257 | 268 | } |
| 258 | 269 | |
| 259 | 270 | public static function renderMapOptionsProduct() |
| 260 | 271 | { |
| @@ -272,16 +283,24 @@ | ||
| 272 | 283 | |
| 273 | 284 | public static function renderSyncProductFields() |
| 274 | 285 | { |
| 275 | 286 | echo '<div>'; |
| 276 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_NAME, 'نام'); | |
| 277 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PHOTOS, 'عکس'); | |
| 278 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PRICE, 'قیمت'); | |
| 279 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_STOCK, 'موجودی'); | |
| 280 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); | |
| 281 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_DESCRIPTION, 'توضیحات'); | |
| 282 | - echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_ATTR, 'ویژگی ها'); | |
| 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. | |
| 283 | 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. | |
| 302 | + echo '</div>'; | |
| 284 | 303 | } |
| 285 | 304 | |
| 286 | 305 | private static function renderSingleCheckbox($field_key, $label) |
| 287 | 306 | { |
| @@ -379,6 +398,33 @@ | ||
| 379 | 398 | public static function renderCustomerSuffixName() |
| 380 | 399 | { |
| 381 | 400 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::CUSTOMER_SUFFIX_NAME); |
| 382 | 401 | echo '<input type="text" name="sync_basalam_settings[' . esc_attr(SettingsConfig::CUSTOMER_SUFFIX_NAME) . ']" value="' . esc_attr($current_value) . '" class="basalam-input basalam-p basalam-max-width-80 basalam-font-12" placeholder="مثال: عزیز">'; |
| 402 | + } | |
| 403 | + | |
| 404 | + public static function renderVideoSource() | |
| 405 | + { | |
| 406 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::VIDEO_SOURCE) ?: 'inherit'; | |
| 407 | + | |
| 408 | + echo '<select class="basalam-select basalam-select-center basalam-video-source-select" name="sync_basalam_settings[' . esc_attr(SettingsConfig::VIDEO_SOURCE) . ']">' | |
| 409 | + . '<option value="inherit"' . selected($current_value, 'inherit', false) . '>ارثبری از قالب یا افزونه</option>' | |
| 410 | + . '<option value="plugin_box"' . selected($current_value, 'plugin_box', false) . '>باکس اختصاصی افزونه (در صفحه محصول)</option>' | |
| 411 | + . '</select>'; | |
| 412 | + } | |
| 413 | + | |
| 414 | + public static function renderVideoInheritMode() | |
| 415 | + { | |
| 416 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::VIDEO_INHERIT_MODE) ?: 'auto'; | |
| 417 | + | |
| 418 | + echo '<select class="basalam-select basalam-select-center basalam-video-inherit-mode-select" name="sync_basalam_settings[' . esc_attr(SettingsConfig::VIDEO_INHERIT_MODE) . ']">' | |
| 419 | + . '<option value="auto"' . selected($current_value, 'auto', false) . '>تشخیص خودکار (Woodmart، Flatsome، YITH، ...)</option>' | |
| 420 | + . '<option value="manual"' . selected($current_value, 'manual', false) . '>وارد کردن دستی meta key</option>' | |
| 421 | + . '</select>'; | |
| 422 | + } | |
| 423 | + | |
| 424 | + public static function renderVideoMetaKey() | |
| 425 | + { | |
| 426 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::VIDEO_META_KEY); | |
| 427 | + | |
| 428 | + echo '<input type="text" name="sync_basalam_settings[' . esc_attr(SettingsConfig::VIDEO_META_KEY) . ']" value="' . esc_attr((string) $current_value) . '" class="basalam-input basalam-p basalam-video-meta-key basalam-max-width-80 basalam-font-12" placeholder="مثال: _woodmart_product_video">'; | |
| 383 | 429 | } |
| 384 | 430 | } |