| 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 |
'shop_page_id' => 'shop', |
| 88 |
'customer_profile_page_id' => 'customer_dashboard', |
| 89 |
]; |
| 90 |
|
| 91 |
// Return the corresponding page type |
| 92 |
$pageType = $pageTypeMaps[$pageTypeKey] ?? null; |
| 93 |
|
| 94 |
return $pageType; |
| 95 |
} |
| 96 |
|
| 97 |
public static function isFcPageType($type) |
| 98 |
{ |
| 99 |
$currentPageType = self::getCurrentFcPageType(); |
| 100 |
return $currentPageType === $type; |
| 101 |
} |
| 102 |
|
| 103 |
public static function getCustomerProfileUrl($extension = '') |
| 104 |
{ |
| 105 |
$url = (new StoreSettings())->getCustomerProfilePage(); |
| 106 |
$url = rtrim($url, '/'); |
| 107 |
|
| 108 |
if ($extension) { |
| 109 |
// add the extension with a leading slash |
| 110 |
$url .= '/' . rtrim($extension, '/'); |
| 111 |
} |
| 112 |
|
| 113 |
return $url; |
| 114 |
} |
| 115 |
|
| 116 |
public static function getAdminUrl($extension = '') |
| 117 |
{ |
| 118 |
return URL::getDashboardUrl($extension); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
public static function getCelebration($type = 'order') |
| 123 |
{ |
| 124 |
if (apply_filters('fluent_cart/disable_email_celebration_messages', false, ['type' => $type])) { |
| 125 |
return ''; |
| 126 |
} |
| 127 |
|
| 128 |
$orderCelebrations = [ |
| 129 |
// translators: %1$s is celebration emoji(s) |
| 130 |
wp_sprintf(_x('Woo-Hoo! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🎉✨'), |
| 131 |
|
| 132 |
// translators: %1$s is celebration emoji(s) |
| 133 |
wp_sprintf(_x('Cha-Ching! Your Shop\'s Raking It In! %1$s', 'Email Celebration', 'fluent-cart'), '💰🚀'), |
| 134 |
|
| 135 |
// translators: %1$s is celebration emoji(s) |
| 136 |
wp_sprintf(_x('Yasss! New Order, Let\'s Party! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🎈'), |
| 137 |
|
| 138 |
// translators: %1$s is celebration emoji(s) |
| 139 |
wp_sprintf(_x('High-Five! You Nailed Another Sale! %1$s', 'Email Celebration', 'fluent-cart'), '🙌💥'), |
| 140 |
|
| 141 |
// translators: %1$s is celebration emoji(s) |
| 142 |
wp_sprintf(_x('Boom! Your Store\'s Popping Off! %1$s', 'Email Celebration', 'fluent-cart'), '🌟🎊'), |
| 143 |
|
| 144 |
// translators: %1$s is celebration emoji(s) |
| 145 |
wp_sprintf(_x('Heck Yeah! Another Sale in the Bag! %1$s', 'Email Celebration', 'fluent-cart'), '🛍️🔥'), |
| 146 |
|
| 147 |
// translators: %1$s is celebration emoji(s) |
| 148 |
wp_sprintf(_x('Dance Party! New Order Just Dropped! %1$s', 'Email Celebration', 'fluent-cart'), '💃🕺'), |
| 149 |
|
| 150 |
// translators: %1$s is celebration emoji(s) |
| 151 |
wp_sprintf(_x('Cheers! Your Shop\'s Got Another Win! %1$s', 'Email Celebration', 'fluent-cart'), '🥂🎉'), |
| 152 |
|
| 153 |
// translators: %1$s is celebration emoji(s) |
| 154 |
wp_sprintf(_x('Jackpot! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🎰✨'), |
| 155 |
|
| 156 |
// translators: %1$s is celebration emoji(s) |
| 157 |
wp_sprintf(_x('Epic Win! Your Store\'s Crushing It! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🚀'), |
| 158 |
|
| 159 |
// translators: %1$s is celebration emoji(s) |
| 160 |
wp_sprintf(_x('Sweet Victory! Another Sale to Celebrate! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🎉'), |
| 161 |
|
| 162 |
// translators: %1$s is celebration emoji(s) |
| 163 |
wp_sprintf(_x('Bling Bling! Your Shop\'s Cashin\' In! %1$s', 'Email Celebration', 'fluent-cart'), '💰✨'), |
| 164 |
|
| 165 |
// translators: %1$s is celebration emoji(s) |
| 166 |
wp_sprintf(_x('Huzzah! New Order, Time to Party! %1$s', 'Email Celebration', 'fluent-cart'), '🎈🥳'), |
| 167 |
|
| 168 |
// translators: %1$s is celebration emoji(s) |
| 169 |
wp_sprintf(_x('Fist Bump! You Scored Another Sale! %1$s', 'Email Celebration', 'fluent-cart'), '👊🔥'), |
| 170 |
|
| 171 |
// translators: %1$s is celebration emoji(s) |
| 172 |
wp_sprintf(_x('Wowza! Your Store\'s on a Roll! %1$s', 'Email Celebration', 'fluent-cart'), '🚀🌟'), |
| 173 |
|
| 174 |
// translators: %1$s is celebration emoji(s) |
| 175 |
wp_sprintf(_x('Yippee! Another Sale in the Books! %1$s', 'Email Celebration', 'fluent-cart'), '🛍️🎊'), |
| 176 |
|
| 177 |
// translators: %1$s is celebration emoji(s) |
| 178 |
wp_sprintf(_x('Let\'s Groove! New Order Just Landed! %1$s', 'Email Celebration', 'fluent-cart'), '🕺💃'), |
| 179 |
|
| 180 |
// translators: %1$s is celebration emoji(s) |
| 181 |
wp_sprintf(_x('Pop the Confetti! Another Sale Win! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚨'), |
| 182 |
|
| 183 |
// translators: %1$s is celebration emoji(s) |
| 184 |
wp_sprintf(_x('Money Moves! Your Shop\'s Killing It! %1$s', 'Email Celebration', 'fluent-cart'), '💸� |
| 185 |
'), |
| 186 |
|
| 187 |
// translators: %1$s is celebration emoji(s) |
| 188 |
wp_sprintf(_x('Epic Haul! Another Sale to Cheer! %1$s', 'Email Celebration', 'fluent-cart'), '🥂⚡️'), |
| 189 |
]; |
| 190 |
|
| 191 |
|
| 192 |
$renewalCelebrations = [ |
| 193 |
// translators: %1$s is celebration emoji(s) |
| 194 |
wp_sprintf(_x('Your Subscription\'s Renewed! Keep Rockin\' It! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚀'), |
| 195 |
|
| 196 |
// translators: %1$s is celebration emoji(s) |
| 197 |
wp_sprintf(_x('Big News! Another Subscription Locked In! %1$s', 'Email Celebration', 'fluent-cart'), '💰✨'), |
| 198 |
|
| 199 |
// translators: %1$s is celebration emoji(s) |
| 200 |
wp_sprintf(_x('Woohoo! A Customer Renewed Their Sub! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🎈'), |
| 201 |
|
| 202 |
// translators: %1$s is celebration emoji(s) |
| 203 |
wp_sprintf(_x('High-Five! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🙌🔥'), |
| 204 |
|
| 205 |
// translators: %1$s is celebration emoji(s) |
| 206 |
wp_sprintf(_x('Cha-Ching! Subscription Renewed, Boss! %1$s', 'Email Celebration', 'fluent-cart'), '💸🌟'), |
| 207 |
|
| 208 |
// translators: %1$s is celebration emoji(s) |
| 209 |
wp_sprintf(_x('Yasss! Another Loyal Sub Stays On! %1$s', 'Email Celebration', 'fluent-cart'), '🏆🎊'), |
| 210 |
|
| 211 |
// translators: %1$s is celebration emoji(s) |
| 212 |
wp_sprintf(_x('Boom! Your Store\'s Sub Count Grows! %1$s', 'Email Celebration', 'fluent-cart'), '💥🛍️'), |
| 213 |
|
| 214 |
// translators: %1$s is celebration emoji(s) |
| 215 |
wp_sprintf(_x('Hooray! A Renewal Just Hit Your Shop! %1$s', 'Email Celebration', 'fluent-cart'), '🥂⚡️'), |
| 216 |
|
| 217 |
// translators: %1$s is celebration emoji(s) |
| 218 |
wp_sprintf(_x('Confetti Time! Subscription Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🚨'), |
| 219 |
|
| 220 |
// translators: %1$s is celebration emoji(s) |
| 221 |
wp_sprintf(_x('Keep Shining! Another Sub Stays With You! %1$s', 'Email Celebration', 'fluent-cart'), '🌟💪'), |
| 222 |
|
| 223 |
// translators: %1$s is celebration emoji(s) |
| 224 |
wp_sprintf(_x('Party On! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🎈🕺'), |
| 225 |
|
| 226 |
// translators: %1$s is celebration emoji(s) |
| 227 |
wp_sprintf(_x('Score! A Customer Renewed Their Plan! %1$s', 'Email Celebration', 'fluent-cart'), '� |
| 228 |
✨'), |
| 229 |
|
| 230 |
// translators: %1$s is celebration emoji(s) |
| 231 |
wp_sprintf(_x('Woot Woot! Subscription Renewal Alert! %1$s', 'Email Celebration', 'fluent-cart'), '🛵🎉'), |
| 232 |
|
| 233 |
// translators: %1$s is celebration emoji(s) |
| 234 |
wp_sprintf(_x('Money Moves! Another Sub Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '💰🔥'), |
| 235 |
|
| 236 |
// translators: %1$s is celebration emoji(s) |
| 237 |
wp_sprintf(_x('Epic Win! Your Shop\'s Sub is Back! %1$s', 'Email Celebration', 'fluent-cart'), '🎰⚡️'), |
| 238 |
|
| 239 |
// translators: %1$s is celebration emoji(s) |
| 240 |
wp_sprintf(_x('Cheers! A Loyal Customer Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🥳🥂'), |
| 241 |
|
| 242 |
// translators: %1$s is celebration emoji(s) |
| 243 |
wp_sprintf(_x('Fist Bump! Subscription Renewed, Champ! %1$s', 'Email Celebration', 'fluent-cart'), '👊🌟'), |
| 244 |
|
| 245 |
// translators: %1$s is celebration emoji(s) |
| 246 |
wp_sprintf(_x('Let\'s Dance! Another Sub Stays On Board! %1$s', 'Email Celebration', 'fluent-cart'), '💃🎊'), |
| 247 |
|
| 248 |
// translators: %1$s is celebration emoji(s) |
| 249 |
wp_sprintf(_x('Jackpot! Your Shop\'s Got a Renewal! %1$s', 'Email Celebration', 'fluent-cart'), '🎉🏆'), |
| 250 |
|
| 251 |
// translators: %1$s is celebration emoji(s) |
| 252 |
wp_sprintf(_x('You\'re Killing It! Another Sub Renewed! %1$s', 'Email Celebration', 'fluent-cart'), '🚀✨'), |
| 253 |
]; |
| 254 |
|
| 255 |
|
| 256 |
if ($type === 'renewal') { |
| 257 |
$celebrations = $renewalCelebrations; |
| 258 |
} else { |
| 259 |
$celebrations = $orderCelebrations; |
| 260 |
} |
| 261 |
|
| 262 |
// send a random celebration message |
| 263 |
return Arr::random($celebrations); |
| 264 |
} |
| 265 |
|
| 266 |
} |
| 267 |
|