Changeset 2946752
- Timestamp:
- 08/02/2023 05:58:09 PM (3 years ago)
- Location:
- drivefx-woocommerce/trunk
- Files:
-
- 9 edited
-
PHCLibrary/customers.php (modified) (8 diffs)
-
PHCLibrary/invoices.php (modified) (10 diffs)
-
PHCLibrary/orders.php (modified) (11 diffs)
-
PHCLibrary/utils.php (modified) (5 diffs)
-
class.DriveFxWoocommerce.php (modified) (23 diffs)
-
drivefx-woocommerce-settings.php (modified) (1 diff)
-
drivefx-woocommerce.php (modified) (1 diff)
-
settings/backend.php (modified) (5 diffs)
-
settings/syncro_gate.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
drivefx-woocommerce/trunk/PHCLibrary/customers.php
r2786822 r2946752 49 49 # Update Customer 50 50 $updatedCustomer = $this->updateCustomer($ch, $credentials, $dataPack, $response); 51 52 // $this->logs->writeFileLog('updatedCustomer', $updatedCustomer); 51 //$this->logs->writeFileLog('updatedCustomer', $updatedCustomer); 53 52 54 53 if (curl_error($ch)) { … … 64 63 #Create a new customer 65 64 $createdCustomer = $this->createCustomer($ch, $credentials, $dataPack); 66 67 65 //$this->logs->writeFileLog('createdCustomer', $createdCustomer); 68 66 … … 82 80 #Verify if a generic customer exists 83 81 $response = $this->utils_services->filterItem_Query($ch, $credentials, 'Cl', 'clivd', '1'); 84 85 82 //$this->logs->writeFileLog('Gen_Cl Checking:', $response); 86 83 … … 118 115 // Save Instance in Software PHC 119 116 $responseGenCl = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 120 121 117 //$this->logs->writeFileLog('genCl Save:', $response); 122 118 … … 254 250 if ($dataPack->settings->createExemptCO){ 255 251 // if is from UE mermber Country 256 if ($responseCountry['result'][0]['ueMember'] == 1){ 252 if ($responseCountry['result'][0]['ueMember'] == 1){ 257 253 //check if it is a company or a private client (via VIES) 258 $checkVAT = $this->utils_services->viesCheckVAT($responseCountry['result'][0]['nomeabrv'], $customer->ncont);259 260 if ($checkVAT ['valid'] == "true"){254 $checkVAT = $this->utils_services->viesCheckVAT($responseCountry['result'][0]['nomeabrv'], $customer->ncont); 255 256 if ($checkVAT->isValid){ 261 257 $response['result'][0]['tabiva'] = 4; 262 258 $response['result'][0]['codmotiseimp'] = $dataPack->settings->typeOfReasonCO; … … 276 272 # Save Instance in Software PHC 277 273 $paramsSaveResponse = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 278 279 274 //$this->logs->writeFileLog('clSave:', $paramsSaveResponse); 280 275 … … 301 296 $response['result'][0]['nome'] = $customer->nome; 302 297 $mustUpdateCl = true; 303 } 298 } 304 299 if(isset($customer->morada) && $response['result'][0]['morada'] !== $customer->morada) { 305 300 $response['result'][0]['morada'] = $customer->morada; … … 364 359 # Save Instance in Software PHC 365 360 $paramsSaveResponse = $this->utils_services->paramsSave($ch, $credentials, 'ClWS', $response); 366 367 361 //$this->logs->writeFileLog('ClUpdate Save:', $paramsSaveResponse); 368 362 -
drivefx-woocommerce/trunk/PHCLibrary/invoices.php
r2786822 r2946752 143 143 //Clear the product lines 144 144 $response['result'][0]['fis'] = []; 145 146 145 //$this->logs->writeFileLog('FtWs Response', $response); 147 146 … … 169 168 ### 170 169 $cart = $ft->cart; 171 170 172 171 // Only If have articles to FT 173 172 if(!empty($cart)){ … … 187 186 ### 188 187 $fees = $ft->fees; 189 190 188 #fees 191 189 if (isset($fees)){ … … 196 194 197 195 $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->feesName); 198 199 196 //$this->logs->writeFileLog('ResponseST', $response); 200 197 … … 238 235 if($settings->shippingName != "0") { 239 236 $responseSt = $this->utils_services->filterItem_Query($ch, $credentials, 'St', 'ref', $settings->shippingName); 240 241 //$this->logs->writeFileLog('ResponseST', $response); 237 //$this->logs->writeFileLog('ResponseST', $responseSt); 242 238 243 239 if(empty($responseSt)) { … … 258 254 } 259 255 260 $fi->design = $ft->shipping_name;256 //$fi->design = $ft->shipping_name; 261 257 $fi->qtt = 1; 262 258 $fi->etiliquido = $ft->shipping_value; … … 315 311 //actEntity 316 312 $response2 = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 317 318 313 //$this->logs->writeFileLog('response2:', $response2['result'][0]['fis']); 319 314 … … 341 336 #actEntity 342 337 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response2); 343 344 //$this->logs->writeFileLog('actEntity1:', $response['result'][0]['fis']); 338 //$this->logs->writeFileLog('actEntity1:', $response['result'][0]['fis']); 345 339 346 340 if (curl_error($ch)) { … … 426 420 #actEntity 427 421 $response = $this->utils_services->actEntity($ch, $credentials, 'FtWS', $response); 428 429 422 //$this->logs->writeFileLog('actEntity2:', $response); 430 423 … … 468 461 ### 469 462 $ftstamp = $response['result'][0]['ftstamp']; 470 471 463 $response = $this->utils_services->paramsSignDocument($ch, $credentials, $ftstamp); 472 473 464 //$this->logs->writeFileLog('signing ft: ', $response); 474 465 } -
drivefx-woocommerce/trunk/PHCLibrary/orders.php
r2786822 r2946752 46 46 # obtain gama 47 47 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 48 49 48 //$this->logs->writeFileLog('BackEnd response:', $response); 50 49 … … 214 213 #actEntity 215 214 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 216 217 215 //$this->logs->writeFileLog('actEntity3:', $response); 218 216 … … 366 364 //Obtain number of customer 367 365 $response['result'][0]['no'] = $newCustomer->no; 366 $response['result'][0]['nome'] = $newCustomer->nome; 367 $response['result'][0]['ncont'] = $newCustomer->ncont; 368 368 $response['result'][0]['clstamp'] = $newCustomer->clstamp; 369 369 … … 372 372 #actEntity 373 373 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 374 375 374 //$this->logs->writeFileLog('actEntity:', $response); 376 375 … … 382 381 $this->logs->writeFileLog('addNewOrder13.1', $response['messages'][0]['messageCodeLocale']); 383 382 } else { 384 $response['result'][0]['no'] = $newCustomer->no;385 $response['result'][0]['nome'] = $newCustomer->nome; 386 $response['result'][0]['ncont'] = $newCustomer->ncont; 383 /* $response['result'][0]['no'] = $newCustomer->no; 384 $response['result'][0]['nome'] = $newCustomer->nome; 385 $response['result'][0]['ncont'] = $newCustomer->ncont;*/ 387 386 388 387 #Put the same number of order in PHC … … 401 400 #Get taxes from Phc 402 401 $responseTaxes = $this->utils_services->getTaxes($ch, $credentials); 403 404 402 //$this->logs->writeFileLog('Get Taxes:', $responseTaxes['result']); 405 403 … … 479 477 //actEntity 480 478 $response2 = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 481 //$this->logs->writeFileLog('response2:', $response2['result'] [0]['bis']);479 //$this->logs->writeFileLog('response2:', $response2['result']); 482 480 483 481 // Update shipping value … … 492 490 493 491 //actEntity 494 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response2); 495 //$this->logs->writeFileLog('actEntity1:', $response ['result']);492 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response2); 493 //$this->logs->writeFileLog('actEntity1:', $response); 496 494 497 495 if (curl_error($ch)) { … … 596 594 $response['result'][0]['ncont'] = $bill->ncont; 597 595 598 599 596 #Obtain taxes 600 597 if (is_array($order->cart)){ … … 622 619 } 623 620 } 624 //$this->logs->writeFileLog('Obtain taxes:', $response ['result'][0]['bis']);621 //$this->logs->writeFileLog('Obtain taxes:', $response); 625 622 ### 626 623 $fees = $order->fees; … … 720 717 } 721 718 722 //actEntity 723 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 719 //actEntity 720 $response = $this->utils_services->actEntity($ch, $credentials, 'BoWS', $response); 724 721 //$this->logs->writeFileLog('actEntity2:', $response); 725 722 -
drivefx-woocommerce/trunk/PHCLibrary/utils.php
r2786822 r2946752 1 1 <?php 2 DEFINE ('VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService');2 DEFINE('VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService'); 3 3 4 4 class UtilsServices { … … 207 207 ); 208 208 //Build Http query using params 209 $this->query = http_build_query ($this->params);209 $this->query = http_build_query($this->params); 210 210 211 211 //Called webservice that make a request … … 883 883 * --- check VAT via VIES --- * 884 884 ********************************************************************/ 885 function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) {885 /* function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) { 886 886 $response = array (); 887 887 $pattern = '/<(%s).*?>([\s\S]*)<\/\1/'; … … 921 921 } 922 922 return $response; 923 } 923 } */ 924 925 function viesCheckVAT($countryCode, $vatNumber) { 926 $curl = curl_init(); 927 928 curl_setopt_array($curl, array( 929 CURLOPT_URL => 'https://ec.europa.eu/taxation_customs/vies/rest-api/ms/PT/vat/502199326', 930 CURLOPT_RETURNTRANSFER => true, 931 CURLOPT_ENCODING => '', 932 CURLOPT_MAXREDIRS => 10, 933 CURLOPT_TIMEOUT => 0, 934 CURLOPT_FOLLOWLOCATION => true, 935 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 936 CURLOPT_CUSTOMREQUEST => 'GET', 937 )); 938 939 $response = curl_exec($curl); 940 curl_close($curl); 941 942 return json_decode($response); 943 } 944 924 945 925 946 /******************************************************************* … … 991 1012 return $response; 992 1013 } 1014 1015 /******************************************************************* 1016 * --- Action query --- * 1017 ********************************************************************/ 1018 public function customQueryLimit($ch, $credentials, $entityName, $selectItems, $filterItem, $valueItem){ 1019 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1020 // Create map with request parameters 1021 $this->params = array ('itemQuery' => '{"groupByItems":[], 1022 "lazyLoaded":false, 1023 "joinEntities":[], 1024 "orderByItems":[], 1025 "SelectItems":["'.$selectItems.'"], 1026 "entityName":"'.$entityName.'", 1027 "filterItems":[{ 1028 "comparison":0, 1029 "filterItem":"'.$filterItem.'", 1030 "valueItem":"'.$valueItem.'", 1031 "groupItem":1, 1032 "checkNull":false, 1033 "skipCheckType":false, 1034 "type":"Number" 1035 }]}' 1036 ); 1037 1038 // Build Http query using params 1039 $this->query = http_build_query ($this->params); 1040 1041 //Called webservice that make a request 1042 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1043 1044 return $response; 1045 } 1046 1047 /******************************************************************* 1048 * --- FilterItem InnerJoin --- * 1049 ********************************************************************/ 1050 /** Quary to get Products by wharehouse **/ 1051 1052 public function customQueryLimit2($ch, $credentials, $armazem, $valueItem){ 1053 $this->url = $credentials->backendUrl."/REST/SearchWS/QueryAsEntities"; 1054 //Create map with request parameters 1055 $this->params = array ('itemQuery' => '{"distinct": true, 1056 "groupByItems": [], 1057 "lazyLoaded": false, 1058 "offset": 0, 1059 "orderByItems":[], 1060 "SelectItems": ["sa.stock"], 1061 "entityName": "st", 1062 "filterItems": [], 1063 "joinEntities": [{ 1064 "tableName": "sa", 1065 "joinType": 1, 1066 "joinExp": [{ 1067 "filterItem": "sa.ref", 1068 "comparison": 0, 1069 "valueItem": "<#var>st.ref", 1070 "groupItem": 1 1071 }, 1072 { 1073 "filterItem": "sa.armazem", 1074 "comparison": 0, 1075 "valueItem": "'.$armazem.'", 1076 "groupItem": 0 1077 }, 1078 { 1079 "filterItem": "sa.ref", 1080 "comparison": 0, 1081 "valueItem":"'.$valueItem.'", 1082 "groupItem": 0 1083 }] 1084 }] 1085 }' 1086 ); 1087 //Build Http query using params 1088 $this->query = http_build_query ($this->params); 1089 1090 //Called webservice that make a request 1091 $response=$this->doPhcRequest($ch, $this->url, $this->params, $credentials); 1092 1093 return $response; 1094 } 993 1095 } 994 1096 ?> -
drivefx-woocommerce/trunk/class.DriveFxWoocommerce.php
r2786822 r2946752 7 7 require_once 'PHCLibrary/orders.php'; 8 8 require_once 'PHCLibrary/invoices.php'; 9 require_once 'endpoints/actions.php'; 9 10 10 11 class DriveFxWoocommerce { … … 22 23 private $orders_services; 23 24 private $invoices_services; 25 private $actions_services; 24 26 25 27 // backend settings … … 58 60 'productPriceColumn'=> array('label' => 'Field to obtain product price in PHC GO', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose field in database of PHC GO that you want to obtain product price', 'notice' => ''), 59 61 'warehouse' => array('label' => 'Warehouse', 'type' => 'select', 'required' => false, 'checkboxDescription' => 'Choose from warehouse do you want import products', 'notice' => ''), 62 'autoUpdateWooPrice'=> array('label' => 'Synchronize price', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Synchronize product\'s prices according to PHC GO', 'notice' => ''), 63 'autoUpdateWooStock'=> array('label' => 'Synchronize stock', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Synchronize product\'s stock according to PHC GO', 'notice' => ''), 60 64 'positiveStock' => array('label' => 'Products with stock', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Only import products that have stock', 'notice' => ''), 61 65 'filterStock' => array('label' => 'Only available stock', 'type' => 'checkbox', 'required' => false, 'checkboxDescription' => 'Filter the quantity of stock minus uninvoiced orders', 'notice' => ''), … … 80 84 $this->orders_services = new OrdersService(); 81 85 $this->invoices_services = new InvoicesServices(); 86 $this->actions_services = new ActionsServices(); 82 87 83 88 // call init … … 125 130 //Save field to show status order in PHC 126 131 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 132 133 //Custom endPoint to receive updates from PHC GO 134 add_action( 'rest_api_init', 'action_callback_url_endpoint' ); 135 136 function action_callback_url_endpoint(){ 137 register_rest_route( 138 'phc/v1/', #Namespace 139 'receive-callback', #Endpoint 140 array( 141 'methods' => 'POST', 142 'callback' => 'receive_callback' 143 ) 144 ); 145 } 146 147 function receive_callback($request_data) { 148 //Get plugin configurations 149 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 150 $actions_services = new ActionsServices(); 151 $data = new stdClass(); 152 $logs = new Logs(); 153 154 if (isset($request_data)) { 155 $data->status = 'OK'; 156 $data->message = 'Communication successfully.'; 157 158 # get the itemVO json data 159 $itemData = json_decode($request_data->get_body()); 160 161 if(isset($itemData)){ 162 # Update Price 163 if(isset($itemData->ststamp) && isset($settings['backend']['autoUpdateWooPrice']) && $settings['backend']['autoUpdateWooPrice'] == 'on'){ 164 $updateAction = $actions_services->update_product_price_action($itemData, $settings); 165 //$logs->writeFileLog('updatePrice: ', $updateAction); 166 } 167 # Update Stock 168 if(isset($itemData->slstamp) && isset($settings['backend']['autoUpdateWooStock']) && $settings['backend']['autoUpdateWooStock'] == 'on'){ 169 $updateAction = $actions_services->update_product_stock_action($itemData, $settings); 170 //$logs->writeFileLog('updateStock: ', $updateAction); 171 } 172 } 173 } else { 174 $data->status = 'Failed'; 175 $data->message = 'Request data Missing!'; 176 $logs->writeFileLog('update_endpoint: ', 'PHC GO trigger connection failed.'); 177 } 178 return $data; 179 } 127 180 128 181 // handler for form submission … … 1104 1157 $this->logs->writeFileLog('setCommunicationFx9', $response['messages'][0]['messageCodeLocale']); 1105 1158 } else { 1106 if( $response['result'][0]['moeda'] != get_option('woocommerce_currency')){1159 if(isset($response['result']) && $response['result'][0]['moeda'] != get_option('woocommerce_currency')){ 1107 1160 $this->messagesInformation("Please configure currency in shop according to PHC"); 1108 1161 unset($_SESSION['username']); 1109 1162 } 1110 1163 } 1164 1165 ### UPDATE PRICES - activate/ deactivate 1166 if(isset($settings['backend']['autoUpdateWooPrice']) && $settings['backend']['autoUpdateWooPrice'] == 'on'){ 1167 # build hookUrl & subscriber 1168 $siteUrl = str_replace("https","http", get_site_url()); 1169 $hookUrl = $siteUrl."/wp-json/phc/v1/receive-callback"; 1170 $subscriber = "wp_st_".wp_get_current_user()->data->user_login; 1171 1172 #Check if update prices action is already registered 1173 $webhookResponse = $this->utils_services->paramsQuery5($ch, $credentials, 'Webhook', '0','hookUrl', $hookUrl, '0','subscriber', $subscriber); 1174 //$this->logs->writeFileLog('webhookResponse:', $webhookResponse); 1175 1176 if (curl_error($ch)) { 1177 $this->logs->writeFileLog('AutoUpdatePrice01', $ch); 1178 } else if(empty($response)){ 1179 $this->logs->writeFileLog('AutoUpdatePrice02', 'EMPTY RESPONSE'); 1180 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1181 $this->logs->writeFileLog('AutoUpdatePrice03', $response['messages'][0]['messageCodeLocale']); 1182 } else { 1183 if(empty($webhookResponse['result'])){ 1184 #Register auto update 1185 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'WebhookWS', 0); 1186 //$this->logs->writeFileLog('autoUpdate_getNewInstance:', $response); 1187 1188 if (curl_error($ch)) { 1189 $this->logs->writeFileLog('register_autoUpdatePrice01', $ch); 1190 } else if(empty($response)){ 1191 $this->logs->writeFileLog('register_autoUpdatePrice02', 'EMPTY RESPONSE'); 1192 } else { 1193 $response['result'][0]['hookUrl'] = $hookUrl; 1194 $response['result'][0]['subscriber'] = $subscriber; 1195 1196 $response['result'][0]['entity'] = 'St'; 1197 $response['result'][0]['onUpdate'] = true; 1198 1199 // Save Instance in Software PHC 1200 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $response); 1201 //$this->logs->writeFileLog('autoUpdate_Save:', $response); 1202 1203 if (curl_error($ch)) { 1204 $this->logs->writeFileLog('save_autoUpdatePrice01', $ch); 1205 } else if(empty($response)){ 1206 $this->logs->writeFileLog('save_autoUpdatePrice02', 'EMPTY RESPONSE'); 1207 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1208 $this->logs->writeFileLog('save_autoUpdatePrice03', $response['messages'][0]['messageCodeLocale']); 1209 } else { 1210 $this->logs->writeFileLog('info: ', "Auto update prices - new subscriber registered."); 1211 } 1212 } 1213 } else { 1214 if($webhookResponse['result'][0]['inactive']){ 1215 #Activate the subscription 1216 $webhookResponse['result'][0]['inactive'] = false; 1217 1218 // Save Instance in Software PHC 1219 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $webhookResponse); 1220 //$this->logs->writeFileLog('autoUpdate_Save01:', $response); 1221 1222 if (curl_error($ch)) { 1223 $this->logs->writeFileLog('save_autoUpdatePrice04', $ch); 1224 } else if(empty($response)){ 1225 $this->logs->writeFileLog('save_autoUpdatePrice05', 'EMPTY RESPONSE'); 1226 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1227 $this->logs->writeFileLog('save_autoUpdatePrice06', $response['messages'][0]['messageCodeLocale']); 1228 } else { 1229 $this->logs->writeFileLog('info: ', "Auto update prices - subscriber activated."); 1230 } 1231 } 1232 } 1233 } 1234 } else { 1235 # build hookUrl & subscriber 1236 $siteUrl = str_replace("https","http", get_site_url()); 1237 $hookUrl = $siteUrl."/wp-json/phc/v1/receive-callback"; 1238 $subscriber = "wp_st_".wp_get_current_user()->data->user_login; 1239 1240 #Check if update prices action is already registered 1241 $webhookResponse = $this->utils_services->paramsQuery5($ch, $credentials, 'Webhook', '0','hookUrl', $hookUrl, '0','subscriber', $subscriber); 1242 //$this->logs->writeFileLog('webhookResponse:', $webhookResponse); 1243 1244 if (curl_error($ch)) { 1245 $this->logs->writeFileLog('AutoUpdatePrice_04', $ch); 1246 } else if(empty($response)){ 1247 $this->logs->writeFileLog('AutoUpdatePrice_05', 'EMPTY RESPONSE'); 1248 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1249 $this->logs->writeFileLog('AutoUpdatePrice_06', $response['messages'][0]['messageCodeLocale']); 1250 } else { 1251 if(!empty($webhookResponse['result'])){ 1252 if(!$webhookResponse['result'][0]['inactive']){ 1253 #Deactivate the subscription 1254 $webhookResponse['result'][0]['inactive'] = true; 1255 1256 // Save Instance in Software PHC 1257 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $webhookResponse); 1258 //$this->logs->writeFileLog('autoUpdate_Save02:', $response); 1259 1260 if (curl_error($ch)) { 1261 $this->logs->writeFileLog('save_autoUpdatePrice07', $ch); 1262 } else if(empty($response)){ 1263 $this->logs->writeFileLog('save_autoUpdatePrice08', 'EMPTY RESPONSE'); 1264 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1265 $this->logs->writeFileLog('save_autoUpdatePrice09', $response['messages'][0]['messageCodeLocale']); 1266 } else { 1267 $this->logs->writeFileLog('info: ', "Auto update prices - subscriber deactivated."); 1268 } 1269 } 1270 } 1271 } 1272 } 1273 1274 ### UPDATE STOCK - activate/ deactivate 1275 if(isset($settings['backend']['autoUpdateWooStock']) && $settings['backend']['autoUpdateWooStock'] == 'on'){ 1276 # build hookUrl & subscriber 1277 $siteUrl = str_replace("https","http", get_site_url()); 1278 $hookUrl = $siteUrl."/wp-json/phc/v1/receive-callback"; 1279 $subscriber = "wp_sl_".wp_get_current_user()->data->user_login; 1280 1281 #Check if update prices action is already registered 1282 $webhookResponse = $this->utils_services->paramsQuery5($ch, $credentials, 'Webhook', '0','hookUrl', $hookUrl, '0','subscriber', $subscriber); 1283 //$this->logs->writeFileLog('webhookResponse:', $webhookResponse); 1284 1285 if (curl_error($ch)) { 1286 $this->logs->writeFileLog('AutoUpdateStock01', $ch); 1287 } else if(empty($response)){ 1288 $this->logs->writeFileLog('AutoUpdateStock02', 'EMPTY RESPONSE'); 1289 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1290 $this->logs->writeFileLog('AutoUpdateStock03', $response['messages'][0]['messageCodeLocale']); 1291 } else { 1292 if(empty($webhookResponse['result'])){ 1293 #Register auto update 1294 $response = $this->utils_services->paramsNewInstance($ch, $credentials, 'WebhookWS', 0); 1295 //$this->logs->writeFileLog('autoUpdate_getNewInstance:', $response); 1296 1297 if (curl_error($ch)) { 1298 $this->logs->writeFileLog('register_autoUpdateStock01', $ch); 1299 } else if(empty($response)){ 1300 $this->logs->writeFileLog('register_autoUpdateStock02', 'EMPTY RESPONSE'); 1301 } else { 1302 $response['result'][0]['hookUrl'] = $hookUrl; 1303 $response['result'][0]['subscriber'] = $subscriber; 1304 1305 $response['result'][0]['entity'] = 'Sl'; 1306 $response['result'][0]['onCreate'] = true; 1307 $response['result'][0]['onUpdate'] = true; 1308 $response['result'][0]['onDelete'] = true; 1309 1310 // Save Instance in Software PHC 1311 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $response); 1312 //$this->logs->writeFileLog('autoUpdate_Save:', $response); 1313 1314 if (curl_error($ch)) { 1315 $this->logs->writeFileLog('save_autoUpdateStock01', $ch); 1316 } else if(empty($response)){ 1317 $this->logs->writeFileLog('save_autoUpdateStock02', 'EMPTY RESPONSE'); 1318 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1319 $this->logs->writeFileLog('save_autoUpdateStock03', $response['messages'][0]['messageCodeLocale']); 1320 } else { 1321 $this->logs->writeFileLog('info: ', "Auto update stocks - new subscriber registered."); 1322 } 1323 } 1324 } else { 1325 if($webhookResponse['result'][0]['inactive']){ 1326 #Activate the subscription 1327 $webhookResponse['result'][0]['inactive'] = false; 1328 1329 // Save Instance in Software PHC 1330 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $webhookResponse); 1331 //$this->logs->writeFileLog('autoUpdate_Save02:', $response); 1332 1333 if (curl_error($ch)) { 1334 $this->logs->writeFileLog('save_autoUpdateStock04', $ch); 1335 } else if(empty($response)){ 1336 $this->logs->writeFileLog('save_autoUpdateStock05', 'EMPTY RESPONSE'); 1337 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1338 $this->logs->writeFileLog('save_autoUpdateStock06', $response['messages'][0]['messageCodeLocale']); 1339 } else { 1340 $this->logs->writeFileLog('info: ', "Auto update stocks - subscriber activated."); 1341 } 1342 } 1343 } 1344 } 1345 } else { 1346 # build hookUrl & subscriber 1347 $siteUrl = str_replace("https","http", get_site_url()); 1348 $hookUrl = $siteUrl."/wp-json/phc/v1/receive-callback"; 1349 $subscriber = "wp_sl_".wp_get_current_user()->data->user_login; 1350 1351 #Check if update prices action is already registered 1352 $webhookResponse = $this->utils_services->paramsQuery5($ch, $credentials, 'Webhook', '0','hookUrl', $hookUrl, '0','subscriber', $subscriber); 1353 //$this->logs->writeFileLog('webhookResponse:', $webhookResponse); 1354 1355 if (curl_error($ch)) { 1356 $this->logs->writeFileLog('AutoUpdateStock04', $ch); 1357 } else if(empty($response)){ 1358 $this->logs->writeFileLog('AutoUpdateStock05', 'EMPTY RESPONSE'); 1359 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1360 $this->logs->writeFileLog('AutoUpdateStock06', $response['messages'][0]['messageCodeLocale']); 1361 } else { 1362 if(!empty($webhookResponse['result'])){ 1363 if(!$webhookResponse['result'][0]['inactive']){ 1364 #Deactivate the subscription 1365 $webhookResponse['result'][0]['inactive'] = true; 1366 1367 // Save Instance in Software PHC 1368 $response = $this->utils_services->paramsSave($ch, $credentials, 'WebhookWS', $webhookResponse); 1369 //$this->logs->writeFileLog('autoUpdate_Save03:', $response); 1370 1371 if (curl_error($ch)) { 1372 $this->logs->writeFileLog('save_autoUpdateStock07', $ch); 1373 } else if(empty($response)){ 1374 $this->logs->writeFileLog('save_autoUpdateStock08', 'EMPTY RESPONSE'); 1375 } else if(isset($response['messages'][0]['messageCodeLocale'])){ 1376 $this->logs->writeFileLog('save_autoUpdateStock09', $response['messages'][0]['messageCodeLocale']); 1377 } else { 1378 $this->logs->writeFileLog('info: ', "Auto update stocks - subscriber deactivated."); 1379 } 1380 } 1381 } 1382 } 1383 } 1111 1384 } 1112 1385 //Logout 1113 1386 $this->auth_services->PHCLogout($ch, $credentials); 1114 1115 1387 } 1116 1388 … … 1289 1561 $this->lockStart(); 1290 1562 $this->logs->writeFileLog('cancelOrder', "Enter for ID: ".$order_id); 1291 1292 1563 1564 $ch = ""; 1293 1565 // get Credentials 1294 1566 $credentials = $this->syncro_services->fetchCredentials(); … … 1344 1616 $docid = get_post_meta($post_ID); 1345 1617 $filterItem = "bostamp"; 1346 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1]; 1618 $valueItem = isset($docid['_docid']) ? $docid['_docid'][sizeof($docid['_docid'])-1] : null; 1619 1347 1620 1348 1621 //Verify if exists in bd … … 1402 1675 $this->logs->writeFileLog('completedOrder', "Enter " . $order_id); 1403 1676 $settings = get_option(DRIVEFXWOOCOMMERCE_PLUGIN_NAME); 1677 $ch = ""; 1404 1678 1405 1679 // get Credentials … … 1440 1714 1441 1715 $filterItem = "bostamp"; 1442 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1];1443 1716 $valueItem = isset($docid['_docid']) ? $docid['_docid'][sizeof($docid['_docid'])-1] : null; 1717 1444 1718 if(empty($valueItem)){ 1445 1719 $order_received = get_option('woocommerce_checkout_order_received_endpoint'); … … 1449 1723 } 1450 1724 $docid = get_post_meta($order_received); 1451 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1];1725 $valueItem = isset($docid['_docid']) ? $docid['_docid'][sizeof($docid['_docid'])-1] : null; 1452 1726 } 1453 1727 if(empty($valueItem)){ 1454 1728 $order_received = sanitize_text_field($order_id ); 1455 1729 $docid = get_post_meta($order_received); 1456 $valueItem = $docid['_docid'][sizeof($docid['_docid'])-1];1730 $valueItem = isset($docid['_docid']) ? $docid['_docid'][sizeof($docid['_docid'])-1] : null; 1457 1731 } 1458 1732 … … 1483 1757 $this->logs->writeFileLog('completedOrder3', $response['messages'][0]['messageCodeLocale']); 1484 1758 } else { 1485 //if($response['result'][0]['isconfiguredtosign'] == false || ($response['result'][0]['isconfiguredtosign'] == true && $response['result'][0]['draftRecord'] == 1)){1486 1759 if(!empty($response['result'][0])){ 1487 1760 //Obtain status … … 1510 1783 $this->logs->writeFileLog('completedOrder4', $response['messages'][0]['messageCodeLocale']); 1511 1784 } 1512 } 1513 //} 1514 $response = $response['result'][0]; 1515 1785 } 1786 $response = isset($response['result'][0]) ? $response['result'][0] : null; 1787 1516 1788 if(!empty($response['bostamp'])){ 1517 1789 //Create Invoice only if is configurated type of invoices … … 1536 1808 $this->auth_services->PHCLogout($ch, $credentials); 1537 1809 //session_destroy(); 1538 $this->logs->writeFileLog('completedOrder', "Exit " . $order_id);1810 $this->logs->writeFileLog('completedOrder', "Exit " . $order_id); 1539 1811 $this->lockEnd(); 1540 1812 } … … 1545 1817 1546 1818 if(isset($settings['backend']['doInvoice']) && $settings['backend']['doInvoice']){ 1547 $this->logs->writeFileLog('addInternalDocumentInvoice', "Start copy of internal document, ID: ".$order_id);1819 //$this->logs->writeFileLog('addInternalDocumentInvoice', "Start copy of internal document, ID: ".$order_id); 1548 1820 1549 1821 $wooOrder = $this->syncro_services->fetchOrderData($order_id); … … 1556 1828 $this->sendEmail($ch, $credentials, $response, $dataPack); 1557 1829 1558 $this->logs->writeFileLog('addInternalDocumentInvoice', "End copy of internal document, ID: ".$order_id);1830 //$this->logs->writeFileLog('addInternalDocumentInvoice', "End copy of internal document, ID: ".$order_id); 1559 1831 } 1560 1832 } … … 1612 1884 1613 1885 $i = 0; 1614 $count = count($fisProducts);1886 $count = isset($fisProducts) ? count($fisProducts) : 0; 1615 1887 //$this->logs->writeFileLog('response:', $count); 1616 1888 while ($i < $count) { … … 1934 2206 $responseFilter = $this->utils_services->doubleFilter($ch, $credentials, 'Sl', 'ref', $value['ref'], 'entrada', '1'); 1935 2207 //$this->logs->writeFileLog('listProducts2', $responseFilter); 1936 $totalStock = array_reduce(2208 /* $totalStock = array_reduce( 1937 2209 $responseFilter['result'], 1938 2210 function( $currentTotal, $sl ) { … … 1940 2212 }, 1941 2213 0 1942 ); 1943 2214 ); */ 2215 1944 2216 if (isset($settings['backend']['positiveStock']) && $settings['backend']['positiveStock'] == 'on'){ 1945 //Extract the customer ordrers from total stock 1946 if ($totalStock - $value['qttcli'] > 0){ 1947 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 2217 //Extract the customer ordrers from total stock (just if is not negative) 2218 if ($value['stock'] - $value['qttcli'] > 0){ 2219 //if ($totalStock - $value['qttcli'] > 0){ 2220 //$arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 2221 $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli']; 2222 } else { 2223 $arrayRef[$value['ref']] = $value['stock']; 1948 2224 } 1949 } else { 1950 $arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 2225 } else { 2226 //Extract the customer ordrers from total stock 2227 //$arrayRef[$value['ref']] = $totalStock - $value['qttcli']; 2228 $arrayRef[$value['ref']] = $value['stock'] - $value['qttcli']; 1951 2229 } 1952 2230 } else{ … … 2214 2492 //Obtain gama of PHC 2215 2493 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 2216 2217 2494 //$this->logs->writeFileLog('Get Gama:', $response); 2218 2495 … … 2421 2698 //Obtain gama of PHC 2422 2699 $response = $this->utils_services->paramsGetBackEndInfo($ch, $credentials); 2423 2424 2700 //$this->logs->writeFileLog('Get Gama:', $response); 2425 2701 … … 2453 2729 2454 2730 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'St', $refArray); 2455 2456 2731 //$this->logs->writeFileLog('StList response:', $response); 2457 2732 … … 2508 2783 2509 2784 $response = $this->utils_services->paramsQuery3($ch, $credentials, 'Sa', $refArray); 2510 2511 2785 //$this->logs->writeFileLog('Update All Sa:', $refArray); 2512 2786 -
drivefx-woocommerce/trunk/drivefx-woocommerce-settings.php
r2456862 r2946752 1 1 <?php 2 2 // check what settings tab to display 3 $tab = sanitize_text_field( $_GET['tab'] );3 $tab = isset($_GET['tab']) ? sanitize_text_field( $_GET['tab'] ) : null; 4 4 5 5 $tab = isset($tab) ? $tab : 'backend'; -
drivefx-woocommerce/trunk/drivefx-woocommerce.php
r2786822 r2946752 3 3 * Plugin Name: PHC GO WooCommerce 4 4 * Description: Easy integration between Woocommerce WordPress and your PHC GO installation. 5 * Version: 4.9. 25 * Version: 4.9.3 6 6 * Author: PHC Software, S.A. 7 7 * Author URI: https://www.phcgo.net/ -
drivefx-woocommerce/trunk/settings/backend.php
r2786822 r2946752 39 39 <input class="regular-text" id="url" type="text" name="drivefx-woocommerce[backend][url]" value="<?php echo $settings['backend']['url'] ?>"> 40 40 41 <?php if( $resultDB->meta_value != ''){ ?>41 <?php if(isset($resultDB->meta_value) && $resultDB->meta_value != ''){ ?> 42 42 <div id="backend_url_initialize" class="button button-primary" title="Autenticate plugin"> 43 43 <img id="plus" src="<?php echo plugins_url('/../images/plus.png', __FILE__) ?>" title="Autenticate plugin"> … … 45 45 </div> 46 46 47 <?php } else if($settings['backend']['url'] == '' && $resultDB->meta_value == '') { ?>47 <?php } else if($settings['backend']['url'] == '' && isset($resultDB->meta_value) && $resultDB->meta_value == '') { ?> 48 48 49 49 <?php } else { ?> … … 71 71 } 72 72 73 if( $resultDB->meta_value != '' && $resultDB->meta_value != 'error'){73 if(isset($resultDB->meta_value) && $resultDB->meta_value != '' && $resultDB->meta_value != 'error'){ 74 74 $showErrorsLogin = true; 75 75 switch ($id) { … … 654 654 </tr> 655 655 <?php } break; 656 ### - Syncronyze product prices 657 case 'autoUpdateWooPrice': 658 if(isset($_SESSION['username']) && $_SESSION['username'] != '') 659 { ?><tr> 660 <th scope="row"><label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label></th> 661 <td> 662 <?php $value == 'on' ? $checkedBox = 'checked' : $checkbox = ''; ?> 663 <input style="width: 0;" class="regular-text" <?php echo $checkedBox ?> id="<?php echo $id ?>" type="<?php echo $opts['type'] ?>" name="<?php echo $name ?>"> 664 <span><?php echo $opts['checkboxDescription'] ?></span> 665 <p class="description"><?php if (isset($opts['descr'])) echo $opts['descr'] ?></p> 666 </td> 667 </tr><?php } 668 break; 669 ### - Syncronyze product stock 670 case 'autoUpdateWooStock': 671 if((isset($_SESSION['gamaDRIVEFX']) && $_SESSION['gamaDRIVEFX'] >= 9) && (isset($_SESSION['username']) && $_SESSION['username'] != '')) 672 { ?><tr> 673 <th scope="row"><label for="<?php echo $id ?>"><?php echo $opts['label'] ?></label></th> 674 <td> 675 <?php $value == 'on' ? $checkedBox = 'checked' : $checkbox = ''; ?> 676 <input style="width: 0;" class="regular-text" <?php echo $checkedBox ?> id="<?php echo $id ?>" type="<?php echo $opts['type'] ?>" name="<?php echo $name ?>"> 677 <span><?php echo $opts['checkboxDescription'] ?></span> 678 <p class="description"><?php if (isset($opts['descr'])) echo $opts['descr'] ?></p> 679 </td> 680 </tr><?php } 681 break; 656 682 case 'warehouse': 657 683 if((isset($_SESSION['gamaDRIVEFX']) && $_SESSION['gamaDRIVEFX'] >= 9) && (isset($_SESSION['username']) && $_SESSION['username'] != '')){ ?> … … 753 779 } 754 780 755 756 781 endforeach; 757 782 758 if( $showErrorsLogin == true && (empty($settings['backend']['username']) || empty($settings['backend']['password']) || empty($settings['backend']['url']))){783 if(isset($showErrorsLogin) && $showErrorsLogin == true && (empty($settings['backend']['username']) || empty($settings['backend']['password']) || empty($settings['backend']['url']))){ 759 784 $this->messagesInformation("Incomplete configurations.<br>Please fill Username, Password and Backend URL"); 760 785 } -
drivefx-woocommerce/trunk/settings/syncro_gate.php
r2786822 r2946752 9 9 require_once __DIR__.'/../PHCLibrary/classes/invoice.php'; 10 10 11 12 11 class SyncroService { 13 12 … … 37 36 $resultDB = $wpdb->get_row(str_replace("'".$table_name."'", $table_name, $wpdb->prepare($query, $table_name, '_token'))); 38 37 39 // build our web service full URL 40 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 41 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 42 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 43 38 // build our web service full URL 39 if(!is_array($settings['backend']['url'])){ 40 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html/'); 41 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/html'); 42 $settings['backend']['url'] = rtrim($settings['backend']['url'], '/'); 43 } 44 44 45 // build credencials 45 $credentials->backendUrl = $settings['backend']['url'].$this->extraurl !== null ?$settings['backend']['url'].$this->extraurl : null;46 $credentials->backendUrl = isset($settings['backend']['url']) ? $settings['backend']['url'].$this->extraurl : null; 46 47 $credentials->userCode = isset($settings['backend']['username']) ? $settings['backend']['username'] : null; 47 48 $credentials->password = isset($settings['backend']['password']) ? $settings['backend']['password'] : null; … … 51 52 $credentials->invoiceType_EU = isset($settings['backend']['typeOf_EU_Invoice']) ? $settings['backend']['typeOf_EU_Invoice'] : null; 52 53 53 /* $credentials->backendUrl = $settings['backend']['url'].$this->extraurl;54 $credentials->userCode = $settings['backend']['username'];55 $credentials->password = $settings['backend']['password'];56 $credentials->appId = $resultDB->meta_value;57 $credentials->company = $settings['backend']['dbname'];58 $credentials->invoiceType = $settings['backend']['typeOfInvoice'];59 $credentials->invoiceType_EU = $settings['backend']['typeOf_EU_Invoice']; */60 61 54 return $credentials; 62 55 63 56 } 64 65 66 57 67 58 /****************************************************************** … … 286 277 $docid = get_post_meta($order_id); 287 278 288 $syncroData->docId = $docid['_docid'][0];279 $syncroData->docId = isset($docid['_docid'][0]) ? $docid['_docid'][0] : null; 289 280 $syncroData->orderId = sanitize_text_field($order_id); 290 281 291 282 #Customer notes 292 $syncroData->obs = $_REQUEST['order_comments'];283 $syncroData->obs = isset($_REQUEST['order_comments']) ? $_REQUEST['order_comments'] : null; 293 284 #Get Currency from woocommerce 294 285 $syncroData->wooCurrency = get_option('woocommerce_currency'); … … 434 425 435 426 #Find the type of shipment 436 $post = get_post( $_REQUEST['shipping_method'][0] );427 $post = get_post($_REQUEST['shipping_method'][0]) !== null ? get_post($_REQUEST['shipping_method'][0]) : null; 437 428 438 429 $syncroData->post_title = isset( $post->post_title ) ? $post->post_title : ''; 439 $syncroData->edescc = WC()->cart->coupon_discount_amounts['saco']; 440 430 $syncroData->edescc = isset( WC()->cart->coupon_discount_amounts['saco'] ) ? WC()->cart->coupon_discount_amounts['saco'] : 0; 441 431 442 432 /******************************************************************* … … 516 506 //$this->logs->writeFileLog('order_meta', $order_meta); 517 507 518 $syncroData->$bill_country_ft = $order_meta['_billing_country'][0];508 $syncroData->$bill_country_ft = isset( $order_meta['_billing_country'][0] ) ? $order_meta['_billing_country'][0] : ''; 519 509 520 510 if($syncroData->billing_country != ''){ … … 532 522 $syncroData->billing_phone_ft = $order_meta['_billing_phone'][0]; 533 523 $syncroData->billing_postcode_ft = $order_meta['_billing_postcode'][0]; 534 $syncroData->billing_nif_ft = $order_meta['_billing_'.$settings['backend']['fieldNif']][0]; 535 536 524 $syncroData->billing_nif_ft = isset($order_meta['_billing_']) ? $order_meta['_billing_'.$settings['backend']['fieldNif']][0] : ''; 525 537 526 /******************************************************************* 538 527 * --- Invoice Shipping Data --- * … … 829 818 } 830 819 //Save items of cart 831 $this->setFtProductsSession($ftProducts); 832 820 if(!empty($ftProducts)) { 821 $this->setFtProductsSession($ftProducts); 822 } 823 833 824 //FT from Backend if is clicked "button tip" 834 825 if(empty($ftProducts[0]['ref'])){ … … 855 846 } 856 847 //Save items of cart 857 $this->setFtProductsSession($ftProducts); 848 if(!empty($ftProducts)) { 849 $this->setFtProductsSession($ftProducts); 850 } 858 851 } 859 852 … … 938 931 //fulfill "prodpack" with all data 939 932 $ftproductPack = $ftProducts; 940 941 933 //$this->logs->writeFileLog('prodPackft', $ftproductPack); 942 934 … … 955 947 array_push($_SESSION['listOfValueItem'], $ftProduct->value); 956 948 } 957 return $ft productPack;949 return $ftProducts; 958 950 } 959 951
Note: See TracChangeset
for help on using the changeset viewer.