Changeset 3330622
- Timestamp:
- 07/19/2025 12:25:24 PM (9 months ago)
- Location:
- pasazh/trunk
- Files:
-
- 2 edited
-
pasazh.php (modified) (24 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pasazh/trunk/pasazh.php
r3212810 r3330622 5 5 Plugin Name: Pasazh 6 6 Plugin URI: https://epasazh.com 7 Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید.8 Version: 1.1 87 Description: Using this plugin, you can connect your store to Pasazh. Just activate it, then go to your admin panel on the Pasazh website and complete the remaining steps to establish the connection. 8 Version: 1.19 9 9 Author: aliparsa 10 10 Author URI: https://profiles.wordpress.org/aliparsa/ … … 15 15 */ 16 16 17 const PASAZHAPI_papi_version = "1.18"; 18 17 const PASAZHAPI_papi_version = "1.19"; 19 18 add_action('rest_api_init', function () { 20 19 register_rest_route('papi', '/products', array( … … 24 23 )); 25 24 }); 26 27 25 add_action('rest_api_init', function () { 28 26 register_rest_route('papi', '/products/count', array( … … 32 30 )); 33 31 }); 34 35 32 add_action('rest_api_init', function () { 36 33 register_rest_route('papi', '/info', array( … … 40 37 )); 41 38 }); 42 43 //add_action('woocommerce_new_product', 'PASAZHAPI_sync_product', 10, 1);44 //add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1);45 39 add_action('deleted_post', 'PASAZHAPI_delete_product'); 46 40 add_action('save_post', 'PASAZHAPI_sync_product'); 47 41 48 49 42 //region api functions 50 43 51 44 function PASAZHAPI_info($product_id) 52 45 { 53 54 46 $logo_url = null; 55 47 $attachment_image_src = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full'); … … 64 56 ]; 65 57 return new WP_REST_Response($response, 200); 66 67 58 } 68 59 … … 73 64 function PASAZHAPI_products($data) 74 65 { 75 76 66 $base64 = $data->get_params()["query"]; 77 67 $json = base64_decode($base64); … … 83 73 $pasazh_products = []; 84 74 $items = wc_get_products($query); 85 foreach ($items as $product) { 86 $product->description = apply_filters( 'the_content', $product->description ); 87 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 88 $pasazh_products[] = $pasazh_product; 75 76 if(is_int($items[0])){ 77 foreach ($items as $productId) { 78 $pasazh_products[] = $productId; 79 } 80 }else{ 81 foreach ($items as $product) { 82 $product->description = apply_filters( 'the_content', $product->description ); 83 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 84 $pasazh_products[] = $pasazh_product; 85 } 89 86 } 90 87 … … 95 92 $response["products"] = $pasazh_products; 96 93 97 98 94 return new WP_REST_Response($response, 200); 99 95 } … … 101 97 function PASAZHAPI_delete_product($product_id) 102 98 { 103 104 105 99 try { 106 100 if (get_transient("papi_product_id") == $product_id) return; … … 108 102 109 103 $post = get_post($product_id); 110 111 112 if (!$post) 113 return; 104 if (!$post) return; 114 105 115 106 $post_type = $post->post_type; 116 if ($post_type != "product") 117 return; 118 107 if ($post_type != "product") return; 119 108 120 109 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-deleted/$product_id", [ … … 123 112 ] 124 113 ]); 125 126 127 } catch (Exception $e) { 128 129 } 130 114 } catch (Exception $e) {} 131 115 } 132 116 133 117 function PASAZHAPI_sync_product($product_id) 134 118 { 135 136 137 119 try { 138 120 if (get_transient("papi_product_id") == $product_id) return; … … 140 122 141 123 $post = get_post($product_id); 142 143 144 if (!$post) 145 return; 124 if (!$post) return; 146 125 147 126 $post_type = $post->post_type; 148 if ($post_type != "product") 149 return; 150 127 if ($post_type != "product") return; 128 129 $product = wc_get_product($product_id); 130 $data = $product->get_data(); 131 $data['type'] = $product->get_type(); 132 if ($product->is_type('variable')) { 133 $data['variations'] = $product->get_available_variations(); 134 } 151 135 152 136 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-updated/$product_id", [ … … 155 139 ] 156 140 ]); 157 158 159 } catch (Exception $e) { 160 161 } 162 141 } catch (Exception $e) {} 163 142 } 164 143 … … 168 147 169 148 function get_readable_product_attributes($product_id) { 170 // دریافت شیء محصول171 149 $product = wc_get_product($product_id); 172 173 150 if (!$product) { 174 151 return []; … … 187 164 188 165 if ($attribute->is_taxonomy()) { 189 // اگر ویژگی نوع تاکسونومی باشد190 $taxonomy = $attribute->get_name(); // مانندpa_color191 $attribute_data['name'] = wc_attribute_label($taxonomy); // دریافت نام ویژگی192 $terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'names']); // مقادیر ویژگی166 // If the attribute is a taxonomy type 167 $taxonomy = $attribute->get_name(); // e.g., pa_color 168 $attribute_data['name'] = wc_attribute_label($taxonomy); // Get attribute label 169 $terms = wc_get_product_terms($product_id, $taxonomy, ['fields' => 'names']); // Get attribute values 193 170 $attribute_data['values'] = $terms; 194 171 } else { 195 // اگر ویژگی نوع دلخواه باشد196 $attribute_data['name'] = $attribute->get_name(); // نام ویژگی197 $attribute_data['values'] = $attribute->get_options(); // مقادیر ویژگی172 // If the attribute is a custom (non-taxonomy) type 173 $attribute_data['name'] = $attribute->get_name(); // Get attribute name 174 $attribute_data['values'] = $attribute->get_options(); // Get attribute values 198 175 } 199 176 … … 215 192 function PASAZHAPI_get_pasazh_product_from_wc_product($product) 216 193 { 217 218 194 $product_status = $product->get_status(); 219 195 … … 222 198 $pasazh_product->setName($product->get_name()); 223 199 $pasazh_product->setUrl(get_permalink($product->get_id())); 224 225 200 226 201 $attributes = get_readable_product_attributes($product->get_id()); … … 246 221 $pasazh_product->setDescription($description); 247 222 248 249 223 // region technical desc 250 224 $technical_description = ""; … … 252 226 253 227 foreach ($attrs as $attr) { 254 255 228 if ($attr["visible"] != true) continue; 256 229 if ($attr["variation"] == true) continue; … … 261 234 $options_text = ""; 262 235 foreach ($data["options"] as $option) { 263 264 236 if (strlen($options_text) > 0) 265 237 $options_text .= " | "; 266 238 $options_text .= $option; 267 239 } 268 269 240 $technical_description .= $options_text; 270 241 } … … 277 248 278 249 if ($product->is_type('variable')) { 279 280 250 $specification_arr = []; 281 282 251 foreach ($product->get_available_variations() as $variation) { 283 284 252 $is_in_stock = isset($variation['is_in_stock']) && $variation['is_in_stock'] == 1; 285 286 253 $specification_object = new \stdClass(); 287 254 $specification_object->name = ""; … … 293 260 $specification_object->is_in_stock = $is_in_stock; 294 261 $specification_arr [] = $specification_object; 295 296 } 297 262 } 298 263 299 264 if (sizeof($specification_arr) > 0) { 300 265 $pasazh_product->setSpecifications($specification_arr); 301 266 } 302 303 } 304 267 } 305 268 306 269 //region set quantity … … 361 324 } else { 362 325 $pasazh_product->setVisibilityStatus(0); 363 364 326 } 365 327 -
pasazh/trunk/readme.txt
r3212810 r3330622 5 5 Requires at least: 5.0.3 6 6 Tested up to: 5.9.3 7 Stable tag: 1.1 87 Stable tag: 1.19 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 23 23 == Screenshots == 24 24 == Changelog == 25 = 1.1 8=25 = 1.19 = 26 26 * First release 27 27 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.