← All changes
|
app/Http/Controllers/FrontendControllers/CustomerOrderController.php
+47
-6
1.5.2
→
1.6.5
View file →
| @@ -20,8 +20,9 @@ | ||
| 20 | 20 | use FluentCart\App\Models\OrderTransaction; |
| 21 | 21 | use FluentCart\App\Models\ProductDownload; |
| 22 | 22 | use FluentCart\App\Models\ProductVariation; |
| 23 | 23 | use FluentCart\App\Models\Subscription; |
| 24 | +use FluentCart\App\Modules\Subscriptions\Services\SystemChargeService; | |
| 24 | 25 | use FluentCart\App\Services\FileSystem\FileManager; |
| 25 | 26 | use FluentCart\App\Services\Localization\LocalizationManager; |
| 26 | 27 | use FluentCart\App\Services\OrderService; |
| 27 | 28 | use FluentCart\App\Services\Payments\PaymentHelper; |
| @@ -28,9 +29,8 @@ | ||
| 28 | 29 | use FluentCart\App\Services\Renderer\Receipt\TaxSummaryHelper; |
| 29 | 30 | use FluentCart\Framework\Database\Orm\Builder; |
| 30 | 31 | use FluentCart\Framework\Database\Orm\Relations\HasMany; |
| 31 | 32 | use FluentCart\Framework\Http\Request\Request; |
| 32 | -use FluentCart\App\Services\DateTime\DateTime; | |
| 33 | 33 | use FluentCart\Framework\Support\Arr; |
| 34 | 34 | use FluentCart\Framework\Support\Collection; |
| 35 | 35 | use FluentCart\Framework\Validator\Validator; |
| 36 | 36 | use FluentCartPro\App\Modules\Licensing\Models\License; |
| @@ -62,9 +62,9 @@ | ||
| 62 | 62 | $page = (int)$request->get('page', 1); |
| 63 | 63 | $search = $request->getSafe('search', 'sanitize_text_field'); |
| 64 | 64 | |
| 65 | 65 | $orders = Order::query() |
| 66 | - ->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']) | |
| 67 | 67 | ->with(['order_items' => function ($query) { |
| 68 | 68 | $query->select('id', 'order_id', 'object_id', 'post_title', 'title', 'quantity', 'payment_type', 'line_meta', 'other_info'); |
| 69 | 69 | }]) |
| 70 | 70 | ->where('customer_id', $customer->id) |
| @@ -81,11 +81,12 @@ | ||
| 81 | 81 | ->paginate($perPage, ['*'], 'page', $page); |
| 82 | 82 | |
| 83 | 83 | $orders->transform(function ($order) { |
| 84 | 84 | return [ |
| 85 | - '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'), | |
| 86 | 86 | 'invoice_no' => $order->invoice_no, |
| 87 | 87 | 'total_amount' => $order->total_amount, |
| 88 | + 'currency' => $order->currency, | |
| 88 | 89 | 'uuid' => $order->uuid, |
| 89 | 90 | 'type' => $order->type, |
| 90 | 91 | 'status' => $order->status, |
| 91 | 92 | 'renewals_count' => $order->renewals_count, |
| @@ -237,12 +238,35 @@ | ||
| 237 | 238 | $variationIds[] = $item->object_id; |
| 238 | 239 | $productIds[] = $item->post_id; |
| 239 | 240 | } |
| 240 | 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 | + | |
| 241 | 265 | $formattedOrderData = [ |
| 242 | 266 | 'fulfillment_type' => $order->fulfillment_type, |
| 243 | 267 | 'type' => $order->type, |
| 244 | - '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'), | |
| 245 | 269 | 'invoice_no' => $order->invoice_no, |
| 246 | 270 | 'currency' => $order->currency, |
| 247 | 271 | 'uuid' => $order->uuid, |
| 248 | 272 | 'order_items' => $orderItems, |
| @@ -258,8 +282,9 @@ | ||
| 258 | 282 | 'total_amount' => $order->total_amount, |
| 259 | 283 | 'total_paid' => $order->total_paid, |
| 260 | 284 | 'total_refund' => $order->total_refund, |
| 261 | 285 | 'shipping_total' => $order->shipping_total, |
| 286 | + 'shipping_method_title' => (string) Arr::get($order->config, 'shipping_method_title', ''), | |
| 262 | 287 | 'coupon_discount_total' => $order->coupon_discount_total, |
| 263 | 288 | 'manual_discount_total' => $order->manual_discount_total, |
| 264 | 289 | 'prorate_credit' => (int) Arr::get($order->config, 'prorate_credit', 0), |
| 265 | 290 | 'tax_total' => $order->tax_total, |
| @@ -313,9 +338,11 @@ | ||
| 313 | 338 | $transactions = OrderTransaction::query() |
| 314 | 339 | ->whereIn('order_id', $orderIds) |
| 315 | 340 | ->whereIn('status', [ |
| 316 | 341 | Status::TRANSACTION_SUCCEEDED, |
| 317 | - Status::TRANSACTION_REFUNDED | |
| 342 | + Status::TRANSACTION_REFUNDED, | |
| 343 | + Status::TRANSACTION_FAILED, | |
| 344 | + Status::TRANSACTION_PENDING, | |
| 318 | 345 | ]) |
| 319 | 346 | ->orderBy('id', 'DESC') |
| 320 | 347 | ->with(['order']) |
| 321 | 348 | ->get(); |
| @@ -320,9 +347,15 @@ | ||
| 320 | 347 | ->with(['order']) |
| 321 | 348 | ->get(); |
| 322 | 349 | |
| 323 | 350 | $formattedOrderData['transactions'] = $transactions->map(function ($transaction) { |
| 324 | - return OrderService::transformTransaction($transaction); | |
| 351 | + $transformedTransaction = OrderService::transformTransaction($transaction); | |
| 352 | + if ($transaction->status === Status::TRANSACTION_PENDING | |
| 353 | + && !empty($transformedTransaction['custom_checkout_url']) | |
| 354 | + ) { | |
| 355 | + $transformedTransaction['show_pay_now'] = true; | |
| 356 | + } | |
| 357 | + return $transformedTransaction; | |
| 325 | 358 | }); |
| 326 | 359 | |
| 327 | 360 | $formattedOrderData = apply_filters('fluent_cart/customer/order_data', $formattedOrderData, [ |
| 328 | 361 | 'order' => $order, |
| @@ -396,8 +429,16 @@ | ||
| 396 | 429 | { |
| 397 | 430 | if (!intval($order->total_amount - $order->total_paid)) { |
| 398 | 431 | return false; |
| 399 | 432 | } |
| 433 | + | |
| 434 | + if ($order->parent_id) { | |
| 435 | + $subscription = Subscription::query()->where('parent_order_id', $order->parent_id)->first(); | |
| 436 | + if ($subscription && $subscription->isSystem() && !SystemChargeService::isExhausted($subscription, $order)) { | |
| 437 | + return false; | |
| 438 | + } | |
| 439 | + } | |
| 440 | + | |
| 400 | 441 | return PaymentHelper::getCustomPaymentLink($order->uuid); |
| 401 | 442 | } |
| 402 | 443 | |
| 403 | 444 | public function getTransactionBillingAddress(Request $request, $transaction_uuid) |