Changeset 2840280
- Timestamp:
- 12/28/2022 07:19:48 AM (3 years ago)
- Location:
- pasazh/trunk
- Files:
-
- 2 edited
-
pasazh.php (modified) (14 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pasazh/trunk/pasazh.php
r2835362 r2840280 6 6 Plugin URI: https://epasazh.com 7 7 Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید. 8 Version: 1. 58 Version: 1.6 9 9 Author: aliparsa 10 10 Author URI: https://profiles.wordpress.org/aliparsa/ … … 15 15 */ 16 16 17 const PASAZHAPI_papi_version = "1. 5";17 const PASAZHAPI_papi_version = "1.0"; 18 18 19 19 add_action('rest_api_init', function () { … … 34 34 35 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' ); 39 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 //} 36 50 37 51 //region api functions … … 52 66 { 53 67 68 54 69 $base64 = $data->get_params()["query"]; 55 70 $json = base64_decode($base64); … … 59 74 $items = wc_get_products($query); 60 75 76 77 61 78 foreach ($items as $product) { 62 79 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 63 80 $pasazh_products[] = $pasazh_product; 64 81 } 82 65 83 66 84 $response = []; … … 70 88 $response["products"] = $pasazh_products; 71 89 90 72 91 return new WP_REST_Response($response, 200); 73 92 } … … 75 94 function PASAZHAPI_sync_product($product_id) 76 95 { 77 78 96 try { 79 97 if (get_transient("papi_product_id") == $product_id) return; 80 98 set_transient('papi_product_id', $product_id, 1); 99 81 100 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-updated/$product_id", [ 82 101 "headers" => [ … … 84 103 ] 85 104 ]); 105 106 86 107 } catch (Exception $e) { 87 108 … … 96 117 function PASAZHAPI_get_pasazh_product_from_wc_product($product) 97 118 { 98 99 119 100 120 $pasazh_product = new PASAZHAPIPasazhProduct(); … … 103 123 $pasazh_product->setUrl(get_permalink($product->get_id())); 104 124 105 106 125 $description = $product->get_description(); 107 108 //get description from variations109 126 if (strlen($description) == 0) { 110 111 foreach ($product->get_attributes() as $attribute) { 112 $attribute_data = json_decode(json_encode($attribute['data'], JSON_PRETTY_PRINT)); 113 $is_visible = $attribute_data->is_visible == 1; 114 if ($is_visible) { 115 $description .= $attribute_data->name . " : \r\n"; 116 $description .= implode(',', $attribute_data->options); 117 $description .= "\r\n\r\n"; 118 } 127 foreach ($product->get_attributes() as $attribute) { 128 $attribute_data = json_decode(json_encode($attribute['data'], JSON_PRETTY_PRINT)); 129 $is_visible = $attribute_data->is_visible == 1; 130 if ($is_visible) { 131 $description .= $attribute_data->name . " : \r\n"; 132 $description .= implode(' , ', $attribute_data->options); 133 $description .= "\r\n\r\n"; 119 134 } 120 121 } 135 } 136 } 137 122 138 $pasazh_product->setDescription($description); 139 123 140 124 141 … … 126 143 $technical_description = ""; 127 144 $attrs = $product->get_attributes(); 128 foreach ($attrs as $attr) { 145 146 $test = ""; 147 foreach ($attrs as $attr){ 129 148 130 149 if ($attr["visible"] != true) continue; 131 150 if ($attr["variation"] == true) continue; 132 133 if (strlen($technical_description) > 0) 151 if (strlen($technical_description)>0) 134 152 $technical_description .= "\n\n"; 135 153 $data = $attr->get_data(); 136 154 $technical_description .= $data["name"] . " : \n"; 137 155 $options_text = ""; 138 foreach ($data["options"] as $option) { 156 foreach ($data["options"] as $option){ 157 139 158 if (strlen($options_text) > 0) 140 $options_text .= " | "; 141 $options_text .= $option; 142 143 } 144 $technical_description .= $options_text; 159 $options_text .= " | " ; 160 $options_text .= $option ; 161 162 $test .= $options_text; 163 164 } 165 166 $technical_description .= $options_text ; 145 167 } 146 168 … … 155 177 $specification_arr = []; 156 178 179 157 180 foreach ($product->get_available_variations() as $variation) { 181 182 $is_in_stock = isset($variation['is_in_stock']) && $variation['is_in_stock'] == 1; 158 183 159 184 $specification_object = new \stdClass(); … … 164 189 $specification_object->name = trim($specification_object->name); 165 190 $specification_object->price = $variation["display_price"]; 191 $specification_object->is_in_stock = $is_in_stock; 166 192 $specification_arr [] = $specification_object; 167 193 168 194 } 195 169 196 170 197 if (sizeof($specification_arr) > 0) { … … 179 206 $quantity = $product->get_stock_quantity(); 180 207 } else { 181 if ($product->is_in_stock()){208 if($product->is_in_stock()){ 182 209 $quantity = 1; 183 210 } -
pasazh/trunk/readme.txt
r2835362 r2840280 5 5 Requires at least: 5.0.3 6 6 Tested up to: 5.9.3 7 Stable tag: 1. 57 Stable tag: 1.6 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. 5=25 = 1.6 = 26 26 * First release 27 27 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.