PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.6
ووسلام – همگام سازی ووکامرس و باسلام v1.8.6
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Admin / Product / elements / ProductList / BulkEdit.php

BulkEdit.php in ووسلام – همگام سازی ووکامرس و باسلام 1.8.6, at includes/Admin/Product/elements/ProductList/BulkEdit.php

130 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\Product\elements\ProductList;
4
5 use SyncBasalam\Admin\Product\elements\SingleProduct\PriceIncreaseField;
6 use SyncBasalam\Admin\Product\Utils\ProductUnits;
7
8 defined('ABSPATH') || exit;
9
10 class BulkEdit
11 {
12 public const TYPE_META_KEY = '_sync_basalam_is_product_type_checkbox';
13 public const UNIT_META_KEY = '_sync_basalam_product_unit';
14 public const QUANTITY_META_KEY = '_sync_basalam_product_value';
15 public const WHOLESALE_META_KEY = '_sync_basalam_is_wholesale';
16
17 public function renderFields(string $columnName, string $postType): void
18 {
19 if ($postType !== 'product' || $columnName !== 'name') {
20 return;
21 }
22
23 $units = ProductUnits::all();
24
25 require __DIR__ . '/views/BulkEditFields.php';
26 }
27
28 public function save(int $postId, \WP_Post $post): void
29 {
30 if ($post->post_type !== 'product') {
31 return;
32 }
33
34 if (
35 !isset($_REQUEST['_inline_edit'])
36 || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_inline_edit'])), 'inlineeditnonce')
37 ) {
38 return;
39 }
40
41 if (!current_user_can('edit_post', $postId)) {
42 return;
43 }
44
45 if (!isset($_REQUEST['sync_basalam_bulk_product_type_action']) && !isset($_REQUEST['sync_basalam_bulk_increase_action'])) {
46 return;
47 }
48
49 $this->saveProductType($postId);
50 $this->saveWholesale($postId);
51 $this->saveIncrease($postId);
52 }
53
54 private function saveProductType(int $postId): void
55 {
56 $action = isset($_REQUEST['sync_basalam_bulk_product_type_action'])
57 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_type_action']))
58 : 'keep';
59
60 if ($action === 'keep') {
61 return;
62 }
63
64 if ($action === 'yes') {
65 update_post_meta($postId, self::TYPE_META_KEY, 'yes');
66
67 $unit = isset($_REQUEST['sync_basalam_bulk_product_unit'])
68 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_unit']))
69 : '6304';
70 $quantity = isset($_REQUEST['sync_basalam_bulk_product_value'])
71 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_value']))
72 : '1';
73
74 $unitValue = is_numeric($unit) ? (string) intval($unit) : '6304';
75 $quantityValue = (is_numeric($quantity) && intval($quantity) > 0) ? (string) intval($quantity) : '1';
76
77 update_post_meta($postId, self::UNIT_META_KEY, $unitValue);
78 update_post_meta($postId, self::QUANTITY_META_KEY, $quantityValue);
79
80 return;
81 }
82
83 update_post_meta($postId, self::TYPE_META_KEY, 'no');
84 delete_post_meta($postId, self::UNIT_META_KEY);
85 delete_post_meta($postId, self::QUANTITY_META_KEY);
86 }
87
88 private function saveWholesale(int $postId): void
89 {
90 $action = isset($_REQUEST['sync_basalam_bulk_wholesale_action'])
91 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_wholesale_action']))
92 : 'keep';
93
94 if ($action === 'keep') {
95 return;
96 }
97
98 $wholesaleValue = $action === 'yes' ? 'yes' : 'no';
99 update_post_meta($postId, self::WHOLESALE_META_KEY, $wholesaleValue);
100 }
101
102 private function saveIncrease(int $postId): void
103 {
104 $action = isset($_REQUEST['sync_basalam_bulk_increase_action'])
105 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_increase_action']))
106 : 'keep';
107
108 if ($action === 'keep') {
109 return;
110 }
111
112 if ($action === 'clear') {
113 delete_post_meta($postId, PriceIncreaseField::META_KEY);
114
115 return;
116 }
117
118 $value = isset($_REQUEST['sync_basalam_bulk_increase_value'])
119 ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_increase_value']))
120 : '';
121
122 if ($value === '' || !is_numeric($value)) {
123 return;
124 }
125
126 $increaseValue = (string) intval($value);
127 update_post_meta($postId, PriceIncreaseField::META_KEY, $increaseValue);
128 }
129 }
130