Changeset 2840313
- Timestamp:
- 12/28/2022 09:13:28 AM (3 years ago)
- Location:
- pasazh/trunk
- Files:
-
- 2 edited
-
pasazh.php (modified) (10 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pasazh/trunk/pasazh.php
r2840280 r2840313 6 6 Plugin URI: https://epasazh.com 7 7 Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید. 8 Version: 1. 68 Version: 1.4 9 9 Author: aliparsa 10 10 Author URI: https://profiles.wordpress.org/aliparsa/ … … 35 35 add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1); 36 36 37 //region add two webhook for detect delete product38 add_action( 'before_delete_post', 'PASAZHAPI_sync_product' );39 add_action( 'save_post', 'PASAZHAPI_sync_product' );40 //endregion41 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 //}50 51 37 //region api functions 52 38 … … 66 52 { 67 53 68 69 54 $base64 = $data->get_params()["query"]; 70 55 $json = base64_decode($base64); … … 74 59 $items = wc_get_products($query); 75 60 76 77 78 61 foreach ($items as $product) { 79 62 $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product); 80 63 $pasazh_products[] = $pasazh_product; 81 64 } 82 83 65 84 66 $response = []; … … 94 76 function PASAZHAPI_sync_product($product_id) 95 77 { 78 96 79 try { 97 80 if (get_transient("papi_product_id") == $product_id) return; 98 81 set_transient('papi_product_id', $product_id, 1); 99 100 82 wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-updated/$product_id", [ 101 83 "headers" => [ … … 103 85 ] 104 86 ]); 105 106 107 87 } catch (Exception $e) { 108 88 … … 117 97 function PASAZHAPI_get_pasazh_product_from_wc_product($product) 118 98 { 99 119 100 120 101 $pasazh_product = new PASAZHAPIPasazhProduct(); 121 102 $pasazh_product->setId($product->get_id()); 122 103 $pasazh_product->setName($product->get_name()); 104 $pasazh_product->setDescription($product->get_description()); 123 105 $pasazh_product->setUrl(get_permalink($product->get_id())); 124 125 $description = $product->get_description();126 if (strlen($description) == 0) {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";134 }135 }136 }137 138 $pasazh_product->setDescription($description);139 140 141 106 142 107 // region technical desc 143 108 $technical_description = ""; 144 109 $attrs = $product->get_attributes(); 145 146 $test = "";147 110 foreach ($attrs as $attr){ 148 111 149 112 if ($attr["visible"] != true) continue; 150 113 if ($attr["variation"] == true) continue; 114 151 115 if (strlen($technical_description)>0) 152 116 $technical_description .= "\n\n"; … … 155 119 $options_text = ""; 156 120 foreach ($data["options"] as $option){ 157 158 121 if (strlen($options_text) > 0) 159 122 $options_text .= " | " ; 160 123 $options_text .= $option ; 161 124 162 $test .= $options_text; 163 164 } 165 125 } 166 126 $technical_description .= $options_text ; 167 127 } … … 177 137 $specification_arr = []; 178 138 179 180 139 foreach ($product->get_available_variations() as $variation) { 181 182 $is_in_stock = isset($variation['is_in_stock']) && $variation['is_in_stock'] == 1;183 140 184 141 $specification_object = new \stdClass(); … … 189 146 $specification_object->name = trim($specification_object->name); 190 147 $specification_object->price = $variation["display_price"]; 191 $specification_object->is_in_stock = $is_in_stock;192 148 $specification_arr [] = $specification_object; 193 149 194 150 } 195 196 151 197 152 if (sizeof($specification_arr) > 0) { -
pasazh/trunk/readme.txt
r2840280 r2840313 5 5 Requires at least: 5.0.3 6 6 Tested up to: 5.9.3 7 Stable tag: 1. 67 Stable tag: 1.4 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. 6=25 = 1.4 = 26 26 * First release 27 27 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.