PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.20
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.20
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 trunk All 48 releases
fluent-cart / app / Helpers / EditorShortCodeHelper.php

EditorShortCodeHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.20, at app/Helpers/EditorShortCodeHelper.php

374 lines 18.1 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\Helpers;
4
5 use FluentCart\Api\ModuleSettings;
6 use FluentCart\App\App;
7
8 class EditorShortCodeHelper
9 {
10 public static function getGeneralShortCodes(): array
11 {
12 return [
13 'title' => __('General', 'fluent-cart'),
14 'key' => 'wp',
15 'shortcodes' => [
16 '{{wp.admin_email}}' => __('Admin Email', 'fluent-cart'),
17 '{{wp.site_url}}' => __('Site URL', 'fluent-cart'),
18 '{{wp.site_title}}' => __('Site Title', 'fluent-cart'),
19 '{{user.ID}}' => __('User ID', 'fluent-cart'),
20 '{{user.display_name}}' => __('User Display Name', 'fluent-cart'),
21 '{{user.first_name}}' => __('User First Name', 'fluent-cart'),
22 '{{user.last_name}}' => __('User Last Name', 'fluent-cart'),
23 '{{user.user_email}}' => __('User Email', 'fluent-cart'),
24 '{{user.user_login}}' => __('User Username', 'fluent-cart')
25 ],
26 ];
27 }
28
29 public static function getSettingsShortCodes(): array
30 {
31 return [
32 'title' => __('Settings', 'fluent-cart'),
33 'key' => 'settings',
34 'shortcodes' => [
35 '{{settings.store_name}}' => __('Store Name', 'fluent-cart'),
36 '{{settings.store_logo}}' => __('Store Logo', 'fluent-cart'),
37 '{{settings.store_address}}' => __('Store Address Line 1', 'fluent-cart'),
38 '{{settings.store_address2}}' => __('Store Address Line 2', 'fluent-cart'),
39 '{{settings.store_country}}' => __('Store Country', 'fluent-cart'),
40 '{{settings.store_state}}' => __('Store State', 'fluent-cart'),
41 '{{settings.store_city}}' => __('Store City', 'fluent-cart'),
42 '{{settings.store_postcode}}' => __('Store Postcode', 'fluent-cart'),
43 ],
44 'group' => 'settings'
45 ];
46 }
47
48
49 static function collectShortcodeFromNestedTextFields($array, $prefix = '')
50 {
51 $text_fields = [];
52
53 foreach ($array as $key => $value) {
54 if (is_array($value)) {
55 if (isset($value['type']) && $value['type'] === 'text' && isset($value['label'])) {
56 $label = isset($value['label']) && $value['label']
57 ? $value['label']
58 : ucwords(str_replace('_', ' ', $key));
59
60 $text_fields['{{' . $prefix . '.' . $key . '}}'] = $label;
61 } elseif (isset($value['schema'])) {
62 $text_fields = array_merge($text_fields, static::collectShortcodeFromNestedTextFields($value['schema'], $prefix));
63 }
64 }
65 }
66
67 return $text_fields;
68 }
69
70 /**
71 * Make shortCodes from array
72 * @array array [ key => [ ... arguments] ]
73 * @parentKey string will add to the key of array label
74 * @type $type string 'keyPair', will only return a key and label (string) array
75 * @return array array of shortCodes Exm: [ {{my.shortcode}} => 'My Shortcode' ]
76 */
77 public static function makeShortCodes(array $array, $parentKey = '', $type = ''): array
78 {
79 $result = [];
80 foreach ($array as $key => $value) {
81 $newKey = $parentKey ? $parentKey . '.' . $key : $key;
82 if (isset($value['label'])) {
83 $title = $value['label'] . ' (' . $parentKey . ')';
84 $code = '{{' . $newKey . '}}';
85 if ($type === 'keyPair') {
86 $result[$code] = $title;
87 } else {
88 $value['attributes'] = [
89 'code' => '{{' . $newKey . '}}',
90 'type' => $value['data-type'],
91 'name' => $value['label'] . ' (' . $parentKey . ')'
92 ];
93 $result[$newKey] = $value;
94 }
95 }
96
97 }
98
99 return $result;
100 }
101
102 public static function checkoutInputs(): array
103 {
104 $cartCheckoutHelper = CartCheckoutHelper::make();
105
106 return array_merge(
107 static::makeShortCodes($cartCheckoutHelper->getBillingAddressFields(), 'billing'),
108 static::makeShortCodes($cartCheckoutHelper->getShippingAddressFields(), 'shipping')
109 );
110 }
111
112 public static function conditionalInputs()
113 {
114
115 }
116
117 public static function getCustomerShortCodesForOrder(): array
118 {
119 $cartCheckoutHelper = CartCheckoutHelper::make();
120 $billingFields = $cartCheckoutHelper->getBillingAddressFields();
121
122 $shippingFields = $cartCheckoutHelper->getShippingAddressFields();
123
124 // $shortCodes = array_merge(
125 // static::collectShortcodeFromNestedTextFields($billingFields, 'billing'),
126 // static::collectShortcodeFromNestedTextFields($shippingFields, 'shipping')
127 // );
128
129 $shortCodes = array_merge(
130 static::collectShortcodeFromNestedTextFields($billingFields, 'order.billing'),
131 [
132 '{{order.billing.city}}' => __('City', 'fluent-cart'),
133 '{{order.billing.state}}' => __('State', 'fluent-cart'),
134 '{{order.billing.postcode}}' => __('Postcode', 'fluent-cart'),
135 '{{order.billing.country}}' => __('Country', 'fluent-cart'),
136 '{{order.billing.address_1}}' => __('Address Line 1', 'fluent-cart'),
137 '{{order.billing.address_2}}' => __('Address Line 2', 'fluent-cart'),
138 ],
139 static::collectShortcodeFromNestedTextFields($shippingFields, 'order.shipping'),
140 [
141 '{{order.shipping.city}}' => __('City', 'fluent-cart'),
142 '{{order.shipping.state}}' => __('State', 'fluent-cart'),
143 '{{order.shipping.postcode}}' => __('Postcode', 'fluent-cart'),
144 '{{order.shipping.country}}' => __('Country', 'fluent-cart'),
145 '{{order.shipping.address_1}}' => __('Address Line 1', 'fluent-cart'),
146 '{{order.shipping.address_2}}' => __('Address Line 2', 'fluent-cart'),
147 ]
148 );
149
150
151 return [
152 'key' => 'customer',
153 'title' => 'Customer',
154 'shortcodes' => $shortCodes
155 ];
156 }
157
158 public static function getPaymentShortCodes(): array
159 {
160 $orderProperties = [
161
162 ];
163
164 return [
165 'key' => 'payment',
166 'title' => 'Payments',
167 'shortcodes' => $orderProperties,
168 ];
169 }
170
171 public static function getTransactionShortCodes(): array
172 {
173 $orderProperties = [
174 '{{transaction.total}}' => __('Total Amount', 'fluent-cart'),
175 '{{transaction.total_formatted}}' => __('Total Amount (Formatted)', 'fluent-cart'),
176 '{{transaction.refund_amount}}' => __('Refund Amount', 'fluent-cart'),
177 '{{transaction.refund_amount_formatted}}' => __('Refund Amount (Formatted)', 'fluent-cart'),
178 '{{transaction.payment_method}}' => __('Payment Method', 'fluent-cart'),
179 '{{transaction.card_last_4}}' => __('Card Last 4', 'fluent-cart'),
180 '{{transaction.card_brand}}' => __('Card Brand', 'fluent-cart'),
181 '{{transaction.status}}' => __('Status', 'fluent-cart'),
182 '{{transaction.currency}}' => __('Currency', 'fluent-cart'),
183 ];
184
185 return [
186 'title' => 'transaction',
187 'key' => 'settings',
188 'shortcodes' => $orderProperties,
189 ];
190 }
191
192 public static function getShortCodes(): array
193 {
194 $groups = [
195 static::getCustomerShortCodesForOrder(),
196 static::getOrderShortCodes(),
197 static::getGeneralShortCodes(),
198 static::getSettingsShortCodes(),
199 ];
200
201 $groups = apply_filters('fluent_cart/confirmation_shortcodes', $groups, []);
202
203 $data = [
204 'data' => $groups
205 ];
206
207 return $data;
208 }
209
210 public static function getOrderShortCodes(): array
211 {
212 return [
213 'title' => __('Order', 'fluent-cart'),
214 'key' => 'order',
215 'shortcodes' => [
216 '{{order.id}}' => __('Order ID', 'fluent-cart'),
217 '{{order.customer_dashboard_link}}' => __('Customer Dashboard Link', 'fluent-cart'),
218 '{{order.status}}' => __('Order Status', 'fluent-cart'),
219 '{{order.parent_id}}' => __('Order Parent Id', 'fluent-cart'),
220 '{{order.invoice_no}}' => __('Order Number', 'fluent-cart'),
221 '{{order.fulfillment_type}}' => __('Order Fulfillment Type', 'fluent-cart'),
222 '{{order.type}}' => __('Order Type', 'fluent-cart'),
223 '{{order.customer_id}}' => __('Order Customer Id', 'fluent-cart'),
224 '{{order.payment_method}}' => __('Order Payment Method', 'fluent-cart'),
225 '{{order.payment_method_title}}' => __('Order Payment Method Title', 'fluent-cart'),
226 '{{order.payment_status}}' => __('Order Payment Status', 'fluent-cart'),
227 '{{order.currency}}' => __('Order Currency', 'fluent-cart'),
228 '{{order.subtotal}}' => __('Order Subtotal', 'fluent-cart'),
229 '{{order.subtotal_formatted}}' => __('Order Subtotal (Formatted)', 'fluent-cart'),
230 '{{order.discount_tax}}' => __('Order Discount Tax', 'fluent-cart'),
231 '{{order.discount_tax_formatted}}' => __('Order Discount Tax (Formatted)', 'fluent-cart'),
232 '{{order.discount_total}}' => __('Order Discount Total', 'fluent-cart'),
233 '{{order.discount_total_formatted}}' => __('Order Discount Total (Formatted)', 'fluent-cart'),
234 '{{order.manual_discount_total}}' => __('Manual Discount Total', 'fluent-cart'),
235 '{{order.manual_discount_total_formatted}}' => __('Manual Discount Total (Formatted)', 'fluent-cart'),
236 '{{order.coupon_discount_total}}' => __('Coupon Discount Total', 'fluent-cart'),
237 '{{order.coupon_discount_total_formatted}}' => __('Coupon Discount Total (Formatted)', 'fluent-cart'),
238 '{{order.shipping_tax}}' => __('Order Shipping Tax', 'fluent-cart'),
239 '{{order.shipping_tax_formatted}}' => __('Order Shipping Tax (Formatted)', 'fluent-cart'),
240 '{{order.shipping_total}}' => __('Order Shipping Total', 'fluent-cart'),
241 '{{order.shipping_total_formatted}}' => __('Order Shipping Total (Formatted)', 'fluent-cart'),
242 '{{order.tax_total}}' => __('Order Tax Total', 'fluent-cart'),
243 '{{order.tax_total_formatted}}' => __('Order Tax Total (Formatted)', 'fluent-cart'),
244 '{{order.total_amount}}' => __('Order Total Amount', 'fluent-cart'),
245 '{{order.total_amount_formatted}}' => __('Order Total Amount (Formatted)', 'fluent-cart'),
246 '{{order.total_paid}}' => __('Order Total Paid', 'fluent-cart'),
247 '{{order.total_paid_formatted}}' => __('Order Total Paid (Formatted)', 'fluent-cart'),
248 '{{order.total_refund}}' => __('Order Total Refund', 'fluent-cart'),
249 '{{order.total_refund_formatted}}' => __('Order Total Refund (Formatted)', 'fluent-cart'),
250 '{{order.rate}}' => __('Order Rate', 'fluent-cart'),
251 '{{order.note}}' => __('Order Note', 'fluent-cart'),
252 '{{order.ip_address}}' => __('Order Ip Address', 'fluent-cart'),
253 '{{order.completed_at}}' => __('Order Completed At', 'fluent-cart'),
254 '{{order.refunded_at}}' => __('Order Refunded At', 'fluent-cart'),
255 '{{order.uuid}}' => __('Order UUID', 'fluent-cart'),
256 '{{order.payment_receipt}}' => __('Payment Receipt', 'fluent-cart'),
257 '{{order.payment_summary}}' => __('Payment Summary', 'fluent-cart'),
258 '{{order.downloads}}' => __('Order Downloads', 'fluent-cart'),
259 '{{order.created_at}}' => __('Order Create Date', 'fluent-cart'),
260 '{{order.item_count}}' => __('Order Item Count', 'fluent-cart'),
261 '{{order.is_digital}}' => __('Is Digital Order', 'fluent-cart'),
262 ],
263 ];
264 }
265
266 public static function getEmailNotificationShortcodes(): array
267 {
268
269 $shortCodes = [
270 'order' => static::getOrderShortCodes(),
271 'general' => static::getGeneralShortCodes(),
272 'customer' => static::getCustomerShortCodesForOrder(),
273 'transaction' => static::getTransactionShortCodes(),
274 'settings' => static::getSettingsShortCodes(),
275 'license' => static::getLicenseShortCodes(),
276 ];
277 return apply_filters('fluent_cart/editor_shortcodes', $shortCodes);
278 }
279
280
281 public static function getEmailSettingsShortcodes(): array
282 {
283 return [
284 static::getGeneralShortCodes(),
285 static::getSettingsShortCodes()
286 ];
287 }
288
289 public static function getItemShortCodes(): array
290 {
291 return [
292 'title' => __('Order Item (Loop)', 'fluent-cart'),
293 'key' => 'item',
294 'shortcodes' => [
295 '{{item.sl}}' => __('Serial Number', 'fluent-cart'),
296 '{{item.name}}' => __('Product Name', 'fluent-cart'),
297 '{{item.variant}}' => __('Variant Name', 'fluent-cart'),
298 '{{item.quantity}}' => __('Quantity', 'fluent-cart'),
299 '{{item.unit_price}}' => __('Unit Price', 'fluent-cart'),
300 '{{item.unit_price_formatted}}' => __('Unit Price (Formatted)', 'fluent-cart'),
301 '{{item.price}}' => __('Total Price', 'fluent-cart'),
302 '{{item.price_formatted}}' => __('Total Price (Formatted)', 'fluent-cart'),
303 '{{item.subtotal}}' => __('Subtotal', 'fluent-cart'),
304 '{{item.subtotal_formatted}}' => __('Subtotal (Formatted)', 'fluent-cart'),
305 '{{item.payment_info}}' => __('Payment Info', 'fluent-cart'),
306 '{{item.payment_type}}' => __('Payment Type', 'fluent-cart'),
307 ],
308 ];
309 }
310
311 public static function getLicenseShortCodes(): array
312 {
313 return [
314 'title' => __('License (Loop)', 'fluent-cart'),
315 'key' => 'license',
316 'shortcodes' => [
317 '{{license.sl}}' => __('Serial Number', 'fluent-cart'),
318 '{{license.key}}' => __('License Key', 'fluent-cart'),
319 '{{license.status}}' => __('Status', 'fluent-cart'),
320 '{{license.product_name}}' => __('Product Name', 'fluent-cart'),
321 '{{license.variant}}' => __('Variant', 'fluent-cart'),
322 '{{license.limit}}' => __('Activation Limit', 'fluent-cart'),
323 '{{license.activation_count}}' => __('Activation Count', 'fluent-cart'),
324 '{{license.expiration_date}}' => __('Expiration Date', 'fluent-cart'),
325 ],
326 ];
327 }
328
329 public static function getDownloadShortCodes(): array
330 {
331 return [
332 'title' => __('Download (Loop)', 'fluent-cart'),
333 'key' => 'download',
334 'shortcodes' => [
335 '{{download.sl}}' => __('Serial Number', 'fluent-cart'),
336 '{{download.title}}' => __('File Title', 'fluent-cart'),
337 '{{download.product_name}}' => __('Product Name', 'fluent-cart'),
338 '{{download.url}}' => __('Download URL', 'fluent-cart'),
339 '{{download.file_size}}' => __('File Size', 'fluent-cart'),
340 ],
341 ];
342 }
343
344 public static function getSubscriptionShortCodes(): array
345 {
346 return [
347 'title' => __('Subscription (Loop)', 'fluent-cart'),
348 'key' => 'subscription',
349 'shortcodes' => [
350 '{{subscription.sl}}' => __('Serial Number', 'fluent-cart'),
351 '{{subscription.item_name}}' => __('Item Name', 'fluent-cart'),
352 '{{subscription.status}}' => __('Status', 'fluent-cart'),
353 '{{subscription.billing_interval}}' => __('Billing Interval', 'fluent-cart'),
354 '{{subscription.recurring_amount}}' => __('Recurring Amount', 'fluent-cart'),
355 '{{subscription.recurring_amount_formatted}}' => __('Recurring Amount (Formatted)', 'fluent-cart'),
356 '{{subscription.payment_info}}' => __('Payment Info', 'fluent-cart'),
357 '{{subscription.next_billing_date}}' => __('Next Billing Date', 'fluent-cart'),
358 '{{subscription.bill_times}}' => __('Bill Times', 'fluent-cart'),
359 '{{subscription.bill_count}}' => __('Bill Count', 'fluent-cart'),
360 '{{subscription.trial_days}}' => __('Trial Days', 'fluent-cart'),
361 '{{subscription.expire_at}}' => __('Expiration Date', 'fluent-cart'),
362 ],
363 ];
364 }
365
366 public static function getButtons()
367 {
368 $url = esc_url(site_url());
369 return [
370 'View Order' => '<a href="' . $url . '/wp-admin/admin.php?page=fluent-cart#/orders/{{order.id}}/view" style="background-color: green; color: #fff; padding: 10px 20px; text-decoration: none; border-radius: 5px;">View Order</a>'
371 ];
372 }
373 }
374