| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Utilities; |
| 4 |
|
| 5 |
class OrderManagerUtilities |
| 6 |
{ |
| 7 |
public static function getAllItemIdsFromMeta($wpdb, $orderId) |
| 8 |
{ |
| 9 |
$metaKeyPattern = '_sync_basalam_item_id_%'; |
| 10 |
|
| 11 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct lookup on WooCommerce orders-meta table; no object cache for this query. |
| 12 |
$results = $wpdb->get_results( |
| 13 |
$wpdb->prepare( |
| 14 |
"SELECT meta_value FROM {$wpdb->prefix}wc_orders_meta |
| 15 |
WHERE order_id = %d AND meta_key LIKE %s", |
| 16 |
$orderId, |
| 17 |
$metaKeyPattern |
| 18 |
) |
| 19 |
); |
| 20 |
|
| 21 |
$itemIds = []; |
| 22 |
if ($results) { |
| 23 |
foreach ($results as $row) { |
| 24 |
$itemIds[] = $row->meta_value; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
return $itemIds; |
| 29 |
} |
| 30 |
|
| 31 |
public static function getInvoiceId($wpdb, $orderId) |
| 32 |
{ |
| 33 |
$tableName = $wpdb->prefix . 'sync_basalam_payments'; |
| 34 |
|
| 35 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom plugin table; identifier from $wpdb->prefix, not user input. |
| 36 |
$orderData = $wpdb->get_row( |
| 37 |
$wpdb->prepare( |
| 38 |
"SELECT invoice_id FROM {$tableName} WHERE order_id = %d LIMIT 1", |
| 39 |
$orderId |
| 40 |
) |
| 41 |
); |
| 42 |
|
| 43 |
return $orderData ? $orderData->invoice_id : null; |
| 44 |
} |
| 45 |
} |
| 46 |
|