PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 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 All 50 releases
fluent-cart / app / Services / TemplateService.php

TemplateService.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.7.0, at app/Services/TemplateService.php

268 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services;
4
5 use FluentCart\Api\StoreSettings;
6 use FluentCart\App\App;
7 use FluentCart\App\Vite;
8 use FluentCart\Framework\Support\Arr;
9
10 class TemplateService
11 {
12 public static function getTemplateByPathName($name, $viewData)
13 {
14 ob_start();
15 $defaultBannerImage = Vite::getAssetUrl('images/email-template/email-banner.png');
16 $viewData = Arr::wrap($viewData);
17 $viewData = array_merge($viewData, [
18 'default_banner_image' => $defaultBannerImage,
19 ]);
20 // Core templates resolve against app/Views/emails. Add-ons register
21 // their own notifications but keep the templates inside their own
22 // plugin, where that prefix cannot reach — they match on the
23 // template_path they registered and return a path View::make() can
24 // resolve (an absolute file path is safest). Core paths are untouched.
25 $viewPath = apply_filters('fluent_cart/email/template_view_path', 'emails.' . $name, [
26 'template_path' => $name,
27 'view_data' => $viewData,
28 ]);
29
30 App::make('view')->render($viewPath, $viewData);
31 return ob_get_clean();
32 }
33
34 public static function getInvoicePackingTemplateByPathName($name)
35 {
36 ob_start();
37 App::make('view')->render('invoice.' . $name);
38 return ob_get_clean();
39 }
40
41 public static function getCurrentFcPageType()
42 {
43 $pageId = null;
44 if (is_page() && is_main_query()) {
45 $pageId = get_queried_object_id();
46 }
47
48 static $pageType = null;
49
50 if ($pageType !== null) {
51 return $pageType; // Return cached page type
52 }
53
54 if (!$pageId) {
55 if (is_singular('fluent-products')) {
56 $pageType = 'single_product';
57 return $pageType;
58 }
59
60 if (is_tax(get_object_taxonomies('fluent-products'))) {
61 $pageType = 'product_taxonomy';
62 return $pageType;
63 }
64
65 }
66
67 $pagesConfig = (new StoreSettings())->getPagesSettings();
68
69 if (!in_array($pageId, $pagesConfig)) {
70 $pageType = '';
71 return $pageType;
72 }
73
74 // find the key of the current page ID in the pagesConfig array
75 $pageTypeKey = array_search($pageId, $pagesConfig);
76 if ($pageTypeKey === false) {
77 $pageType = '';
78 return $pageType;
79 }
80
81 $pageTypeMaps = [
82 'checkout_page_id' => 'checkout',
83 'registration_page_id' => 'registration',
84 'login_page_id' => 'login',
85 'cart_page_id' => 'cart',
86 'receipt_page_id' => 'receipt',
87 'order_review_page_id' => 'order_review',
88 'shop_page_id' => 'shop',
89 'customer_profile_page_id' => 'customer_dashboard',
90 ];
91
92 // Return the corresponding page type
93 $pageType = $pageTypeMaps[$pageTypeKey] ?? null;
94
95 return $pageType;
96 }
97
98 public static function isFcPageType($type)
99 {
100 $currentPageType = self::getCurrentFcPageType();
101 return $currentPageType === $type;
102 }
103
104 public static function getCustomerProfileUrl($extension = '')
105 {
106 $url = (new StoreSettings())->getCustomerProfilePage();
107 $url = rtrim($url, '/');
108
109 if ($extension) {
110 // add the extension with a leading slash
111 $url .= '/' . rtrim($extension, '/');
112 }
113
114 return $url;
115 }
116
117 public static function getAdminUrl($extension = '')
118 {
119 return URL::getDashboardUrl($extension);
120 }
121
122
123 public static function getCelebration($type = 'order')
124 {
125 if (apply_filters('fluent_cart/disable_email_celebration_messages', false, ['type' => $type])) {
126 return '';
127 }
128
129 $orderCelebrations = [
130 // translators: %1$s is celebration emoji(s)
131 wp_sprintf(_x('Woo-Hoo! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🎉✨'),
132
133 // translators: %1$s is celebration emoji(s)
134 wp_sprintf(_x('Cha-Ching! Your Shop\'s Raking It In! %1$s', 'Email Celebration', 'fluent-cart'), '💰🚀'),
135
136 // translators: %1$s is celebration emoji(s)
137 wp_sprintf(_x('Yasss! New Order, Let\'s Party! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🎈'),
138
139 // translators: %1$s is celebration emoji(s)
140 wp_sprintf(_x('High-Five! You Nailed Another Sale! %1$s', 'Email Celebration', 'fluent-cart'), '🙌💥'),
141
142 // translators: %1$s is celebration emoji(s)
143 wp_sprintf(_x('Boom! Your Store\'s Popping Off! %1$s', 'Email Celebration', 'fluent-cart'), '🌟🎊'),
144
145 // translators: %1$s is celebration emoji(s)
146 wp_sprintf(_x('Heck Yeah! Another Sale in the Bag! %1$s', 'Email Celebration', 'fluent-cart'), '🛍️🔥'),
147
148 // translators: %1$s is celebration emoji(s)
149 wp_sprintf(_x('Dance Party! New Order Just Dropped! %1$s', 'Email Celebration', 'fluent-cart'), '💃🕺'),
150
151 // translators: %1$s is celebration emoji(s)
152 wp_sprintf(_x('Cheers! Your Shop\'s Got Another Win! %1$s', 'Email Celebration', 'fluent-cart'), '🥂🎉'),
153
154 // translators: %1$s is celebration emoji(s)
155 wp_sprintf(_x('Jackpot! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🎰✨'),
156
157 // translators: %1$s is celebration emoji(s)
158 wp_sprintf(_x('Epic Win! Your Store\'s Crushing It! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🚀'),
159
160 // translators: %1$s is celebration emoji(s)
161 wp_sprintf(_x('Sweet Victory! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🎉'),
162
163 // translators: %1$s is celebration emoji(s)
164 wp_sprintf(_x('Bling Bling! Your Shop\'s Cashin\' In! %1$s', 'Email Celebration', 'fluent-cart'), '💰✨'),
165
166 // translators: %1$s is celebration emoji(s)
167 wp_sprintf(_x('Huzzah! New Order, Time to Party! %1$s', 'Email Celebration', 'fluent-cart'), '🎈🥳'),
168
169 // translators: %1$s is celebration emoji(s)
170 wp_sprintf(_x('Fist Bump! You Scored Another Sale! %1$s', 'Email Celebration', 'fluent-cart'), '👊🔥'),
171
172 // translators: %1$s is celebration emoji(s)
173 wp_sprintf(_x('Wowza! Your Store\'s on a Roll! %1$s', 'Email Celebration', 'fluent-cart'), '🚀🌟'),
174
175 // translators: %1$s is celebration emoji(s)
176 wp_sprintf(_x('Yippee! Another Sale in the Books! %1$s', 'Email Celebration', 'fluent-cart'), '🛍️🎊'),
177
178 // translators: %1$s is celebration emoji(s)
179 wp_sprintf(_x('Let\'s Groove! New Order Just Landed! %1$s', 'Email Celebration', 'fluent-cart'), '🕺💃'),
180
181 // translators: %1$s is celebration emoji(s)
182 wp_sprintf(_x('Pop the Confetti! Another Sale Win! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚨'),
183
184 // translators: %1$s is celebration emoji(s)
185 wp_sprintf(_x('Money Moves! Your Shop\'s Killing It! %1$s', 'Email Celebration', 'fluent-cart'), '💸�
186 '),
187
188 // translators: %1$s is celebration emoji(s)
189 wp_sprintf(_x('Epic Haul! Another Sale to Cheer! %1$s', 'Email Celebration', 'fluent-cart'), '🥂⚡️'),
190 ];
191
192
193 $renewalCelebrations = [
194 // translators: %1$s is celebration emoji(s)
195 wp_sprintf(_x('Your Subscription\'s Renewed! Keep Rockin\' It! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚀'),
196
197 // translators: %1$s is celebration emoji(s)
198 wp_sprintf(_x('Big News! Another Subscription Locked In! %1$s', 'Email Celebration', 'fluent-cart'), '💰✨'),
199
200 // translators: %1$s is celebration emoji(s)
201 wp_sprintf(_x('Woohoo! A Customer Renewed Their Sub! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🎈'),
202
203 // translators: %1$s is celebration emoji(s)
204 wp_sprintf(_x('High-Five! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🙌🔥'),
205
206 // translators: %1$s is celebration emoji(s)
207 wp_sprintf(_x('Cha-Ching! Subscription Renewed, Boss! %1$s', 'Email Celebration', 'fluent-cart'), '💸🌟'),
208
209 // translators: %1$s is celebration emoji(s)
210 wp_sprintf(_x('Yasss! Another Loyal Sub Stays On! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🎊'),
211
212 // translators: %1$s is celebration emoji(s)
213 wp_sprintf(_x('Boom! Your Store\'s Sub Count Grows! %1$s', 'Email Celebration', 'fluent-cart'), '💥🛍️'),
214
215 // translators: %1$s is celebration emoji(s)
216 wp_sprintf(_x('Hooray! A Renewal Just Hit Your Shop! %1$s', 'Email Celebration', 'fluent-cart'), '🥂⚡️'),
217
218 // translators: %1$s is celebration emoji(s)
219 wp_sprintf(_x('Confetti Time! Subscription Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚨'),
220
221 // translators: %1$s is celebration emoji(s)
222 wp_sprintf(_x('Keep Shining! Another Sub Stays With You! %1$s', 'Email Celebration', 'fluent-cart'), '🌟💪'),
223
224 // translators: %1$s is celebration emoji(s)
225 wp_sprintf(_x('Party On! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🎈🕺'),
226
227 // translators: %1$s is celebration emoji(s)
228 wp_sprintf(_x('Score! A Customer Renewed Their Plan! %1$s', 'Email Celebration', 'fluent-cart'), '�
229 ✨'),
230
231 // translators: %1$s is celebration emoji(s)
232 wp_sprintf(_x('Woot Woot! Subscription Renewal Alert! %1$s', 'Email Celebration', 'fluent-cart'), '🛵🎉'),
233
234 // translators: %1$s is celebration emoji(s)
235 wp_sprintf(_x('Money Moves! Another Sub Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '💰🔥'),
236
237 // translators: %1$s is celebration emoji(s)
238 wp_sprintf(_x('Epic Win! Your Shop\'s Sub is Back! %1$s', 'Email Celebration', 'fluent-cart'), '🎰⚡️'),
239
240 // translators: %1$s is celebration emoji(s)
241 wp_sprintf(_x('Cheers! A Loyal Customer Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🥂'),
242
243 // translators: %1$s is celebration emoji(s)
244 wp_sprintf(_x('Fist Bump! Subscription Renewed, Champ! %1$s', 'Email Celebration', 'fluent-cart'), '👊🌟'),
245
246 // translators: %1$s is celebration emoji(s)
247 wp_sprintf(_x('Let\'s Dance! Another Sub Stays On Board! %1$s', 'Email Celebration', 'fluent-cart'), '💃🎊'),
248
249 // translators: %1$s is celebration emoji(s)
250 wp_sprintf(_x('Jackpot! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🏆'),
251
252 // translators: %1$s is celebration emoji(s)
253 wp_sprintf(_x('You\'re Killing It! Another Sub Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🚀✨'),
254 ];
255
256
257 if ($type === 'renewal') {
258 $celebrations = $renewalCelebrations;
259 } else {
260 $celebrations = $orderCelebrations;
261 }
262
263 // send a random celebration message
264 return Arr::random($celebrations);
265 }
266
267 }
268