| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | use FluentCart\Api\StoreSettings; |
| 10 | 10 | use FluentCart\App\App; |
| 11 | 11 | use FluentCart\App\Models\CustomerAddresses; |
| 12 | 12 | use FluentCart\App\Models\Order; |
| 13 | +use FluentCart\App\Models\OrderAddress; | |
| 13 | 14 | use FluentCart\App\Models\ShippingMethod; |
| 14 | 15 | use FluentCart\App\Services\Localization\LocalizationManager; |
| 15 | 16 | use FluentCart\App\Services\Renderer\CheckoutFieldsSchema; |
| 16 | 17 | use FluentCart\Framework\Support\Arr; |
| @@ -90,8 +91,26 @@ | ||
| 90 | 91 | OrderAddressResource::create($addressFieldsData); |
| 91 | 92 | } |
| 92 | 93 | } |
| 93 | 94 | } |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Copy an existing OrderAddress's meta (company/VAT/legal-reg id/label) onto the | |
| 99 | + * order-address row of the same type already created for $orderId. insertOrderAddresses() | |
| 100 | + * only accepts flat column data, so a parent-order snapshot copy (renewals) must | |
| 101 | + * carry meta over separately. | |
| 102 | + */ | |
| 103 | + public static function copyOrderAddressMeta($orderId, $type, $sourceAddress): void | |
| 104 | + { | |
| 105 | + if (!$sourceAddress || empty($sourceAddress->meta)) { | |
| 106 | + return; | |
| 107 | + } | |
| 108 | + | |
| 109 | + OrderAddress::query() | |
| 110 | + ->where('order_id', $orderId) | |
| 111 | + ->where('type', $type) | |
| 112 | + ->update(['meta' => json_encode($sourceAddress->meta)]); | |
| 94 | 113 | } |
| 95 | 114 | |
| 96 | 115 | public static function getIpAddress($anonymize = false) |
| 97 | 116 | { |