Changeset 3308682
- Timestamp:
- 06/09/2025 07:36:27 PM (10 months ago)
- Location:
- shop-2-api
- Files:
-
- 63 added
- 6 edited
-
tags/1.0.32.2 (added)
-
tags/1.0.32.2/assets (added)
-
tags/1.0.32.2/assets/CredentialsBol.png (added)
-
tags/1.0.32.2/assets/bol-icon.png (added)
-
tags/1.0.32.2/assets/bol2api_bol_to_wc_product_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_category_mapping_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_common_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_dashboard.js (added)
-
tags/1.0.32.2/assets/bol2api_mapping_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_order_report_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_report_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_scripts.js (added)
-
tags/1.0.32.2/assets/bol2api_styles.css (added)
-
tags/1.0.32.2/assets/bol2api_styles_wc.css (added)
-
tags/1.0.32.2/assets/bol2api_wc_scripts.js (added)
-
tags/1.0.32.2/assets/external (added)
-
tags/1.0.32.2/assets/external/jquery (added)
-
tags/1.0.32.2/assets/external/jquery/jquery.modal.min.css (added)
-
tags/1.0.32.2/assets/external/jquery/jquery.modal.min.js (added)
-
tags/1.0.32.2/assets/external/jquery_mask (added)
-
tags/1.0.32.2/assets/external/jquery_mask/jquery.mask.min.js (added)
-
tags/1.0.32.2/assets/external/png (added)
-
tags/1.0.32.2/assets/external/png/drop-down-menu.png (added)
-
tags/1.0.32.2/assets/external/png/pictures.png (added)
-
tags/1.0.32.2/assets/logo.png (added)
-
tags/1.0.32.2/assets/shop2api_koopblock.js (added)
-
tags/1.0.32.2/assets/shop2api_order.js (added)
-
tags/1.0.32.2/assets/woocommerce-icon.png (added)
-
tags/1.0.32.2/includes (added)
-
tags/1.0.32.2/includes/Api (added)
-
tags/1.0.32.2/includes/Api/DashboardFields.php (added)
-
tags/1.0.32.2/includes/Api/Shop2ApiConnect.php (added)
-
tags/1.0.32.2/includes/Api/Shop2ApiWooCommerce.php (added)
-
tags/1.0.32.2/includes/Base (added)
-
tags/1.0.32.2/includes/Base/Activate.php (added)
-
tags/1.0.32.2/includes/Base/AjaxButtonActions.php (added)
-
tags/1.0.32.2/includes/Base/CommonFunctions.php (added)
-
tags/1.0.32.2/includes/Base/Deactivate.php (added)
-
tags/1.0.32.2/includes/Base/Enqueue.php (added)
-
tags/1.0.32.2/includes/Base/EnqueueWC.php (added)
-
tags/1.0.32.2/includes/Base/EnqueueWCAPI.php (added)
-
tags/1.0.32.2/includes/Base/SettingsLinks.php (added)
-
tags/1.0.32.2/includes/Init.php (added)
-
tags/1.0.32.2/includes/Pages (added)
-
tags/1.0.32.2/includes/Pages/Admin.php (added)
-
tags/1.0.32.2/includes/Tables (added)
-
tags/1.0.32.2/includes/Tables/Bol2WcOrderReport.php (added)
-
tags/1.0.32.2/includes/Tables/Bol2WcStatusReport.php (added)
-
tags/1.0.32.2/includes/Tables/Bol2WcStatusReportDetail.php (added)
-
tags/1.0.32.2/includes/Tables/Wc2BolProductSettings.php (added)
-
tags/1.0.32.2/index.php (added)
-
tags/1.0.32.2/readme.txt (added)
-
tags/1.0.32.2/shop-2-api.php (added)
-
tags/1.0.32.2/templates (added)
-
tags/1.0.32.2/templates/bol-get-best-price.php (added)
-
tags/1.0.32.2/templates/bol-order-sync.php (added)
-
tags/1.0.32.2/templates/bol-to-wc-product-sync.php (added)
-
tags/1.0.32.2/templates/common-header.php (added)
-
tags/1.0.32.2/templates/dashboard.php (added)
-
tags/1.0.32.2/templates/wc-to-bol-mapping.php (added)
-
tags/1.0.32.2/translation (added)
-
tags/1.0.32.2/translation/shop2api_dashboard.php (added)
-
tags/1.0.32.2/uninstall.php (added)
-
trunk/assets/bol2api_dashboard.js (modified) (7 diffs)
-
trunk/assets/bol2api_styles.css (modified) (10 diffs)
-
trunk/includes/Api/Shop2ApiConnect.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/shop-2-api.php (modified) (2 diffs)
-
trunk/templates/dashboard.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shop-2-api/trunk/assets/bol2api_dashboard.js
r3055588 r3308682 48 48 }) 49 49 50 /** 51 * Check connection status and update UI accordingly 52 * Shows/hides elements based on connection status 53 */ 50 54 function check_connection_status() { 51 55 // This will check if the connection is good on Shop 2 API … … 60 64 add_connection_error(); 61 65 } 62 // IF WC Connected and Boll connected then show STEP DATA. 66 67 // IF WC Connected and Bol connected then show STEP DATA. 63 68 if (!settings.wc_connected || !settings.bol_connected) { 64 69 $('#get-started-card-completed').hide(); … … 66 71 67 72 if (settings.wc_connected && settings.bol_connected) { 68 $('#get-started-card').hide(); 73 // Smooth transition to hide the card 74 $('#get-started-card').fadeOut(500); 69 75 } else { 70 // dashicons-yes-alt item-completed76 // Update icon to show not completed status 71 77 let $item = $('#connection-completed h1 span').first().removeClass('dashicons-yes-alt').removeClass('item-completed'); 72 78 $item.addClass('dashicons-dismiss').addClass('item-not-completed'); … … 95 101 } 96 102 103 /** 104 * Add connection error message to the UI 105 * Hides the WordPress error and shows a custom error message 106 */ 97 107 function add_connection_error() { 98 108 $('#setting-error-shop2api_token_error').hide(); 99 let error_text = $('#setting-error-shop2api_token_error').text() 109 let error_text = $('#setting-error-shop2api_token_error').text(); 100 110 if (error_text !== "") { 101 111 $('#token-error').text(error_text); 102 $('#token-error').show(); 103 } 104 } 105 112 $('#token-error').fadeIn(500); 113 } 114 } 115 116 /** 117 * Handle WooCommerce connection UI and click events 118 * Updates the UI based on connection status and sets up click handler 119 */ 106 120 function woocommerce_reroute() { 107 121 // If WC is connected change to green class 108 122 if (settings.wc_connected) { 109 let wc_connection = $("#connect-to-wc") 110 wc_connection.find(".connect-error").removeClass("connect-error").addClass("connect-success"); 111 wc_connection.find(".dashicons-admin-plugins").removeClass("dashicons-admin-plugins").addClass("dashicons-plugins-checked"); 123 let wc_connection = $("#connect-to-wc"); 124 wc_connection.find(".connect-error") 125 .removeClass("connect-error") 126 .addClass("connect-success") 127 .css("opacity", 0) 128 .animate({opacity: 1}, 500); 129 130 wc_connection.find(".dashicons-admin-plugins") 131 .removeClass("dashicons-admin-plugins") 132 .addClass("dashicons-plugins-checked"); 112 133 } 113 134 … … 117 138 } 118 139 119 //Open boll modal id bol is connected. 140 /** 141 * Handle Bol connection UI and modal interactions 142 * Updates the UI based on connection status and sets up event handlers 143 */ 120 144 function bol_connect_modal() { 121 145 if (settings.bol_connected) { 122 let bol_connection = $("#connect-to-bol") 123 bol_connection.find(".connect-error").removeClass("connect-error").addClass("connect-success"); 124 bol_connection.find(".dashicons-admin-plugins").removeClass("dashicons-admin-plugins").addClass("dashicons-plugins-checked"); 125 } 126 ; 146 let bol_connection = $("#connect-to-bol"); 147 bol_connection.find(".connect-error") 148 .removeClass("connect-error") 149 .addClass("connect-success") 150 .css("opacity", 0) 151 .animate({opacity: 1}, 500); 152 153 bol_connection.find(".dashicons-admin-plugins") 154 .removeClass("dashicons-admin-plugins") 155 .addClass("dashicons-plugins-checked"); 156 } 157 127 158 $('#connect-to-bol').on('click', function () { 128 159 $("#bol-connect-modal").modal(); … … 159 190 } 160 191 161 // This will save the bol data and trigger the save of WC data. 192 /** 193 * Save Bol connection data 194 * Collects form data and sends it to the server 195 */ 162 196 function save_bol_data() { 197 // Show loading indicator 198 $('#save-bol-data').prop('disabled', true).html('<i class="dashicons dashicons-update-alt" style="animation: spin 2s linear infinite;"></i> Saving...'); 199 163 200 let data = { 164 201 'action': 'set_shop_2_api_information_bol', … … 171 208 } 172 209 210 /** 211 * Handle the response from saving Bol data 212 * Shows error message or reloads page on success 213 * 214 * @param {Object} response_data - The response data from the server 215 * @param {string} status - The status of the request 216 */ 173 217 function handle_save_bol_response(response_data, status) { 174 218 if (response_data.success == false || status == false) { 175 $("#bol-connection-error").text("There was an issue updating the data."); 219 $("#bol-connection-error").text("There was an issue updating the data.").fadeIn(500); 220 221 // Reset button 222 $('#save-bol-data').prop('disabled', false).html('<i class="dashicons dashicons-admin-plugins"></i>'); 176 223 } else { 177 location.reload(); 178 } 179 } 224 // Show success message before reload 225 $("<div class='success-message'>Connection successful! Reloading page...</div>") 226 .appendTo("body") 227 .fadeIn(500); 228 229 setTimeout(function() { 230 location.reload(); 231 }, 1500); 232 } 233 } 234 235 // Add CSS for spin animation 236 $("<style>@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }</style>").appendTo("head"); 180 237 181 238 function get_sync_summary() { -
shop-2-api/trunk/assets/bol2api_styles.css
r3055588 r3308682 3 3 .card { 4 4 margin: 20px; 5 border-radius: 10%; 5 border-radius: 12px; 6 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 7 transition: transform 0.3s ease, box-shadow 0.3s ease; 8 background-color: #ffffff; 9 padding: 15px; 10 } 11 12 .card:hover { 13 transform: translateY(-5px); 14 box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15); 6 15 } 7 16 … … 12 21 font-weight: bold; 13 22 line-height: 2em; 23 color: #333; 14 24 } 15 25 … … 51 61 /* Success/Error messages */ 52 62 .error-message { 53 border-radius: 25px;54 background-color: rgb (240, 128, 128, 0.7);55 text-align: center; 56 width: 20%;57 padding: 1 0px;58 margin: 20px 120px 20px 20px;63 border-radius: 8px; 64 background-color: rgba(255, 76, 76, 0.9); 65 text-align: center; 66 width: 300px; 67 padding: 15px; 68 margin: 20px 20px 20px 20px; 59 69 font-weight: bold; 60 color: red;70 color: white; 61 71 display: none; 62 72 position: sticky; 63 73 float: right; 74 box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); 75 animation: fadeIn 0.5s ease; 64 76 } 65 77 66 78 .success-message { 67 border-radius: 25px;68 background-color: rgba( 130, 240, 143, 0.7);69 text-align: center; 70 width: 20%;71 padding: 1 0px;72 margin: 20px 120px 20px 20px;79 border-radius: 8px; 80 background-color: rgba(76, 175, 80, 0.9); 81 text-align: center; 82 width: 300px; 83 padding: 15px; 84 margin: 20px 20px 20px 20px; 73 85 font-weight: bold; 74 color: green;86 color: white; 75 87 display: none; 76 88 position: fixed; 77 89 right: 0; 90 box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); 91 animation: fadeIn 0.5s ease; 78 92 } 79 93 80 94 .warning-message { 81 border-radius: 25px;82 background-color: orange;83 text-align: center; 84 width: 20%;85 padding: 1 0px;95 border-radius: 8px; 96 background-color: rgba(255, 152, 0, 0.9); 97 text-align: center; 98 width: 300px; 99 padding: 15px; 86 100 margin: 5px; 87 101 font-weight: bold; 88 color: black;102 color: white; 89 103 /*display: none;*/ 90 104 position: fixed; 91 105 right: 0; 106 box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); 107 animation: fadeIn 0.5s ease; 108 } 109 110 @keyframes fadeIn { 111 from { opacity: 0; transform: translateY(-20px); } 112 to { opacity: 1; transform: translateY(0); } 92 113 } 93 114 94 115 /* Style buttons */ 95 116 .btn { 96 background-color: DodgerBlue; /* Blue background */117 background-color: #2196F3; /* Modern blue background */ 97 118 border: none; /* Remove borders */ 98 119 color: white; /* White text */ 99 padding: 12px 16px; /* Somepadding */120 padding: 12px 20px; /* Increased padding */ 100 121 font-size: 16px; /* Set a font size */ 101 122 cursor: pointer; /* Mouse pointer on hover */ 102 border-radius: 10%; 103 } 104 105 /* Darker background on mouse-over */ 123 border-radius: 6px; /* More subtle rounded corners */ 124 transition: all 0.3s ease; /* Smooth transition for hover effects */ 125 box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Subtle shadow for depth */ 126 font-weight: 500; /* Slightly bolder text */ 127 display: inline-flex; /* For better icon alignment */ 128 align-items: center; /* Center items vertically */ 129 justify-content: center; /* Center items horizontally */ 130 } 131 132 /* Darker background on mouse-over with scale effect */ 106 133 .btn:hover { 107 background-color: RoyalBlue; 134 background-color: #0d8bf2; 135 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); 136 transform: translateY(-2px); 137 } 138 139 /* Active/pressed state */ 140 .btn:active { 141 transform: translateY(1px); 142 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); 108 143 } 109 144 110 145 .btn > i { 111 font-size: xx-large; 112 padding-right: 10px; 113 padding-bottom: 10px; 146 font-size: 24px; 147 margin-right: 10px; 114 148 } 115 149 … … 124 158 /* LOGO */ 125 159 .common-header { 126 background-color: aliceblue;127 box-shadow: -2px -2px 10px 0px;160 background-color: #f8f9fa; 161 box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); 128 162 width: 100%; 129 163 margin-left: -15px; 130 164 padding-left: 30px; 131 165 margin-top: -10px; 132 padding-top: 10px; 133 padding-bottom: 10px; 166 padding-top: 15px; 167 padding-bottom: 15px; 168 border-bottom: 1px solid #e9ecef; 169 display: flex; 170 align-items: center; 134 171 } 135 172 … … 137 174 .shop2api-logo { 138 175 width: 200px; 176 transition: transform 0.3s ease; 177 } 178 179 .shop2api-logo:hover { 180 transform: scale(1.05); 139 181 } 140 182 141 183 .woocommerce-logo { 142 184 height: 90px; 185 transition: transform 0.3s ease; 186 } 187 188 .woocommerce-logo:hover { 189 transform: scale(1.05); 143 190 } 144 191 145 192 .bol-logo { 146 193 height: 70px; 194 transition: transform 0.3s ease; 195 } 196 197 .bol-logo:hover { 198 transform: scale(1.05); 147 199 } 148 200 … … 176 228 td, th { 177 229 display: table-cell; 178 vertical-align: inherit 230 vertical-align: middle; 231 padding: 10px; 179 232 } 180 233 … … 182 235 font-weight: bold; 183 236 text-align: left; 237 background-color: #f5f5f5; 238 border-bottom: 2px solid #ddd; 184 239 } 185 240 186 241 table { 187 242 border-collapse: collapse; 243 width: 100%; 244 margin-bottom: 20px; 245 background-color: #fff; 246 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); 247 border-radius: 4px; 248 overflow: hidden; 249 } 250 251 tr:nth-child(even) { 252 background-color: #f9f9f9; 253 } 254 255 tr:hover { 256 background-color: #f1f1f1; 188 257 } 189 258 … … 249 318 border: none; 250 319 color: white; 251 padding: 1 5px 32px;320 padding: 12px 24px; 252 321 text-align: center; 253 322 text-decoration: none; 254 display: inline-block; 323 display: inline-flex; 324 align-items: center; 255 325 font-size: 16px; 256 border-radius: 15px; 257 cursor: pointer; 326 border-radius: 6px; 327 cursor: pointer; 328 transition: all 0.3s ease; 329 box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); 330 font-weight: 500; 331 } 332 333 .shop-2-api-connect-save:hover { 334 background-color: #3e8e41; 335 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); 336 transform: translateY(-2px); 337 } 338 339 .shop-2-api-connect-save:active { 340 transform: translateY(1px); 341 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); 342 } 343 344 .shop-2-api-connect-save .dashicons { 345 margin-right: 8px; 258 346 } 259 347 260 348 .shop-2-api-connect-save-sync { 261 background-color: #008CBA; /* Green*/349 background-color: #008CBA; /* Blue */ 262 350 border: none; 263 351 color: white; 264 padding: 1 5px 32px;352 padding: 12px 24px; 265 353 text-align: center; 266 354 text-decoration: none; 267 display: inline-block; 355 display: inline-flex; 356 align-items: center; 268 357 font-size: 16px; 269 border-radius: 15px; 270 cursor: pointer; 358 border-radius: 6px; 359 cursor: pointer; 360 transition: all 0.3s ease; 361 box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); 362 font-weight: 500; 363 } 364 365 .shop-2-api-connect-save-sync:hover { 366 background-color: #007095; 367 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); 368 transform: translateY(-2px); 369 } 370 371 .shop-2-api-connect-save-sync:active { 372 transform: translateY(1px); 373 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); 374 } 375 376 .shop-2-api-connect-save-sync .dashicons { 377 margin-right: 8px; 271 378 } 272 379 273 380 .shop-2-api-connect-submit-bol-to-wc { 274 background-color: #008CBA; /* Green*/381 background-color: #008CBA; /* Blue */ 275 382 border: none; 276 383 color: white; 277 padding: 1 5px 32px;384 padding: 12px 24px; 278 385 text-align: center; 279 386 text-decoration: none; 280 display: inline-block; 387 display: inline-flex; 388 align-items: center; 281 389 font-size: 16px; 282 border-radius: 15px; 283 cursor: pointer; 390 border-radius: 6px; 391 cursor: pointer; 392 transition: all 0.3s ease; 393 box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); 394 font-weight: 500; 395 } 396 397 .shop-2-api-connect-submit-bol-to-wc:hover { 398 background-color: #007095; 399 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); 400 transform: translateY(-2px); 401 } 402 403 .shop-2-api-connect-submit-bol-to-wc:active { 404 transform: translateY(1px); 405 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); 406 } 407 408 .shop-2-api-connect-submit-bol-to-wc .dashicons { 409 margin-right: 8px; 284 410 } 285 411 … … 305 431 .tooltip .tooltiptext { 306 432 visibility: hidden; 307 width: 120px;308 background-color: black;433 width: 200px; 434 background-color: rgba(0, 0, 0, 0.8); 309 435 color: #fff; 310 436 text-align: center; 311 padding: 5px 0;437 padding: 8px 12px; 312 438 border-radius: 6px; 313 314 /* Position the tooltip text - see examples below! */ 439 font-size: 14px; 440 line-height: 1.4; 441 442 /* Position the tooltip text */ 315 443 position: absolute; 316 z-index: 1; 444 z-index: 100; 445 446 /* Fade in animation */ 447 opacity: 0; 448 transition: opacity 0.3s, transform 0.3s; 449 transform: translateY(10px); 317 450 } 318 451 319 452 .tooltip-left { 320 left: -120px; 453 left: -220px; 454 top: 0; 455 } 456 457 .tooltip-right { 458 right: -220px; 459 top: 0; 321 460 } 322 461 … … 324 463 .tooltip:hover .tooltiptext { 325 464 visibility: visible; 465 opacity: 1; 466 transform: translateY(0); 467 } 468 469 /* Arrow for tooltip */ 470 .tooltip .tooltiptext::after { 471 content: ""; 472 position: absolute; 473 top: 50%; 474 margin-top: -5px; 475 border-width: 5px; 476 border-style: solid; 477 } 478 479 .tooltip-left::after { 480 left: 100%; 481 border-color: transparent transparent transparent rgba(0, 0, 0, 0.8); 482 } 483 484 .tooltip-right::after { 485 right: 100%; 486 border-color: transparent rgba(0, 0, 0, 0.8) transparent transparent; 326 487 } 327 488 -
shop-2-api/trunk/includes/Api/Shop2ApiConnect.php
r3055588 r3308682 15 15 public $shop_2_api_url = ""; 16 16 protected $header = []; 17 17 protected $timeout = 60; // Default timeout in seconds 18 19 /** 20 * Constructor - initializes the connection to the Shop 2 API server 21 * Sets up the API URL and authorization headers 22 */ 18 23 function __construct() 19 24 { 20 25 $token = esc_attr(get_option('shop2api_token')); 21 $this->shop_2_api_url = getenv('SHOP_2_API_URL', true) ? getenv('SHOP_2_API_URL') : "https:// www.shop2apidevelopment.com";26 $this->shop_2_api_url = getenv('SHOP_2_API_URL', true) ? getenv('SHOP_2_API_URL') : "https://shop2apidevelopment.com"; 22 27 $this->header = ['Authorization' => 'Token ' . $token]; 28 29 // Set the authurl based on environment 23 30 if (get_site_url() == 'http://localhost:8000' || get_site_url() == 'http://127.0.0.1:8000') { 24 31 $this->header = array_merge($this->header, ['authurl' => "https://shop2api.com/testshop"]); … … 35 42 } 36 43 44 /** 45 * Check if the connection to the API is working 46 * 47 * @param string|null $token Optional token to use for the check 48 * @return bool True if connection is successful, false otherwise 49 */ 37 50 public function check_connection($token = NULL): bool 38 51 { … … 42 55 43 56 $response = wp_remote_get( 44 $this->shop_2_api_url . '/api/orders/', ['headers' => $this->header] 45 ); 46 47 update_option('shop2api_connection_succeeded', wp_remote_retrieve_response_code($response) == 200); 48 return wp_remote_retrieve_response_code($response) == 200; 49 } 50 51 // Check if bol can connect 57 $this->shop_2_api_url . '/api/orders/', 58 [ 59 'headers' => $this->header, 60 'timeout' => $this->timeout 61 ] 62 ); 63 64 // Check for WP error 65 if (is_wp_error($response)) { 66 error_log('Shop2API Connection Error: ' . $response->get_error_message()); 67 update_option('shop2api_connection_succeeded', false); 68 return false; 69 } 70 71 $is_connected = wp_remote_retrieve_response_code($response) == 200; 72 update_option('shop2api_connection_succeeded', $is_connected); 73 return $is_connected; 74 } 75 76 /** 77 * Check if Bol connection is working 78 * 79 * @return bool True if Bol connection is successful, false otherwise 80 */ 52 81 public function check_bol_connection(): bool 53 82 { 54 83 $response = wp_remote_get( 55 $this->shop_2_api_url . '/bol/test-connection/', ['headers' => $this->header] 56 ); 84 $this->shop_2_api_url . '/bol/test-connection/', 85 [ 86 'headers' => $this->header, 87 'timeout' => $this->timeout 88 ] 89 ); 90 91 // Check for WP error 92 if (is_wp_error($response)) { 93 error_log('Shop2API Bol Connection Error: ' . $response->get_error_message()); 94 update_option('shop2api_bol_connection_succeeded', false); 95 return false; 96 } 97 57 98 $response_data = json_decode(wp_remote_retrieve_body($response), true); 58 if (!$response_data) return False; 59 update_option('shop2api_bol_connection_succeeded', array_key_exists('success', $response_data)); 60 return array_key_exists('success', $response_data); 61 } 62 63 // Check if wc can connect 99 if (!$response_data) { 100 update_option('shop2api_bol_connection_succeeded', false); 101 return false; 102 } 103 104 $is_connected = array_key_exists('success', $response_data); 105 update_option('shop2api_bol_connection_succeeded', $is_connected); 106 return $is_connected; 107 } 108 109 /** 110 * Check if WooCommerce connection is working 111 * 112 * @return bool True if WooCommerce connection is successful, false otherwise 113 */ 64 114 public function check_wc_connection(): bool 65 115 { 66 116 $response = wp_remote_get( 67 $this->shop_2_api_url . '/woocommerce/test-connection/', ['headers' => $this->header] 68 ); 117 $this->shop_2_api_url . '/woocommerce/test-connection/', 118 [ 119 'headers' => $this->header, 120 'timeout' => $this->timeout 121 ] 122 ); 123 124 // Check for WP error 125 if (is_wp_error($response)) { 126 error_log('Shop2API WooCommerce Connection Error: ' . $response->get_error_message()); 127 update_option('shop2api_wc_connection_succeeded', false); 128 return false; 129 } 130 69 131 $response_data = json_decode(wp_remote_retrieve_body($response), true); 70 if (!$response_data) return False; 71 update_option('shop2api_wc_connection_succeeded', array_key_exists('success', $response_data)); 72 return array_key_exists('success', $response_data); 132 if (!$response_data) { 133 update_option('shop2api_wc_connection_succeeded', false); 134 return false; 135 } 136 137 $is_connected = array_key_exists('success', $response_data); 138 update_option('shop2api_wc_connection_succeeded', $is_connected); 139 return $is_connected; 73 140 } 74 141 … … 89 156 } 90 157 91 // This will get the order and if there is no order it will die (because it is either expired or not ordered) 92 // The order also translate the product of the user. 158 /** 159 * Get the first order from the API 160 * This will get the order and if there is no order it will return an empty array 161 * The order also translates the product of the user. 162 * 163 * @return array The first order or empty array if no orders found or error occurred 164 */ 93 165 public function get_order() 94 166 { 95 $orders = wp_remote_retrieve_body($this->get_orders()); 167 $response = $this->get_orders(); 168 169 // Check for WP error 170 if (is_wp_error($response)) { 171 error_log('Shop2API Error retrieving orders: ' . $response->get_error_message()); 172 return []; 173 } 174 175 $orders = wp_remote_retrieve_body($response); 96 176 $json_orders = json_decode($orders, true); 97 if (gettype($json_orders) != 'array') 98 { 177 178 // Validate response data 179 if (!is_array($json_orders)) { 99 180 return []; 100 181 } 101 if (count($json_orders) == 0 || $json_orders == NULL) return []; 102 if (array_key_exists('detail', $json_orders) && str_contains($json_orders["detail"], 'Invalid token')) return []; 103 if (array_key_exists('detail', $json_orders) && str_contains($json_orders["detail"], 'inactive or deleted')) return []; 182 183 if (empty($json_orders) || $json_orders === NULL) { 184 return []; 185 } 186 187 // Check for API error messages 188 if (array_key_exists('detail', $json_orders)) { 189 if (str_contains($json_orders["detail"], 'Invalid token') || 190 str_contains($json_orders["detail"], 'inactive or deleted')) { 191 return []; 192 } 193 } 104 194 105 195 return $json_orders[0]; … … 481 571 } 482 572 483 // Get Order data 573 /** 574 * Get Order data from the API 575 * 576 * @return array|WP_Error The response or WP_Error on failure 577 */ 484 578 public function get_order_data() 485 579 { 486 return wp_remote_get( 487 $this->shop_2_api_url . '/map/api/wc-order/', ['headers' => $this->header] 488 ); 580 $response = wp_remote_get( 581 $this->shop_2_api_url . '/map/api/wc-order/', 582 [ 583 'headers' => $this->header, 584 'timeout' => $this->timeout 585 ] 586 ); 587 588 if (is_wp_error($response)) { 589 error_log('Shop2API Error getting order data: ' . $response->get_error_message()); 590 } 591 592 return $response; 489 593 } 490 594 -
shop-2-api/trunk/readme.txt
r3248682 r3308682 92 92 1) Description and link updates 93 93 94 = 1.0.32.2 = 95 1) URL Update 96 94 97 == Instructions == 95 98 1) After installing Shop2Api, a new menu item will be available in your WordPress installation, you can continue and click on it and enter your e-mail address. -
shop-2-api/trunk/shop-2-api.php
r3248677 r3308682 5 5 Plugin URI: https://wordpress.org/plugins/shop-2-api/ 6 6 Description: The plugin Shop2Api will sync products between e-Commerce platforms. The current supported e-Commerce platforms are WooCommerce to Bol.com, and we are working on Amazon, Shopify and others. We added a koopblok service so that you can check if you lower your price can you get koopblok. 7 Version: 1.0.32. 17 Version: 1.0.32.2 8 8 Requires at least: 5.0 9 9 Requires PHP: 7.2 … … 12 12 License: GPLv2 or later 13 13 Text Domain: shop2API 14 Stable tag: 1.0.32. 114 Stable tag: 1.0.32.2 15 15 Short Description: Sync products between e-Commerce platforms like WooCommerce, Bol.com. 16 16 */ -
shop-2-api/trunk/templates/dashboard.php
r3058328 r3308682 189 189 <label for="sync-wc-product">Sync Products/Offers/Stock Manually</label> 190 190 </p> 191 <button id="sync-wc-product" class="shop-2-api-connect-save">Sync</button> 191 <button id="sync-wc-product" class="shop-2-api-connect-save"> 192 <span class="dashicons dashicons-update"></span> Sync 193 </button> 192 194 </div> 193 195 <div> … … 195 197 <label for="refresh-dropdowns">Refresh Category/Attribute Dropdowns</label> 196 198 </p> 197 <button id="refresh-dropdowns" class="shop-2-api-connect-save">Refresh</button> 199 <button id="refresh-dropdowns" class="shop-2-api-connect-save"> 200 <span class="dashicons dashicons-update"></span> Refresh 201 </button> 198 202 </div> 199 203 </div>
Note: See TracChangeset
for help on using the changeset viewer.