← All changes
|
includes/Admin/Components/SettingPageComponents.php
+41
-15
1.10.2
→
1.10.28
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 |
| @@ -19,8 +20,25 @@ | ||
| 19 | 20 | $value = syncBasalamSettings()->getSettings(SettingsConfig::SYNC_STATUS_PRODUCT) == true ? false : true; |
| 20 | 21 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::SYNC_STATUS_PRODUCT) . ']" value="' . esc_attr($value) . '">'; |
| 21 | 22 | } |
| 22 | 23 | |
| 24 | + public static function renderProductSyncOperations() | |
| 25 | + { | |
| 26 | + $operations = [ | |
| 27 | + SettingsConfig::SYNC_STATUS_PRODUCT_CREATE => 'ایجاد محصول در باسلام', | |
| 28 | + SettingsConfig::SYNC_STATUS_PRODUCT_UPDATE => 'بروزرسانی محصول در باسلام', | |
| 29 | + ]; | |
| 30 | + | |
| 31 | + foreach ($operations as $setting => $label) { | |
| 32 | + $enabled = syncBasalamSettings()->getSettings($setting); | |
| 33 | + echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr($setting) . ']" value="0">'; | |
| 34 | + echo '<label class="basalam-product-sync-option">'; | |
| 35 | + echo '<input type="checkbox" name="sync_basalam_settings[' . esc_attr($setting) . ']" value="1"' . checked($enabled, true, false) . '>'; | |
| 36 | + echo '<span><strong>' . esc_html($label) . '</strong></span>'; | |
| 37 | + echo '</label>'; | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 23 | 41 | public static function syncStatusOrder() |
| 24 | 42 | { |
| 25 | 43 | $value = syncBasalamSettings()->getSettings(SettingsConfig::SYNC_STATUS_ORDER) == true ? false : true; |
| 26 | 44 | echo '<input type="hidden" name="sync_basalam_settings[' . esc_attr(SettingsConfig::SYNC_STATUS_ORDER) . ']" value="' . esc_attr($value) . '">'; |
| @@ -80,24 +98,25 @@ | ||
| 80 | 98 | . '<option value="product"' . selected($current_value, 'product', false) . '>موجودی والد</option>' |
| 81 | 99 | . '</select>'; |
| 82 | 100 | } |
| 83 | 101 | |
| 84 | - public static function renderDefaultPercentage() | |
| 102 | + public static function renderPriceChange() | |
| 85 | 103 | { |
| 86 | - static $increasePriceControlIndex = 0; | |
| 87 | - $increasePriceControlIndex++; | |
| 104 | + static $priceChangeControlIndex = 0; | |
| 105 | + $priceChangeControlIndex++; | |
| 88 | 106 | |
| 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; | |
| 107 | + $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRICE_CHANGE_VALUE); | |
| 108 | + $is_commission = PriceAdjustment::isCommission($current_value); | |
| 109 | + $is_checked = $is_commission ? 'checked' : ''; | |
| 110 | + $input_disabled = $is_commission ? 'disabled' : ''; | |
| 111 | + $input_value = $is_commission || !is_numeric($current_value) ? '' : number_format((int) $current_value); | |
| 112 | + $checkbox_id = 'toggle-percentage-' . $priceChangeControlIndex; | |
| 113 | + $hidden_input_id = 'price-change-value-' . $priceChangeControlIndex; | |
| 114 | + $text_input_id = 'price-change-input-' . $priceChangeControlIndex; | |
| 96 | 115 | |
| 97 | 116 | 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>'; | |
| 117 | + 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>'; | |
| 118 | + echo '<span class="percentage-unit basalam-p basalam-min-width-0 basalam-font-13">' . esc_html(PriceAdjustment::unitLabel($current_value)) . '</span>'; | |
| 100 | 119 | echo '</div>'; |
| 101 | 120 | |
| 102 | 121 | echo '<div class="basalam-flex-end-gap-4 basalam-margin-top-8">'; |
| 103 | 122 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| @@ -103,9 +122,9 @@ | ||
| 103 | 122 | echo '<input type="checkbox" id="' . esc_attr($checkbox_id) . '" class="toggle-percentage" name="toggle_percentage" ' . esc_attr($is_checked) . '>'; |
| 104 | 123 | echo '<label class="basalam-font-10" for="' . esc_attr($checkbox_id) . '">کارمزد دستهبندی</label>'; |
| 105 | 124 | echo '</div>'; |
| 106 | 125 | |
| 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) . '">'; | |
| 126 | + 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 | 127 | } |
| 109 | 128 | |
| 110 | 129 | public static function renderDefaultRound() |
| 111 | 130 | { |
| @@ -119,9 +138,9 @@ | ||
| 119 | 138 | |
| 120 | 139 | public static function renderSyncProduct() |
| 121 | 140 | { |
| 122 | 141 | $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">' | |
| 142 | + echo '<select class="basalam-select basalam-select-center" name="sync_basalam_settings[' . esc_attr(SettingsConfig::SYNC_PRODUCT_FIELDS) . ']" id="basalam-sync-type">' | |
| 124 | 143 | . '<option value="all"' . selected($current_value, "all", false) . '>همه اطلاعات</option>' |
| 125 | 144 | . '<option value="price_stock"' . selected($current_value, "price_stock", false) . '>فقط قیمت و موجودی</option>' |
| 126 | 145 | . '<option value="custom"' . selected($current_value, "custom", false) . '>سفارشی</option>' |
| 127 | 146 | . '</select>'; |
| @@ -261,9 +280,9 @@ | ||
| 261 | 280 | $current_value = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY); |
| 262 | 281 | $is_enabled = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED) == 'yes'; |
| 263 | 282 | $disabled = $is_enabled ? '' : 'disabled'; |
| 264 | 283 | |
| 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="مثال: ناشر" ' . esc_attr($disabled) . '>'; | |
| 284 | + 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 | 285 | } |
| 267 | 286 | |
| 268 | 287 | public static function renderMapOptionsProduct() |
| 269 | 288 | { |
| @@ -282,8 +301,9 @@ | ||
| 282 | 301 | public static function renderSyncProductFields() |
| 283 | 302 | { |
| 284 | 303 | echo '<div>'; |
| 285 | 304 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_NAME, 'نام'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 305 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_SKU, 'کد محصول (SKU)'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 286 | 306 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PHOTOS, 'عکس'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 287 | 307 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_PRICE, 'قیمت'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 288 | 308 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_STOCK, 'موجودی'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 289 | 309 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| @@ -289,8 +309,14 @@ | ||
| 289 | 309 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_WEIGHT, 'وزن'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 290 | 310 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_DESCRIPTION, 'توضیحات'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 291 | 311 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_ATTR, 'ویژگی ها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 292 | 312 | echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VIDEO, 'ویدیو'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. |
| 313 | + echo '</div>'; | |
| 314 | + | |
| 315 | + echo '<div class="basalam-margin-top-25-bottom-10">'; | |
| 316 | + echo '<label class="basalam-label basalam-p">متغیرها</label><br>'; | |
| 317 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_PRICE, 'قیمت متغیرها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 318 | + echo self::renderSingleCheckbox(SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_STOCK, 'موجودی متغیرها'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML is escaped inside the component method. | |
| 293 | 319 | echo '</div>'; |
| 294 | 320 | } |
| 295 | 321 | |
| 296 | 322 | private static function renderSingleCheckbox($field_key, $label) |