← All changes
|
app/Http/Controllers/FrontendControllers/CustomerOrderController.php
+27
-4
1.6.1
→
1.6.5
View file →
| @@ -29,9 +29,8 @@ | ||
| 29 | 29 | use FluentCart\App\Services\Renderer\Receipt\TaxSummaryHelper; |
| 30 | 30 | use FluentCart\Framework\Database\Orm\Builder; |
| 31 | 31 | use FluentCart\Framework\Database\Orm\Relations\HasMany; |
| 32 | 32 | use FluentCart\Framework\Http\Request\Request; |
| 33 | -use FluentCart\App\Services\DateTime\DateTime; | |
| 34 | 33 | use FluentCart\Framework\Support\Arr; |
| 35 | 34 | use FluentCart\Framework\Support\Collection; |
| 36 | 35 | use FluentCart\Framework\Validator\Validator; |
| 37 | 36 | use FluentCartPro\App\Modules\Licensing\Models\License; |
| @@ -63,9 +62,9 @@ | ||
| 63 | 62 | $page = (int)$request->get('page', 1); |
| 64 | 63 | $search = $request->getSafe('search', 'sanitize_text_field'); |
| 65 | 64 | |
| 66 | 65 | $orders = Order::query() |
| 67 | - ->select(['invoice_no', 'id', 'parent_id', 'total_amount', 'fee_total', 'uuid', 'type', 'status', 'created_at']) | |
| 66 | + ->select(['invoice_no', 'id', 'parent_id', 'total_amount', 'fee_total', 'currency', 'uuid', 'type', 'status', 'created_at']) | |
| 68 | 67 | ->with(['order_items' => function ($query) { |
| 69 | 68 | $query->select('id', 'order_id', 'object_id', 'post_title', 'title', 'quantity', 'payment_type', 'line_meta', 'other_info'); |
| 70 | 69 | }]) |
| 71 | 70 | ->where('customer_id', $customer->id) |
| @@ -82,11 +81,12 @@ | ||
| 82 | 81 | ->paginate($perPage, ['*'], 'page', $page); |
| 83 | 82 | |
| 84 | 83 | $orders->transform(function ($order) { |
| 85 | 84 | return [ |
| 86 | - 'created_at' => DateTime::gmtToTimezone($order->created_at, Arr::get($order->config, 'user_tz', wp_timezone_string()))->format('Y-m-d H:i:s'), | |
| 85 | + 'created_at' => $order->created_at->format('Y-m-d H:i:s'), | |
| 87 | 86 | 'invoice_no' => $order->invoice_no, |
| 88 | 87 | 'total_amount' => $order->total_amount, |
| 88 | + 'currency' => $order->currency, | |
| 89 | 89 | 'uuid' => $order->uuid, |
| 90 | 90 | 'type' => $order->type, |
| 91 | 91 | 'status' => $order->status, |
| 92 | 92 | 'renewals_count' => $order->renewals_count, |
| @@ -238,12 +238,35 @@ | ||
| 238 | 238 | $variationIds[] = $item->object_id; |
| 239 | 239 | $productIds[] = $item->post_id; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | + $upgradableVariationIds = []; | |
| 243 | + $isUpgradeEligibleOrder = in_array($order->payment_status, [ | |
| 244 | + Status::PAYMENT_PAID, | |
| 245 | + Status::PAYMENT_PARTIALLY_PAID, | |
| 246 | + Status::PAYMENT_PARTIALLY_REFUNDED | |
| 247 | + ]); | |
| 248 | + | |
| 249 | + if ($isUpgradeEligibleOrder && $variationIds) { | |
| 250 | + $upgradableVariationIds = Meta::query() | |
| 251 | + ->where('meta_key', 'variant_upgrade_path') | |
| 252 | + ->where('object_type', 'variant_upgrade') | |
| 253 | + ->whereIn('object_id', $variationIds) | |
| 254 | + ->pluck('object_id') | |
| 255 | + ->toArray(); | |
| 256 | + } | |
| 257 | + | |
| 258 | + foreach ($orderItems as &$orderItem) { | |
| 259 | + $orderItem['has_upgrade_paths'] = Arr::get($orderItem, 'payment_type') === 'onetime' | |
| 260 | + && !Arr::get($orderItem, 'line_meta.parent_item_id') | |
| 261 | + && in_array(Arr::get($orderItem, 'variation_id'), $upgradableVariationIds); | |
| 262 | + } | |
| 263 | + unset($orderItem); | |
| 264 | + | |
| 242 | 265 | $formattedOrderData = [ |
| 243 | 266 | 'fulfillment_type' => $order->fulfillment_type, |
| 244 | 267 | 'type' => $order->type, |
| 245 | - 'created_at' => DateTime::gmtToTimezone($order->created_at, Arr::get($order->config, 'user_tz', wp_timezone_string()))->format('Y-m-d H:i:s'), | |
| 268 | + 'created_at' => $order->created_at->format('Y-m-d H:i:s'), | |
| 246 | 269 | 'invoice_no' => $order->invoice_no, |
| 247 | 270 | 'currency' => $order->currency, |
| 248 | 271 | 'uuid' => $order->uuid, |
| 249 | 272 | 'order_items' => $orderItems, |