Changeset 2841766
- Timestamp:
- 12/31/2022 10:30:55 AM (3 years ago)
- Location:
- pasazh/trunk
- Files:
-
- 3 edited
-
PASAZHAPIPasazhProduct.php (modified) (1 diff)
-
pasazh.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pasazh/trunk/PASAZHAPIPasazhProduct.php
r2840280 r2841766 27 27 public $url; 28 28 public $commodity_id; 29 // public $guarantee; 29 30 30 31 31 32 /** -
pasazh/trunk/pasazh.php
r2840342 r2841766 6 6 Plugin URI: https://epasazh.com 7 7 Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید. 8 Version: 1. 78 Version: 1.8 9 9 Author: aliparsa 10 10 Author URI: https://profiles.wordpress.org/aliparsa/ … … 31 31 }); 32 32 33 add_action('woocommerce_new_product', 'PASAZHAPI_sync_product', 10, 1); 34 35 add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1); 36 37 //region add two webhook for detect delete product 38 add_action('before_delete_post', 'PASAZHAPI_sync_product'); 33 //add_action('woocommerce_new_product', 'PASAZHAPI_sync_product', 10, 1); 34 //add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1); 35 add_action('deleted_post', 'PASAZHAPI_delete_product'); 39 36 add_action('save_post', 'PASAZHAPI_sync_product'); 40 //endregion 41 42 43 //function wpse_110037_new_posts($post_id){ 44 // $WC_Product = wc_get_product( $post_id); 45 // 46 // if($WC_Product->status == "trash"){ 47 // 48 // } 49 //} 37 50 38 51 39 //region api functions … … 66 54 { 67 55 68 69 56 $base64 = $data->get_params()["query"]; 70 57 $json = base64_decode($base64); 71 58 $query = json_decode($json, true); 59 $query['status'] = [ 'trash', 'publish']; 60 // $product_id = isset($query['include']) ? $query['include'][0] : null; 61 62 72 63 73 64 $pasazh_products = []; 74 65 $items = wc_get_products($query); 75 76 66 foreach ($items as $product) { 77 67 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); … … 79 69 } 80 70 81 82 71 $response = []; 83 72 $response["meta"] = [ 84 "count" => sizeof($ items)73 "count" => sizeof($pasazh_products) 85 74 ]; 86 75 $response["products"] = $pasazh_products; … … 90 79 } 91 80 92 function PASAZHAPI_sync_product($product_id) 93 { 81 function PASAZHAPI_delete_product($product_id) 82 { 83 84 94 85 try { 95 86 if (get_transient("papi_product_id") == $product_id) return; 96 87 set_transient('papi_product_id', $product_id, 1); 97 88 98 99 $post_type = null; 100 101 try { 102 $query = [ 103 "include" => [$product_id], 104 ]; 105 $items = wc_get_products($query); 106 $post_type = $items[0]->post_type; 107 } catch (Exception $exception) { 108 109 } 110 111 89 $post = get_post($product_id); 90 91 92 if (!$post) 93 return; 94 95 $post_type = $post->post_type; 112 96 if ($post_type != "product") 97 return; 98 99 100 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-deleted/$product_id", [ 101 "headers" => [ 102 "papi-source-url" => get_site_url() 103 ] 104 ]); 105 106 107 } catch (Exception $e) { 108 109 } 110 111 } 112 113 function PASAZHAPI_sync_product($product_id) 114 { 115 116 117 try { 118 if (get_transient("papi_product_id") == $product_id) return; 119 set_transient('papi_product_id', $product_id, 1); 120 121 $post = get_post($product_id); 122 123 124 if (!$post) 125 return; 126 127 $post_type = $post->post_type; 128 if ($post_type != "product") 129 return; 130 131 132 if (in_array($post->post_status , ['auto-draft' , 'draft']) ) 113 133 return; 114 134 … … 133 153 function PASAZHAPI_get_pasazh_product_from_wc_product($product) 134 154 { 155 156 $product_status = $product->get_status(); 135 157 136 158 $pasazh_product = new PASAZHAPIPasazhProduct(); -
pasazh/trunk/readme.txt
r2840342 r2841766 5 5 Requires at least: 5.0.3 6 6 Tested up to: 5.9.3 7 Stable tag: 1. 77 Stable tag: 1.8 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. 7=25 = 1.8 = 26 26 * First release 27 27 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.