Changeset 3243360
- Timestamp:
- 02/19/2025 03:34:31 PM (14 months ago)
- Location:
- sideup-ksa/trunk
- Files:
-
- 5 edited
-
includes/orders_page.php (modified) (3 diffs)
-
public/js/side-up-manger.js (modified) (12 diffs)
-
readme.txt (modified) (1 diff)
-
sideup.php (modified) (1 diff)
-
views/ship_model.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sideup-ksa/trunk/includes/orders_page.php
r3242002 r3243360 78 78 return; 79 79 } 80 81 $orders = wc_get_orders(array('return' => 'ids')); 80 $orders = wc_get_orders([ 81 'return' => 'ids', 82 'limit' => 15, // Change to desired per_page value 83 ]); 82 84 if (empty($orders)) { 83 85 return; 84 86 } 87 $page = isset($_GET['paged']) ? intval($_GET['paged']) : 1; // Get current page from URL 88 89 $orders = wc_get_orders([ 90 'return' => 'ids', 91 'limit' => 20, // Matches WooCommerce per-page setting 92 'page' => $page, 93 ]); 85 94 86 95 // Prepare keys for the API request 87 96 $keys = array_map(function($order) { 88 $post = get_post($order);89 $orderInfo = wc_get_order($order);97 $post = get_post($order); 98 $orderInfo = wc_get_order($order); 90 99 return ($post->post_password ?: get_post_meta($order, '_order_key', true)) ?: $orderInfo->order_key; 91 100 }, $orders); … … 95 104 } 96 105 97 $data= getWowCommerceData($keys,$orders);106 $data= getWowCommerceData($keys,$orders); 98 107 99 108 if (!is_wp_error($data) && !is_bool(json_decode($data['body'])->data[0]->code)) { … … 122 131 wp_die($error_message); 123 132 } 124 add_filter("manage_{$screen->id}_columns", 'sideup_wco_add_columns');125 add_action("manage_{$screen->post_type}_posts_custom_column", 'sideup_wco_column_cb_data', 10, 2);133 add_filter("manage_{$screen->id}_columns", 'sideup_wco_add_columns'); 134 add_action("manage_{$screen->post_type}_posts_custom_column", 'sideup_wco_column_cb_data', 10, 2); 126 135 } 127 136 -
sideup-ksa/trunk/public/js/side-up-manger.js
r3242002 r3243360 51 51 } 52 52 }) 53 .done(function (response) {54 let orderData = Object.values(response.data)[0];55 56 if (orderData && orderData.prices) {57 let carriersOptions = '';58 59 Object.entries(orderData.prices).forEach(([courier, price]) => {60 carriersOptions += `61 <div style="display:inline-block; margin-right: 10px;">62 <input type="radio" name="carrier_${orderId}" value="${courier}" class=".courierSelection" data-order-id="${orderId}" id="carrier_${orderId}">63 <label for="carrier_${orderId}" class="carrier_prices_${orderId}" data-value="${price}">64 ${courier} - ${price} ${currency}65 </label>66 </div>67 `;68 });69 70 couriersPricesContainer.html(carriersOptions);71 } else {72 couriersPricesContainer.html('<span class="text-danger">No pricing data available.</span>');73 }74 })75 .fail(function (jqXHR) {76 couriersPricesContainer.html('<span class="text-danger">Failed to fetch courier prices.</span>');77 console.error("AJAX Error:", jqXHR.responseText);78 });53 .done(function (response) { 54 let orderData = Object.values(response.data)[0]; 55 56 if (orderData && orderData.prices) { 57 let carriersOptions = ''; 58 59 Object.entries(orderData.prices).forEach(([courier, price]) => { 60 carriersOptions += ` 61 <div style="display:inline-block; margin-right: 10px;"> 62 <input type="radio" name="carrier_${orderId}" value="${courier}" class=".courierSelection" data-order-id="${orderId}" id="carrier_${orderId}"> 63 <label for="carrier_${orderId}" class="carrier_prices_${orderId}" data-value="${price}"> 64 ${courier} - ${price} ${currency} 65 </label> 66 </div> 67 `; 68 }); 69 70 couriersPricesContainer.html(carriersOptions); 71 } else { 72 couriersPricesContainer.html('<span class="text-danger">No pricing data available.</span>'); 73 } 74 }) 75 .fail(function (jqXHR) { 76 couriersPricesContainer.html('<span class="text-danger">Failed to fetch courier prices.</span>'); 77 console.error("AJAX Error:", jqXHR.responseText); 78 }); 79 79 } 80 80 … … 85 85 **/ 86 86 $(document).on('click', '.ship_order', function () { 87 87 88 let orderId = $(this).data('order-id'); 89 let order_key = $(this).data('order-key'); 88 90 let totalPrice = $(this).data('total-price'); 89 let order_key = $(this).data('order-key');90 91 let dropArea = $(this).data('drop-area'); 92 let products = $(this).data('products'); 91 93 let totalPriceContext = $(this).data('total-price-context'); 92 94 let customerName = $(this).data('customer-name'); 93 let customerPhone = $(this).data('customer-phone'); 95 96 let customerShippingPhone = $(this).data('customer-phone'); 97 98 // $('.phone_' + orderId).val(customerShippingPhone); 99 // let customerPhone = $('.phone_' + orderId).val(); 94 100 let address = $(this).data('address'); 95 101 let dropAreaName = dropArea; … … 101 107 102 108 let model = ` 103 <div style="max-height: 400px; overflow-y: auto;"> 104 <table class="table table-borderless table-striped table-hover"> 105 <tr class=""> 106 <th style="width: 10%;">ID</th> 107 <th style="width: 15%;">Customer Name</th> 108 <th style="width: 10%;">Phone</th> 109 <th style="width: 15%;">Payment Method</th> 110 <th style="width: 10%;">Total Cost</th> 111 <th style="width: 40%;">Couriers</th> 112 </tr> 113 <tr data-order-id="${orderId}" 114 data-order-key="${order_key}" 115 data-address="${address}" 116 data-drop-area="${dropAreaName}" 117 data-total-price="${totalPrice}" 118 data-customer-name="${customerName}" 119 data-customer-phone="${customerPhone}"> 120 121 <td>${orderId}</td> 122 <td>${customerName}</td> 123 <td>${customerPhone}</td> 124 <td> 125 <select class="form-control-lg paymentMethod_${orderId}" name="paymentMethod_${orderId}"> 126 <option selected>Select Payment Method</option> 127 <option value="4" selected>Cash On Delivery</option> 128 <option value="1">Credit Card (Visa or Mastercard)</option> 129 <option value="3">Zero Cash Collection</option> 130 </select> 131 </td> 132 <td class="total-price-context">${totalPriceContext}</td> 133 <td class="couriers-prices_${orderId}"></td> 134 </tr> 135 <tr> 136 <td colspan="6" class="text-end"> 137 <button type="button" class="btn btn-primary confirm_shipment">Ship</button> 138 </td> 139 </tr> 140 </table> 141 </div> 142 `; 109 <div style="max-height: 400px; overflow-y: auto;"> 110 <table class="table table-borderless table-striped table-hover" style="width: 100%; table-layout: fixed;"> 111 <tr> 112 <th style="width: 8%;">ID</th> 113 <th style="width: 18%;">Customer Name</th> 114 <th style="width: 12%;">Phone</th> 115 <th style="width: 12%;">Other Phone</th> 116 <th style="width: 15%;">Payment Method</th> 117 <th style="width: 10%;">Total Cost</th> 118 <th style="width: 25%;">Couriers</th> 119 </tr> 120 <tr data-order-id="${orderId}" 121 data-order-key="${order_key}" 122 data-address="${address}" 123 data-drop-area="${dropAreaName}" 124 data-total-price="${totalPrice}" 125 data-customer-name="${customerName}" 126 data-customer-phone="${customerShippingPhone}" 127 data-products="${products}"> 128 129 <td>${orderId}</td> 130 <td>${customerName}</td> 131 <td> 132 <input type="text" class="phone_${orderId} form-control" style="width: 100%;" value="${customerShippingPhone}" placeholder="01012345678, 01198765432, 01555555555"> 133 </td> 134 <td> 135 <input type="text" class="receiver_extra_phone${orderId} form-control" style="width: 100%;" value="" placeholder="01012345678, 01198765432, 01555555555"> 136 </td> 137 <td> 138 <select class="form-control paymentMethod_${orderId}" name="paymentMethod_${orderId}" style="width: 100%;"> 139 <option selected>Select Payment Method</option> 140 <option value="4" selected>Cash On Delivery</option> 141 <option value="1">Credit Card (Visa or Mastercard)</option> 142 <option value="3">Zero Cash Collection</option> 143 </select> 144 </td> 145 <td class="total-price-context"> 146 <label class="d-flex align-items-center"> 147 <input type="text" class="price_${orderId} form-control w-50" value="${totalPrice}"> 148 <span class="ms-2">${currency}</span> 149 </label> 150 </td> 151 <td class="couriers-prices_${orderId}"></td> 152 </tr> 153 <tr> 154 <td colspan="7" class="text-end"> 155 <button type="button" class="btn btn-primary confirm_shipment">Ship</button> 156 </td> 157 </tr> 158 </table> 159 </div> 160 `; 143 161 144 162 Swal.fire({ … … 163 181 } 164 182 }); 183 $(document).off('change', `.price_${orderId}`).on('change', `.price_${orderId}`, function () { 184 let selectedPaymentMethod = $(`.paymentMethod_${orderId}`).val(); 185 let totalPrice = $(this).val(); 186 187 if (selectedPaymentMethod == 3 && parseFloat(totalPrice) > 0){ 188 $(this).val("0.00"); 189 totalPrice = "0.00"; 190 191 Swal.fire({ 192 icon: "warning", 193 title: "Invalid Price Entry!", 194 text: "You cannot enter a price when using Zero Cash Collection. Please follow the guide instructions.", 195 confirmButtonText: "OK", 196 }).then((result) => { 197 if (result.isConfirmed) { 198 location.reload(); // Reload page when user confirms 199 } 200 }); 201 }else { 202 totalPrice =totalPrice; 203 } 204 let orderData = { 205 orderId: orderId, 206 total_cost: totalPrice , 207 dropArea: dropArea, 208 paymentMethod: selectedPaymentMethod, 209 currency: currency 210 }; 211 212 213 console.log("Updated Price:", totalPrice); 214 fetchPricingSingleOrderOnClick(orderId, selectedPaymentMethod, orderData, dropAreaName); 215 216 }); 165 217 166 218 /** … … 169 221 * **************************************************** 170 222 **/ 223 171 224 $(document).off('change', `.paymentMethod_${orderId}`).on('change', `.paymentMethod_${orderId}`, function () { 172 225 let newPaymentMethod = $(this).val(); 226 227 let totalPrice = $(this).val(); 228 229 if (newPaymentMethod == 3 && parseFloat(totalPrice) > 0) { 230 $(`.price_${orderId}`).val("0.00"); 231 totalPrice = "0.00"; 232 } 173 233 let orderData = { 174 234 orderId: orderId, … … 178 238 currency: currency 179 239 }; 180 181 240 console.log("Updated Payment Method:", newPaymentMethod); 182 241 fetchPricingSingleOrderOnClick(orderId, newPaymentMethod, orderData, dropAreaName); 183 // getSelectedOrdersData();184 242 185 243 }); … … 191 249 192 250 251 193 252 }); 194 253 /** … … 221 280 222 281 let shipmentCode = `WOWC-${Math.floor(1000000 + Math.random() * 9000000)}`; 223 let totalPrice = orderRow.data('total-price') || "0.00";224 282 let orderKey = orderRow.data('order-key'); 225 283 let dropArea = orderRow.data('drop-area') || "N/A"; 226 284 let customerName = orderRow.data('customer-name') || "Unknown"; 227 let customerPhone = orderRow.data('customer-phone') || "0000000000"; 285 let totalPrice = $(`.price_${orderId}`).val() || "0.00"; // Fix: Retrieve total price correctly 286 let customerPhone = $(`.phone_${orderId}`).val() || "0000000000"; 287 let customerOtherPhone = $(`.receiver_extra_phone${orderId}`).val() || "0000000000"; 288 let products = orderRow.data('products'); 289 228 290 let address = orderRow.data('address') || "No Address"; 229 291 let courier = orderRow.find(`input[name="carrier_${orderId}"]:checked`).val(); 230 292 if (!courier) { 231 console.warn(`No courier selected for Order ID ${orderId}`); 232 return; 233 } 293 alert(`Error: missing courier for Order ID ${orderId}.`); 294 } 295 if (!customerPhone || customerPhone.length < 10 && isValidSaudiPhone(customerPhone)) { 296 alert(`Error: Invalid or missing phone number for Order ID ${orderId}.`); 297 } 298 299 234 300 235 301 let foundArea = cities_and_zones.find(area => area.value === dropArea || area.key === dropArea); … … 242 308 landmark: 'N/A', 243 309 notes: 'WooCommerce Order', 244 item_description: 'WooCommerce Order',310 item_description: products, 245 311 isWooCommerce: true, 246 312 online_payment: paymentMethod == "1" ? "online_payment_paymob" : null, 247 313 zero_cash_collection: paymentMethod == "3" ? true :false, 248 314 total_cash_collection: paymentMethod == "3" ? "0.00" : totalPrice.toString(), 249 backup_mobile: '',250 315 name: customerName, 251 316 phone: customerPhone, 317 backup_mobile: customerOtherPhone, 252 318 area_id: areaParsed[findDropAreaName] || null, 253 319 address: address, … … 255 321 }; 256 322 257 258 259 if (!shipments.some(s => s.woocommerce_id === orderKey)) { 260 shipments.push(shipment); 261 } else { 262 console.warn(`Shipment for Order ID ${orderId} already exists.`); 263 } 264 submitOrder(shipment); 323 if ( 324 courier && 325 areaParsed[findDropAreaName] != null && 326 customerPhone && customerPhone.trim() !== "" && 327 customerPhone.length >= 10 && isValidSaudiPhone(customerPhone) 328 ){ 329 submitOrder(shipment); 330 331 Swal.fire({ 332 title: 'Processing Shipment...', 333 text: 'Please wait while we process your order.', 334 allowOutsideClick: false, 335 didOpen: () => { 336 Swal.showLoading(); // Show loading indicator 337 } 338 }); 339 } 265 340 266 341 }); 342 267 343 268 344 let requestData = { … … 273 349 274 350 275 function submitOrder(request) {351 function submitOrder(request) { 276 352 $.ajax({ 277 353 url: baseURL+'orders', … … 365 441 366 442 443 function isValidSaudiPhone(phone) { 444 let saudiRegex = /^(?:\+9665|9665|05)[0-9]{8}$/; 445 return saudiRegex.test(phone); 446 } 367 447 368 448 function overrideStates() { 369 $('#_shipping_state').empty();370 371 let options = '';372 373 for (let city = 0; city < sideupSettings.cities_and_zones.length; city++) {374 let selected = (sideupSettings.selected_shipping_state === sideupSettings.cities_and_zones[city].key ||375 sideupSettings.selected_shipping_state === sideupSettings.cities_and_zones[city].value)376 ? 'selected' : '';377 378 options += '<option value="' + sideupSettings.cities_and_zones[city].key + '" ' + selected + '>' + sideupSettings.cities_and_zones[city].key + '</option>';379 }380 $('#_shipping_state').append(options);381 $('#_billing_state').empty();382 383 let billing_options = '';384 for (let city = 0; city < sideupSettings.cities_and_zones.length; city++) {385 let selected = (sideupSettings.selected_billing_state === sideupSettings.cities_and_zones[city].key ||386 sideupSettings.selected_billing_state === sideupSettings.cities_and_zones[city].value)387 ? 'selected' : '';388 389 billing_options += '<option value="' + sideupSettings.cities_and_zones[city].key + '" ' + selected + '>' + sideupSettings.cities_and_zones[city].key + '</option>';390 }391 $('#_billing_state').append(billing_options);392 }449 $('#_shipping_state').empty(); 450 451 let options = ''; 452 453 for (let city = 0; city < sideupSettings.cities_and_zones.length; city++) { 454 let selected = (sideupSettings.selected_shipping_state === sideupSettings.cities_and_zones[city].key || 455 sideupSettings.selected_shipping_state === sideupSettings.cities_and_zones[city].value) 456 ? 'selected' : ''; 457 458 options += '<option value="' + sideupSettings.cities_and_zones[city].key + '" ' + selected + '>' + sideupSettings.cities_and_zones[city].key + '</option>'; 459 } 460 $('#_shipping_state').append(options); 461 $('#_billing_state').empty(); 462 463 let billing_options = ''; 464 for (let city = 0; city < sideupSettings.cities_and_zones.length; city++) { 465 let selected = (sideupSettings.selected_billing_state === sideupSettings.cities_and_zones[city].key || 466 sideupSettings.selected_billing_state === sideupSettings.cities_and_zones[city].value) 467 ? 'selected' : ''; 468 469 billing_options += '<option value="' + sideupSettings.cities_and_zones[city].key + '" ' + selected + '>' + sideupSettings.cities_and_zones[city].key + '</option>'; 470 } 471 $('#_billing_state').append(billing_options); 472 } 393 473 394 474 }); -
sideup-ksa/trunk/readme.txt
r3242002 r3243360 7 7 Requires PHP: 7.4 8 8 Tested up to: 6.7.1 9 Stable tag: 3.0. 09 Stable tag: 3.0.1 10 10 License: GPL v2 or later 11 11 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
sideup-ksa/trunk/sideup.php
r3242012 r3243360 4 4 * Plugin URI: https://www.sideup.co/sideup-sa-plugin/ 5 5 * Description: SIDEUP’s official extension for WooCommerce on WordPress in KSA. 6 * Version: 3.0. 06 * Version: 3.0.1 7 7 * Requires at least: 5.2 8 8 * Requires PHP: 7.2 -
sideup-ksa/trunk/views/ship_model.php
r3242002 r3243360 1 1 2 <a href="javascript:void(0);" class="ship_order btn btn-primary" 3 data-bs-toggle="modal" 4 data-bs-target="#customModal<?php echo $orderId?>" 5 data-order-id="<?php echo $orderId?>" 6 data-drop-area="<?php echo $state?>" 7 data-total-price="<?php echo $total?>" 8 data-total-price-context="<?php echo $total. ' '.$currency?>" 9 data-customer-name="<?php echo $customer_first_name.' '.$customer_last_name?>" 10 data-customer-phone="<?php echo $customer_phone?>" 11 data-order-key="<?php echo $order_key?>" 12 data-address="<?php echo $shipping_address?>" 13 > 14 Ship 15 </a> 2 <a href="javascript:void(0);" class="ship_order btn btn-primary" 3 data-bs-toggle="modal" 4 data-bs-target="#customModal<?php echo $orderId?>" 5 data-order-id="<?php echo $orderId?>" 6 data-drop-area="<?php echo $state?>" 7 data-total-price="<?php echo $total?>" 8 data-total-price-context="<?php echo $total. ' '.$currency?>" 9 data-customer-name="<?php echo $customer_first_name.' '.$customer_last_name?>" 10 data-customer-phone="<?php echo $customer_phone?>" 11 data-order-key="<?php echo $order_key?>" 12 data-address="<?php echo $shipping_address?>" 13 data-products="<?php echo $desc?>>" 14 > 15 Ship 16 </a> 16 17 17 18
Note: See TracChangeset
for help on using the changeset viewer.