PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
← All changes | app/Http/Controllers/FrontendControllers/CustomerOrderController.php +46 -6 1.5.5 → 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,
@@ -314,9 +338,11 @@
314 338 $transactions = OrderTransaction::query()
315 339 ->whereIn('order_id', $orderIds)
316 340 ->whereIn('status', [
317 341 Status::TRANSACTION_SUCCEEDED,
318 - Status::TRANSACTION_REFUNDED
342 + Status::TRANSACTION_REFUNDED,
343 + Status::TRANSACTION_FAILED,
344 + Status::TRANSACTION_PENDING,
319 345 ])
320 346 ->orderBy('id', 'DESC')
321 347 ->with(['order'])
322 348 ->get();
@@ -321,9 +347,15 @@
321 347 ->with(['order'])
322 348 ->get();
323 349
324 350 $formattedOrderData['transactions'] = $transactions->map(function ($transaction) {
325 - 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;
326 358 });
327 359
328 360 $formattedOrderData = apply_filters('fluent_cart/customer/order_data', $formattedOrderData, [
329 361 'order' => $order,
@@ -397,8 +429,16 @@
397 429 {
398 430 if (!intval($order->total_amount - $order->total_paid)) {
399 431 return false;
400 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 +
401 441 return PaymentHelper::getCustomPaymentLink($order->uuid);
402 442 }
403 443
404 444 public function getTransactionBillingAddress(Request $request, $transaction_uuid)