← All changes
|
app/Services/ShortCodeParser/Parsers/LicenseParser.php
+10
-1
1.3.26
→
1.6.5
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 | 4 | |
| 5 | +use FluentCart\App\Services\DateTime\DateFormatter; | |
| 5 | 6 | use FluentCart\Framework\Support\Arr; |
| 6 | 7 | |
| 7 | 8 | class LicenseParser extends BaseParser |
| 8 | 9 | { |
| @@ -7,11 +8,19 @@ | ||
| 7 | 8 | class LicenseParser extends BaseParser |
| 8 | 9 | { |
| 9 | 10 | private $license; |
| 10 | 11 | |
| 12 | + /** | |
| 13 | + * Only used as the timezone context for DateFormatter — the order carries the | |
| 14 | + * user_tz captured at checkout. Null when the shortcode runs without one, in | |
| 15 | + * which case DateFormatter falls back to UTC. | |
| 16 | + */ | |
| 17 | + private $order; | |
| 18 | + | |
| 11 | 19 | public function __construct($data) |
| 12 | 20 | { |
| 13 | 21 | $this->license = Arr::get($data, 'license'); |
| 22 | + $this->order = Arr::get($data, 'order'); | |
| 14 | 23 | parent::__construct($data); |
| 15 | 24 | } |
| 16 | 25 | |
| 17 | 26 | public function parse($accessor = null, $code = null, $transformer = null): ?string |
| @@ -38,9 +47,9 @@ | ||
| 38 | 47 | case 'activation_count': |
| 39 | 48 | return esc_html($license->activation_count); |
| 40 | 49 | case 'expiration_date': |
| 41 | 50 | return $license->expiration_date |
| 42 | - ? esc_html(date('M j, Y', strtotime($license->expiration_date))) | |
| 51 | + ? esc_html(DateFormatter::format($license->expiration_date, false, $this->order)) | |
| 43 | 52 | : __('Never', 'fluent-cart'); |
| 44 | 53 | default: |
| 45 | 54 | return Arr::get((array) $license, $accessor, ''); |
| 46 | 55 | } |